|
| 1 | +//==--------- property_helper.hpp --- SYCL property helper -----------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include <CL/sycl/detail/common.hpp> |
| 12 | + |
| 13 | +__SYCL_INLINE_NAMESPACE(cl) { |
| 14 | +namespace sycl { |
| 15 | + |
| 16 | +namespace detail { |
| 17 | + |
| 18 | +// All properties are split here to dataless properties and properties with |
| 19 | +// data. A dataless property is one which has no data stored in it. A property |
| 20 | +// with data is one which has data stored in it and usually provides and access |
| 21 | +// to it. For dataless property we just store a bool which indicates if a |
| 22 | +// property is set or not. For properties with data we store a pointer to the |
| 23 | +// base class because we do not know the size of such properties beforehand. |
| 24 | + |
| 25 | +// List of all dataless properties' IDs |
| 26 | +enum DataLessPropKind { |
| 27 | + BufferUseHostPtr = 0, |
| 28 | + ImageUseHostPtr, |
| 29 | + QueueEnableProfiling, |
| 30 | + InOrder, |
| 31 | + NoInit, |
| 32 | + BufferUsePinnedHostMemory, |
| 33 | + UsePrimaryContext, |
| 34 | + DataLessPropKindSize |
| 35 | +}; |
| 36 | + |
| 37 | +// List of all properties with data IDs |
| 38 | +enum PropWithDataKind { |
| 39 | + BufferUseMutex = 0, |
| 40 | + BufferContextBound, |
| 41 | + ImageUseMutex, |
| 42 | + ImageContextBound, |
| 43 | + PropWithDataKindSize |
| 44 | +}; |
| 45 | + |
| 46 | +// Base class for dataless properties, needed to check that the type of an |
| 47 | +// object passed to the property_list is a property. |
| 48 | +class DataLessPropertyBase {}; |
| 49 | + |
| 50 | +// Helper class for the dataless properties. Every such property is supposed |
| 51 | +// to inherit from it. The ID template parameter should be one from |
| 52 | +// DataLessPropKind. |
| 53 | +template <int ID> class DataLessProperty : DataLessPropertyBase { |
| 54 | +public: |
| 55 | + static constexpr int getKind() { return ID; } |
| 56 | +}; |
| 57 | + |
| 58 | +// Base class for properties with data, needed to check that the type of an |
| 59 | +// object passed to the property_list is a property and for checking if two |
| 60 | +// properties with data are of the same type. |
| 61 | +class PropertyWithDataBase { |
| 62 | +public: |
| 63 | + PropertyWithDataBase(int ID) : MID(ID) {} |
| 64 | + bool isSame(int ID) const { return ID == MID; } |
| 65 | + virtual ~PropertyWithDataBase() = default; |
| 66 | + |
| 67 | +private: |
| 68 | + int MID = -1; |
| 69 | +}; |
| 70 | + |
| 71 | +// Helper class for the properties with data. Every such property is supposed |
| 72 | +// to inherit from it. The ID template parameter should be one from |
| 73 | +// PropWithDataKind. |
| 74 | +template <int ID> class PropertyWithData : public PropertyWithDataBase { |
| 75 | +public: |
| 76 | + PropertyWithData() : PropertyWithDataBase(ID) {} |
| 77 | + static int getKind() { return ID; } |
| 78 | +}; |
| 79 | + |
| 80 | +} // namespace detail |
| 81 | + |
| 82 | +} // namespace sycl |
| 83 | +} // __SYCL_INLINE_NAMESPACE(cl) |
0 commit comments