Skip to content
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

Fix naming inconsistency khr #244

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
80 changes: 45 additions & 35 deletions include/CL/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,15 @@ namespace cl {
class Buffer;
class Pipe;
#ifdef cl_khr_semaphore
namespace khr{
class Semaphore;
}
#endif
#if defined(cl_khr_command_buffer)
class CommandBufferKhr;
class MutableCommandKhr;
namespace khr {
class CommandBuffer;
class MutableCommand;
} // namespace khr
#endif // cl_khr_command_buffer

#if defined(CL_HPP_ENABLE_EXCEPTIONS)
Expand Down Expand Up @@ -1851,7 +1855,7 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_PROPE

#if defined(cl_khr_command_buffer_mutable_dispatch)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_QUEUE_KHR, CommandQueue)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, CommandBufferKhr)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, cl::khr::CommandBuffer)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_TYPE_KHR, cl_command_type)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR, cl::vector<cl_ndrange_kernel_command_properties_khr>)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel)
Expand Down Expand Up @@ -9175,13 +9179,13 @@ typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(

#ifdef cl_khr_semaphore
cl_int enqueueWaitSemaphores(
const vector<Semaphore> &sema_objects,
const vector<khr::Semaphore> &sema_objects,
const vector<cl_semaphore_payload_khr> &sema_payloads = {},
const vector<Event>* events_wait_list = nullptr,
Event *event = nullptr) const;

cl_int enqueueSignalSemaphores(
const vector<Semaphore> &sema_objects,
const vector<khr::Semaphore> &sema_objects,
const vector<cl_semaphore_payload_khr>& sema_payloads = {},
const vector<Event>* events_wait_list = nullptr,
Event* event = nullptr);
Expand Down Expand Up @@ -10772,6 +10776,7 @@ enum ExternalSemaphoreType : cl_external_semaphore_handle_type_khr
};
#endif // cl_khr_external_semaphore

namespace khr {
class Semaphore : public detail::Wrapper<cl_semaphore_khr>
{
public:
Expand Down Expand Up @@ -10928,11 +10933,12 @@ class Semaphore : public detail::Wrapper<cl_semaphore_khr>
}

};
} // namespace khr

CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Semaphore::ext_init_;
CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag khr::Semaphore::ext_init_;

inline cl_int CommandQueue::enqueueWaitSemaphores(
const vector<Semaphore> &sema_objects,
const vector<khr::Semaphore> &sema_objects,
const vector<cl_semaphore_payload_khr> &sema_payloads,
const vector<Event>* events_wait_list,
Event *event) const
Expand Down Expand Up @@ -10960,7 +10966,7 @@ inline cl_int CommandQueue::enqueueWaitSemaphores(
}

