Skip to content

[SYCL] Rework of SYCL poperties #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include(AddSYCLExecutable)
set(SYCL_MAJOR_VERSION 2)
set(SYCL_MINOR_VERSION 1)
set(SYCL_PATCH_VERSION 0)
set(SYCL_DEV_ABI_VERSION 3)
set(SYCL_DEV_ABI_VERSION 4)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include <CL/sycl/platform.hpp>
#include <CL/sycl/pointers.hpp>
#include <CL/sycl/program.hpp>
#include <CL/sycl/properties/accessor_properties.hpp>
#include <CL/sycl/properties/buffer_properties.hpp>
#include <CL/sycl/properties/context_properties.hpp>
#include <CL/sycl/properties/image_properties.hpp>
#include <CL/sycl/properties/queue_properties.hpp>
#include <CL/sycl/queue.hpp>
#include <CL/sycl/range.hpp>
#include <CL/sycl/sampler.hpp>
Expand Down
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <CL/sycl/id.hpp>
#include <CL/sycl/image.hpp>
#include <CL/sycl/pointers.hpp>
#include <CL/sycl/properties/accessor_properties.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/sampler.hpp>

/// \file accessor.hpp
Expand Down
83 changes: 83 additions & 0 deletions sycl/include/CL/sycl/detail/property_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//==--------- property_helper.hpp --- SYCL property helper -----------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/common.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

namespace detail {

// All properties are split here to dataless properties and properties with
// data. A dataless property is one which has no data stored in it. A property
// with data is one which has data stored in it and usually provides and access
// to it. For dataless property we just store a bool which indicates if a
// property is set or not. For properties with data we store a pointer to the
// base class because we do not know the size of such properties beforehand.

// List of all dataless properties' IDs
enum DataLessPropKind {
BufferUseHostPtr = 0,
ImageUseHostPtr,
QueueEnableProfiling,
InOrder,
NoInit,
BufferUsePinnedHostMemory,
UsePrimaryContext,
DataLessPropKindSize
};

// List of all properties with data IDs
enum PropWithDataKind {
BufferUseMutex = 0,
BufferContextBound,
ImageUseMutex,
ImageContextBound,
PropWithDataKindSize
};

// Base class for dataless properties, needed to check that the type of an
// object passed to the property_list is a property.
class DataLessPropertyBase {};

// Helper class for the dataless properties. Every such property is supposed
// to inherit from it. The ID template parameter should be one from
// DataLessPropKind.
template <int ID> class DataLessProperty : DataLessPropertyBase {
public:
static constexpr int getKind() { return ID; }
};

// Base class for properties with data, needed to check that the type of an
// object passed to the property_list is a property and for checking if two
// properties with data are of the same type.
class PropertyWithDataBase {
public:
PropertyWithDataBase(int ID) : MID(ID) {}
bool isSame(int ID) const { return ID == MID; }
virtual ~PropertyWithDataBase() = default;

private:
int MID = -1;
};

// Helper class for the properties with data. Every such property is supposed
// to inherit from it. The ID template parameter should be one from
// PropWithDataKind.
template <int ID> class PropertyWithData : public PropertyWithDataBase {
public:
PropertyWithData() : PropertyWithDataBase(ID) {}
static int getKind() { return ID; }
};

} // namespace detail

} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
#include <CL/sycl/detail/type_traits.hpp>
#include <CL/sycl/event.hpp>
#include <CL/sycl/properties/buffer_properties.hpp>
#include <CL/sycl/properties/image_properties.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/stl.hpp>

Expand Down
37 changes: 37 additions & 0 deletions sycl/include/CL/sycl/properties/accessor_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//==----------- accessor_properties.hpp --- SYCL accessor properties -------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/property_helper.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace property {

class noinit : public detail::DataLessProperty<detail::NoInit> {};

} // namespace property

#if __cplusplus > 201402L

inline constexpr property::noinit noinit;

#else

namespace {

constexpr const auto &noinit =
sycl::detail::InlineVariableHelper<property::noinit>::value;
}

#endif

} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
57 changes: 57 additions & 0 deletions sycl/include/CL/sycl/properties/buffer_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//==----------- buffer_properties.hpp --- SYCL buffer properties -----------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/property_helper.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

namespace property {
namespace buffer {
class use_host_ptr : public detail::DataLessProperty<detail::BufferUseHostPtr> {
};

class use_mutex : public detail::PropertyWithData<detail::BufferUseMutex> {
public:
use_mutex(sycl::mutex_class &MutexRef) : MMutex(MutexRef) {}

sycl::mutex_class *get_mutex_ptr() const { return &MMutex; }

private:
sycl::mutex_class &MMutex;
};

class context_bound
: public detail::PropertyWithData<detail::BufferContextBound> {
public:
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}

context get_context() const { return MCtx; }

private:
sycl::context MCtx;
};
} // namespace buffer
} // namespace property

namespace ext {
namespace oneapi {
namespace property {
namespace buffer {

class use_pinned_host_memory
: public detail::DataLessProperty<detail::BufferUsePinnedHostMemory> {};
} // namespace buffer
} // namespace property
} // namespace oneapi
} // namespace ext
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
25 changes: 25 additions & 0 deletions sycl/include/CL/sycl/properties/context_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//==----------- context_properties.hpp --- SYCL context properties ---------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/property_helper.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace property {
namespace context {
namespace cuda {
class use_primary_context
: public detail::DataLessProperty<detail::UsePrimaryContext> {};
} // namespace cuda
} // namespace context
} // namespace property
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
44 changes: 44 additions & 0 deletions sycl/include/CL/sycl/properties/image_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//==----------- image_properties.hpp --- SYCL image properties -------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/property_helper.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace property {
namespace image {
class use_host_ptr : public detail::DataLessProperty<detail::ImageUseHostPtr> {
};

class use_mutex : public detail::PropertyWithData<detail::ImageUseMutex> {
public:
use_mutex(sycl::mutex_class &MutexRef) : MMutex(MutexRef) {}

sycl::mutex_class *get_mutex_ptr() const { return &MMutex; }

private:
sycl::mutex_class &MMutex;
};

class context_bound
: public detail::PropertyWithData<detail::ImageContextBound> {
public:
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}

context get_context() const { return MCtx; }

private:
sycl::context MCtx;
};
} // namespace image
} // namespace property
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
23 changes: 23 additions & 0 deletions sycl/include/CL/sycl/properties/queue_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//==----------- queue_properties.hpp --- SYCL queue properties -------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/property_helper.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace property {
namespace queue {
class in_order : public detail::DataLessProperty<detail::InOrder> {};
class enable_profiling
: public detail::DataLessProperty<detail::QueueEnableProfiling> {};
} // namespace queue
} // namespace property
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
Loading