diff --git a/include/CL/opencl.hpp b/include/CL/opencl.hpp index cb6e6883..58b3bbd0 100644 --- a/include/CL/opencl.hpp +++ b/include/CL/opencl.hpp @@ -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) @@ -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_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel) @@ -9175,13 +9179,13 @@ typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( #ifdef cl_khr_semaphore cl_int enqueueWaitSemaphores( - const vector &sema_objects, + const vector &sema_objects, const vector &sema_payloads = {}, const vector* events_wait_list = nullptr, Event *event = nullptr) const; cl_int enqueueSignalSemaphores( - const vector &sema_objects, + const vector &sema_objects, const vector& sema_payloads = {}, const vector* events_wait_list = nullptr, Event* event = nullptr); @@ -10772,6 +10776,7 @@ enum ExternalSemaphoreType : cl_external_semaphore_handle_type_khr }; #endif // cl_khr_external_semaphore +namespace khr { class Semaphore : public detail::Wrapper { public: @@ -10928,11 +10933,12 @@ class Semaphore : public detail::Wrapper } }; +} // 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 &sema_objects, + const vector &sema_objects, const vector &sema_payloads, const vector* events_wait_list, Event *event) const @@ -10960,7 +10966,7 @@ inline cl_int CommandQueue::enqueueWaitSemaphores( } inline cl_int CommandQueue::enqueueSignalSemaphores( - const vector &sema_objects, + const vector &sema_objects, const vector& sema_payloads, const vector* events_wait_list, Event* event) @@ -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 +namespace khr { +class CommandBuffer : public detail::Wrapper { public: //! \brief Default constructor - initializes to nullptr. - CommandBufferKhr() : detail::Wrapper() { } + CommandBuffer() : detail::Wrapper() { } - explicit CommandBufferKhr(const vector &queues, + explicit CommandBuffer(const vector &queues, cl_command_buffer_properties_khr properties = 0, cl_int* errcode_ret = nullptr) { @@ -11028,10 +11035,10 @@ class CommandBufferKhr : public detail::Wrapper } } - explicit CommandBufferKhr(const cl_command_buffer_khr& commandBufferKhr, bool retainObject = false) : - detail::Wrapper(commandBufferKhr, retainObject) { } + explicit CommandBuffer(const cl_command_buffer_khr& commandBuffer, bool retainObject = false) : + detail::Wrapper(commandBuffer, retainObject) { } - CommandBufferKhr& operator=(const cl_command_buffer_khr& rhs) + CommandBuffer& operator=(const cl_command_buffer_khr& rhs) { detail::Wrapper::operator=(rhs); return *this; @@ -11090,7 +11097,7 @@ class CommandBufferKhr : public detail::Wrapper cl_int commandBarrierWithWaitList(const vector* 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) { @@ -11121,7 +11128,7 @@ class CommandBufferKhr : public detail::Wrapper size_type size, const vector* 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) { @@ -11161,7 +11168,7 @@ class CommandBufferKhr : public detail::Wrapper size_type dst_slice_pitch, const vector* 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) { @@ -11201,7 +11208,7 @@ class CommandBufferKhr : public detail::Wrapper const array& region, const vector* 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) { @@ -11237,7 +11244,7 @@ class CommandBufferKhr : public detail::Wrapper const array& region, const vector* 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) { @@ -11273,7 +11280,7 @@ class CommandBufferKhr : public detail::Wrapper size_type dst_offset, const vector* 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) { @@ -11309,7 +11316,7 @@ class CommandBufferKhr : public detail::Wrapper size_type size, const vector* 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) { @@ -11344,7 +11351,7 @@ class CommandBufferKhr : public detail::Wrapper const array& region, const vector* 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) { @@ -11379,7 +11386,7 @@ class CommandBufferKhr : public detail::Wrapper const NDRange& local = NullRange, const vector* 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) { @@ -11492,24 +11499,26 @@ class CommandBufferKhr : public detail::Wrapper 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 +namespace khr { +class MutableCommand : public detail::Wrapper { public: //! \brief Default constructor - initializes to nullptr. - MutableCommandKhr() : detail::Wrapper() { } + MutableCommand() : detail::Wrapper() { } - explicit MutableCommandKhr(const cl_mutable_command_khr& mutableCommandKhr, bool retainObject = false) : - detail::Wrapper(mutableCommandKhr, retainObject) { } + explicit MutableCommand(const cl_mutable_command_khr& mutableCommand, bool retainObject = false) : + detail::Wrapper(mutableCommand, retainObject) { } - MutableCommandKhr& operator=(const cl_mutable_command_khr& rhs) + MutableCommand& operator=(const cl_mutable_command_khr& rhs) { detail::Wrapper::operator=(rhs); return *this; @@ -11539,7 +11548,8 @@ class MutableCommandKhr : public detail::Wrapper } return param; } -}; // MutableCommandKhr +}; // MutableCommand +} // namespace khr #endif /* cl_khr_command_buffer_mutable_dispatch */ #endif // cl_khr_command_buffer diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index c794b16b..8f8e74b7 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -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]; @@ -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])); \ @@ -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) { @@ -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 @@ -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) {} @@ -3676,7 +3700,7 @@ void testEnqueueWaitSemaphores(void) { clEnqueueWaitSemaphoresKHR_StubWithCallback(clEnqueueWaitSemaphoresKHR_testEnqueueWaitSemaphores); - VECTOR_CLASS sema_objects; + VECTOR_CLASS sema_objects; sema_objects.emplace_back(make_semaphore_khr(1)); VECTOR_CLASS sema_payloads(1); cl::Event event; @@ -3721,7 +3745,7 @@ void testEnqueueSignalSemaphores(void) { clEnqueueSignalSemaphoresKHR_StubWithCallback(clEnqueueSignalSemaphoresKHR_testEnqueueSignalSemaphores); - VECTOR_CLASS sema_objects; + VECTOR_CLASS sema_objects; sema_objects.emplace_back(make_semaphore_khr(2)); VECTOR_CLASS sema_payloads(1); cl::Event event; @@ -3764,7 +3788,7 @@ void testSemaphoreWithProperties(void) VECTOR_CLASS 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()); @@ -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(device);