inline cl_int CommandQueue::enqueueSignalSemaphores(
const vector<Semaphore> &sema_objects,
const vector<khr::Semaphore> &sema_objects,
const vector<cl_semaphore_payload_khr>& sema_payloads,
const vector<Event>* events_wait_list,
Event* event)
Expand Down Expand Up @@ -10990,16 +10996,17 @@ inline cl_int CommandQueue::enqueueSignalSemaphores(
#endif // cl_khr_semaphore

#if defined(cl_khr_command_buffer)
/*! \class CommandBufferKhr
* \brief CommandBufferKhr interface for cl_command_buffer_khr.
/*! \class CommandBuffer
* \brief CommandBuffer interface for cl_command_buffer_khr.
*/
class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
namespace khr {
class CommandBuffer : public detail::Wrapper<cl_command_buffer_khr>
{
public:
//! \brief Default constructor - initializes to nullptr.
CommandBufferKhr() : detail::Wrapper<cl_type>() { }
CommandBuffer() : detail::Wrapper<cl_type>() { }

explicit CommandBufferKhr(const vector<CommandQueue> &queues,
explicit CommandBuffer(const vector<CommandQueue> &queues,
cl_command_buffer_properties_khr properties = 0,
cl_int* errcode_ret = nullptr)
{
Expand Down Expand Up @@ -11028,10 +11035,10 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
}
}

explicit CommandBufferKhr(const cl_command_buffer_khr& commandBufferKhr, bool retainObject = false) :
detail::Wrapper<cl_type>(commandBufferKhr, retainObject) { }
explicit CommandBuffer(const cl_command_buffer_khr& commandBuffer, bool retainObject = false) :
detail::Wrapper<cl_type>(commandBuffer, retainObject) { }

CommandBufferKhr& operator=(const cl_command_buffer_khr& rhs)
CommandBuffer& operator=(const cl_command_buffer_khr& rhs)
{
detail::Wrapper<cl_type>::operator=(rhs);
return *this;
Expand Down Expand Up @@ -11090,7 +11097,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>

cl_int commandBarrierWithWaitList(const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandBarrierWithWaitListKHR == nullptr) {
Expand Down Expand Up @@ -11121,7 +11128,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
size_type size,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandCopyBufferKHR == nullptr) {
Expand Down Expand Up @@ -11161,7 +11168,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
size_type dst_slice_pitch,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandCopyBufferRectKHR == nullptr) {
Expand Down Expand Up @@ -11201,7 +11208,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
const array<size_type, 3>& region,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandCopyBufferToImageKHR == nullptr) {
Expand Down Expand Up @@ -11237,7 +11244,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
const array<size_type, 3>& region,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandCopyImageKHR == nullptr) {
Expand Down Expand Up @@ -11273,7 +11280,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
size_type dst_offset,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandCopyImageToBufferKHR == nullptr) {
Expand Down Expand Up @@ -11309,7 +11316,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
size_type size,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandFillBufferKHR == nullptr) {
Expand Down Expand Up @@ -11344,7 +11351,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
const array<size_type, 3>& region,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandFillImageKHR == nullptr) {
Expand Down Expand Up @@ -11379,7 +11386,7 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
const NDRange& local = NullRange,
const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
cl_sync_point_khr* sync_point = nullptr,
MutableCommandKhr* mutable_handle = nullptr,
MutableCommand* mutable_handle = nullptr,
const CommandQueue* command_queue = nullptr)
{
if (pfn_clCommandNDRangeKernelKHR == nullptr) {
Expand Down Expand Up @@ -11492,24 +11499,26 @@ class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
detail::errHandler(CL_INVALID_VALUE, __CREATE_COMMAND_BUFFER_KHR_ERR);
}
}
}; // CommandBufferKhr
}; // CommandBuffer
} // namespace khr

CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandBufferKhr::ext_init_;
CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag cl::khr::CommandBuffer::ext_init_;

#if defined(cl_khr_command_buffer_mutable_dispatch)
/*! \class MutableCommandKhr
* \brief MutableCommandKhr interface for cl_mutable_command_khr.
/*! \class MutableCommand
* \brief MutableCommand interface for cl_mutable_command_khr.
*/
class MutableCommandKhr : public detail::Wrapper<cl_mutable_command_khr>
namespace khr {
class MutableCommand : public detail::Wrapper<cl_mutable_command_khr>
{
public:
//! \brief Default constructor - initializes to nullptr.
MutableCommandKhr() : detail::Wrapper<cl_type>() { }
MutableCommand() : detail::Wrapper<cl_type>() { }

explicit MutableCommandKhr(const cl_mutable_command_khr& mutableCommandKhr, bool retainObject = false) :
detail::Wrapper<cl_type>(mutableCommandKhr, retainObject) { }
explicit MutableCommand(const cl_mutable_command_khr& mutableCommand, bool retainObject = false) :
detail::Wrapper<cl_type>(mutableCommand, retainObject) { }

MutableCommandKhr& operator=(const cl_mutable_command_khr& rhs)
MutableCommand& operator=(const cl_mutable_command_khr& rhs)
{
detail::Wrapper<cl_type>::operator=(rhs);
return *this;
Expand Down Expand Up @@ -11539,7 +11548,8 @@ class MutableCommandKhr : public detail::Wrapper<cl_mutable_command_khr>
}
return param;
}
}; // MutableCommandKhr
}; // MutableCommand
} // namespace khr
#endif /* cl_khr_command_buffer_mutable_dispatch */

#endif // cl_khr_command_buffer
Expand Down
68 changes: 46 additions & 22 deletions tests/test_openclhpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ static cl::Image3D image3DPool[POOL_MAX];
static cl::Kernel kernelPool[POOL_MAX];
static cl::Program programPool[POOL_MAX];
#if defined(cl_khr_command_buffer)
static cl::CommandBufferKhr commandBufferKhrPool[POOL_MAX];
static cl::khr::CommandBuffer commandBufferKhrPool[POOL_MAX];
#endif
#if defined(cl_khr_semaphore)
static cl::Semaphore semaphorePool[POOL_MAX];
static cl::khr::Semaphore semaphorePool[POOL_MAX];
#endif
static cl::Device devicePool[POOL_MAX];

Expand Down Expand Up @@ -371,8 +371,8 @@ MAKE_REFCOUNT_STUBS(cl_command_buffer_khr, clRetainCommandBufferKHR, clReleaseCo
pool[0] = std::move(pool[1]); \
TEST_ASSERT_EQUAL_PTR(makeFunc(1), pool[0]()); \
TEST_ASSERT_NULL(pool[1]()); \
} \
\
}
#define MAKE_MOVE_TESTS_CL(prefix, type, makeFunc, releaseFunc, pool) \
void prefix ## MoveConstruct ## type ## NonNull(void) \
{ \
cl::type tmp(std::move(pool[0])); \
Expand All @@ -388,15 +388,39 @@ MAKE_REFCOUNT_STUBS(cl_command_buffer_khr, clRetainCommandBufferKHR, clReleaseCo
TEST_ASSERT_NULL(tmp()); \
TEST_ASSERT_NULL(empty()); \
}
#define MAKE_MOVE_TESTS_KHR2(prefix, type, makeFunc, releaseFunc, pool) \
void prefix ## MoveConstruct ## type ## NonNull(void) \
{ \
cl::khr::type tmp(std::move(pool[0])); \
TEST_ASSERT_EQUAL_PTR(makeFunc(0), tmp()); \
TEST_ASSERT_NULL(pool[0]()); \
tmp() = nullptr; \
} \
\
void prefix ## MoveConstruct ## type ## Null(void) \
{ \
cl::khr::type empty; \
cl::khr::type tmp(std::move(empty)); \
TEST_ASSERT_NULL(tmp()); \
TEST_ASSERT_NULL(empty()); \
}
#else
#define MAKE_MOVE_TESTS2(prefix, type, makeFunc, releaseFunc, pool) \
void prefix ## MoveAssign ## type ## NonNull(void) {} \
void prefix ## MoveAssign ## type ## Null(void) {} \
void prefix ## MoveAssign ## type ## Null(void) {}
#define MAKE_MOVE_TESTS_CL(prefix, type, makeFunc, releaseFunc, pool) \
void prefix ## MoveConstruct ## type ## NonNull(void) {} \
void prefix ## MoveConstruct ## type ## Null(void) {}
#define MAKE_MOVE_TESTS_KHR2(prefix, type, makeFunc, releaseFunc, pool) \
void prefix ## MoveConstruct ## type ## NonNull(void) {} \
void prefix ## MoveConstruct ## type ## Null(void) {}
#endif // !TEST_RVALUE_REFERENCES
#define MAKE_MOVE_TESTS(type, makeFunc, releaseFunc, pool) \
MAKE_MOVE_TESTS2(test, type, makeFunc, releaseFunc, pool)
MAKE_MOVE_TESTS2(test, type, makeFunc, releaseFunc, pool) \
MAKE_MOVE_TESTS_CL(test, type, makeFunc, releaseFunc, pool)
#define MAKE_MOVE_TESTS_KHR(type, makeFunc, releaseFunc, pool) \
MAKE_MOVE_TESTS2(test, type, makeFunc, releaseFunc, pool) \
MAKE_MOVE_TESTS_KHR2(test, type, makeFunc, releaseFunc, pool)

void setUp(void)
{
Expand Down Expand Up @@ -3464,19 +3488,19 @@ void testLinkProgramWithVectorProgramInput(void)
}

/****************************************************************************
* Tests for cl::CommandBufferKhr
* Tests for cl::khr::CommandBuffer
****************************************************************************/
#if defined(cl_khr_command_buffer)
void testMoveAssignCommandBufferKhrNonNull(void);
void testMoveAssignCommandBufferKhrNull(void);
void testMoveConstructCommandBufferKhrNonNull(void);
void testMoveConstructCommandBufferKhrNull(void);
MAKE_MOVE_TESTS(CommandBufferKhr, make_command_buffer_khr, clReleaseCommandBufferKHR, commandBufferKhrPool)
void testMoveAssignCommandBufferNonNull(void);
void testMoveAssignCommandBufferNull(void);
void testMoveConstructCommandBufferNonNull(void);
void testMoveConstructCommandBufferNull(void);
MAKE_MOVE_TESTS_KHR(CommandBuffer, make_command_buffer_khr, clReleaseCommandBufferKHR, commandBufferKhrPool)
#else
void testMoveAssignCommandBufferKhrNonNull(void) {}
void testMoveAssignCommandBufferKhrNull(void) {}
void testMoveConstructCommandBufferKhrNonNull(void) {}
void testMoveConstructCommandBufferKhrNull(void) {}
void testMoveAssignCommandBufferNonNull(void) {}
void testMoveAssignCommandBufferNull(void) {}
void testMoveConstructCommandBufferNonNull(void) {}
void testMoveConstructCommandBufferNull(void) {}
#endif

// Stub for clGetCommandBufferInfoKHR that returns 1
Expand Down Expand Up @@ -3629,14 +3653,14 @@ void testDevice_GetInfo_CLDeviceName()
}

/****************************************************************************
* Tests for cl::Semaphore
* Tests for cl::khr::Semaphore
****************************************************************************/
#if defined(cl_khr_semaphore)
void testMoveAssignSemaphoreNonNull(void);
void testMoveAssignSemaphoreNull(void);
void testMoveConstructSemaphoreNonNull(void);
void testMoveConstructSemaphoreNull(void);
MAKE_MOVE_TESTS(Semaphore, make_semaphore_khr, clReleaseSemaphoreKHR, semaphorePool);
MAKE_MOVE_TESTS_KHR(Semaphore, make_semaphore_khr, clReleaseSemaphoreKHR, semaphorePool);
#else
void testMoveAssignSemaphoreNonNull(void) {}
void testMoveAssignSemaphoreNull(void) {}
Expand Down Expand Up @@ -3676,7 +3700,7 @@ void testEnqueueWaitSemaphores(void)
{
clEnqueueWaitSemaphoresKHR_StubWithCallback(clEnqueueWaitSemaphoresKHR_testEnqueueWaitSemaphores);

VECTOR_CLASS<cl::Semaphore> sema_objects;
VECTOR_CLASS<cl::khr::Semaphore> sema_objects;
sema_objects.emplace_back(make_semaphore_khr(1));
VECTOR_CLASS<cl_semaphore_payload_khr> sema_payloads(1);
cl::Event event;
Expand Down Expand Up @@ -3721,7 +3745,7 @@ void testEnqueueSignalSemaphores(void)
{
clEnqueueSignalSemaphoresKHR_StubWithCallback(clEnqueueSignalSemaphoresKHR_testEnqueueSignalSemaphores);

VECTOR_CLASS<cl::Semaphore> sema_objects;
VECTOR_CLASS<cl::khr::Semaphore> sema_objects;
sema_objects.emplace_back(make_semaphore_khr(2));
VECTOR_CLASS<cl_semaphore_payload_khr> sema_payloads(1);
cl::Event event;
Expand Down Expand Up @@ -3764,7 +3788,7 @@ void testSemaphoreWithProperties(void)

VECTOR_CLASS<cl_semaphore_properties_khr> sema_props{CL_SEMAPHORE_TYPE_KHR};
cl_int err = CL_INVALID_OPERATION;
cl::Semaphore sem(contextPool[0], sema_props, &err);
cl::khr::Semaphore sem(contextPool[0], sema_props, &err);

TEST_ASSERT_EQUAL(CL_SUCCESS, err);
TEST_ASSERT_EQUAL_PTR(make_semaphore_khr(1), sem());
Expand Down Expand Up @@ -4112,7 +4136,7 @@ void testTemplateGetSemaphoreHandleForTypeKHR()

clGetSemaphoreHandleForTypeKHR_StubWithCallback(clGetSemaphoreHandleForTypeKHR_GetHandles);

cl::Semaphore semaphore;
cl::khr::Semaphore semaphore;
#if defined(cl_khr_external_semaphore_dx_fence)
{
auto handle0 = semaphore.getHandleForTypeKHR<cl::ExternalSemaphoreType::D3D12Fence>(device);
Expand Down