Skip to content

Commit d98be7b

Browse files
Standardizes the names of DPPL functions (#44)
* Move _memory.pyx * Import setuptools before Cython. Otherwise, both might disagree about the class to use. * Add dppl._memory Cython module. * Run dppl/tests/dppl_tests too when run all unit tests. * Add tests for memory manager. * Split tests for memory. One test one context (no, CPU, GPU). * [opt] Rename getpyexts() to extensions(). * Adds C and Cython API for portions of Sycl queue, device, context interfaces. - Separates out the queue manager from the sycl queue interface wrapper. - Added API to get context, device froma Sycl queue. - Added C-API wrappers for sycl device, queue, context interfaces exposing some of the API functionalities. More can be added as needed. - The dppl extension now defines extension types for sycl quque, device, context to mimic the C API. - Sycl queues are now returned to callers as a SyclQueue extension type rather than a Py_capsule. * Add C-API stub library for sycl memory. * Add missing DPPL_API. * Move platform specific functions into a separate file. * Create a single utility function to delete C strings. * Update backends/source/dppl_utils.cpp New line at EOF. * Add _sycl_core.pxd file. * Remove using of PyCapsule in _memory.pyx. * Small style fixes in _memory.pyx. * Moved functions from _memory.pyx to C-API interface library. * Move Cython definitions for backend to single pxd file. * Remove SyclQueue from _memory.pyx * Use SyclQueue from * Remove cl::sycl::queue from _memory.pyx * Removed commented code from _memory.pyx * Eliminate temporary context object. * Fix style. * Add MemoryUSM* classes. * Add __getbuffer__ to Shared and Host MemoryUSM classes. * Rename C-API types for USM. * Add DPPLUSM_GetPointerType and remove types from CL/sycl.hpp from _memory.pyx * Clean unused code from _memory_.pyx * Small fixes. * Remove unused code. * Fix style. * Fix style * Use wrap(). * Store context instead of queue in Memory class. * Pass queue as parameter to constructor. If queue is None then get dppl current queue. * Add comment about casting memory_ptr to char*. * Remove pointer property from Memory. * Rename file with usm tests. * Standardize the names of DPPL functions on DPPLXXX_FuncName. * Fix files. * Rename the CString deleter to follow convention in rest of the library. Co-authored-by: Sergey Pokhodenko <[email protected]> Co-authored-by: Sergey Pokhodenko <[email protected]>
1 parent e590884 commit d98be7b

14 files changed

+146
-143
lines changed

backends/include/dppl_sycl_context_interface.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ DPPL_C_EXTERN_C_BEGIN
3737
/*!
3838
* @brief Returns true if this SYCL context is a host context.
3939
*
40-
* @param CtxtRef A opaque pointer to a sycl::context.
40+
* @param CtxRef A opaque pointer to a sycl::context.
4141
* @return True if the SYCL context is a host context, else False.
4242
*/
4343
DPPL_API
44-
bool DPPLIsHostContext (__dppl_keep const DPPLSyclContextRef CtxtRef);
44+
bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef);
4545

4646
/*!
4747
* @brief Delete the pointer after casting it to sycl::context
4848
*
49-
* @param CtxtRef The DPPLSyclContextRef pointer to be deleted.
49+
* @param CtxRef The DPPLSyclContextRef pointer to be deleted.
5050
*/
5151
DPPL_API
52-
void DPPLDeleteSyclContext (__dppl_take DPPLSyclContextRef CtxtRef);
52+
void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef);
5353

5454
DPPL_C_EXTERN_C_END

backends/include/dppl_sycl_device_interface.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ typedef enum
5757
* @param DRef A DPPLSyclDeviceRef pointer.
5858
*/
5959
DPPL_API
60-
void DPPLDumpDeviceInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
60+
void DPPLDevice_DumpInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
6161

6262
/*!
6363
* @brief Deletes a DPPLSyclDeviceRef pointer after casting to to sycl::device.
6464
*
6565
* @param DRef The DPPLSyclDeviceRef pointer to be freed.
6666
*/
6767
DPPL_API
68-
void DPPLDeleteSyclDevice (__dppl_take DPPLSyclDeviceRef DRef);
68+
void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef);
6969

7070
/*!
7171
* @brief Returns true if this SYCL device is an OpenCL device and the device
@@ -75,7 +75,7 @@ void DPPLDeleteSyclDevice (__dppl_take DPPLSyclDeviceRef DRef);
7575
* @return True if the device type is an accelerator, else False.
7676
*/
7777
DPPL_API
78-
bool DPPLDeviceIsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef);
78+
bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef);
7979

8080
/*!
8181
* @brief Returns true if this SYCL device is an OpenCL device and the device
@@ -85,7 +85,7 @@ bool DPPLDeviceIsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef);
8585
* @return True if the device type is a cpu, else False.
8686
*/
8787
DPPL_API
88-
bool DPPLDeviceIsCPU (__dppl_keep const DPPLSyclDeviceRef DRef);
88+
bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef);
8989

9090
/*!
9191
* @brief Returns true if this SYCL device is an OpenCL device and the device
@@ -95,7 +95,7 @@ bool DPPLDeviceIsCPU (__dppl_keep const DPPLSyclDeviceRef DRef);
9595
* @return True if the device type is a gpu, else False.
9696
*/
9797
DPPL_API
98-
bool DPPLDeviceIsGPU (__dppl_keep const DPPLSyclDeviceRef DRef);
98+
bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef);
9999

100100
/*!
101101
* @brief Returns true if this SYCL device is a host device.
@@ -104,7 +104,7 @@ bool DPPLDeviceIsGPU (__dppl_keep const DPPLSyclDeviceRef DRef);
104104
* @return True if the device is a host device, else False.
105105
*/
106106
DPPL_API
107-
bool DPPLDeviceIsHost (__dppl_keep const DPPLSyclDeviceRef DRef);
107+
bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef);
108108

109109
/*!
110110
* @brief Returns the OpenCL software driver version as a C string.
@@ -115,7 +115,7 @@ bool DPPLDeviceIsHost (__dppl_keep const DPPLSyclDeviceRef DRef);
115115
*/
116116
DPPL_API
117117
__dppl_give const char*
118-
DPPLGetDeviceDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
118+
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
119119

120120
/*!
121121
* @brief Returns a C string for the device name.
@@ -125,7 +125,7 @@ DPPLGetDeviceDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
125125
*/
126126
DPPL_API
127127
__dppl_give const char*
128-
DPPLGetDeviceName (__dppl_keep const DPPLSyclDeviceRef DRef);
128+
DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef);
129129

130130
/*!
131131
* @brief Returns a C string corresponding to the vendor name.
@@ -135,7 +135,7 @@ DPPLGetDeviceName (__dppl_keep const DPPLSyclDeviceRef DRef);
135135
*/
136136
DPPL_API
137137
__dppl_give const char*
138-
DPPLGetDeviceVendorName (__dppl_keep const DPPLSyclDeviceRef DRef);
138+
DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef);
139139

140140
/*!
141141
* @brief Returns True if the device and the host share a unified memory
@@ -146,6 +146,6 @@ DPPLGetDeviceVendorName (__dppl_keep const DPPLSyclDeviceRef DRef);
146146
* with the host.
147147
*/
148148
DPPL_API
149-
bool DPPLGetDeviceHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef);
149+
bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef);
150150

151151
DPPL_C_EXTERN_C_END

backends/include/dppl_sycl_queue_interface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ DPPL_C_EXTERN_C_BEGIN
4343
*/
4444
DPPL_API
4545
__dppl_give DPPLSyclContextRef
46-
DPPLGetContextFromQueue (__dppl_keep const DPPLSyclQueueRef QRef);
46+
DPPLQueue_GetContext (__dppl_keep const DPPLSyclQueueRef QRef);
4747

4848
/*!
4949
* @brief returns the Sycl device for the queue.
@@ -53,14 +53,14 @@ DPPLGetContextFromQueue (__dppl_keep const DPPLSyclQueueRef QRef);
5353
*/
5454
DPPL_API
5555
__dppl_give DPPLSyclDeviceRef
56-
DPPLGetDeviceFromQueue (__dppl_keep const DPPLSyclQueueRef QRef);
56+
DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef);
5757

5858
/*!
5959
* @brief Delete the pointer after casting it to sycl::queue.
6060
*
6161
* @param QRef A DPPLSyclQueueRef pointer that gets deleted.
6262
*/
6363
DPPL_API
64-
void DPPLDeleteSyclQueue (__dppl_take DPPLSyclQueueRef QRef);
64+
void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef);
6565

6666
DPPL_C_EXTERN_C_END

backends/include/dppl_sycl_queue_manager.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DPPL_C_EXTERN_C_BEGIN
5050
* wrapped inside an opaque DPPLSyclQueueRef pointer.
5151
*/
5252
DPPL_API
53-
__dppl_give DPPLSyclQueueRef DPPLGetCurrentQueue ();
53+
__dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue ();
5454

5555
/*!
5656
* @brief Get a sycl::queue object of the specified type and device id.
@@ -63,8 +63,8 @@ __dppl_give DPPLSyclQueueRef DPPLGetCurrentQueue ();
6363
* raised if no such device exists.
6464
*/
6565
DPPL_API
66-
__dppl_give DPPLSyclQueueRef DPPLGetQueue (DPPLSyclDeviceType DeviceTy,
67-
size_t DNum);
66+
__dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclDeviceType DeviceTy,
67+
size_t DNum);
6868

6969
/*!
7070
* @brief Get the number of activated queues not including the global or
@@ -73,23 +73,23 @@ __dppl_give DPPLSyclQueueRef DPPLGetQueue (DPPLSyclDeviceType DeviceTy,
7373
* @return The number of activated queues.
7474
*/
7575
DPPL_API
76-
size_t DPPLGetNumActivatedQueues ();
76+
size_t DPPLQueueMgr_GetNumActivatedQueues ();
7777

7878
/*!
7979
* @brief Get the number of GPU queues available on the system.
8080
*
8181
* @return The number of available GPU queues.
8282
*/
8383
DPPL_API
84-
size_t DPPLGetNumGPUQueues ();
84+
size_t DPPLQueueMgr_GetNumGPUQueues ();
8585

8686
/*!
8787
* @brief Get the number of CPU queues available on the system.
8888
*
8989
* @return The number of available CPU queues.
9090
*/
9191
DPPL_API
92-
size_t DPPLGetNumCPUQueues ();
92+
size_t DPPLQueueMgr_GetNumCPUQueues ();
9393

9494
/*!
9595
* @brief Set the default DPPL queue to the sycl::queue for the given device.
@@ -100,8 +100,8 @@ size_t DPPLGetNumCPUQueues ();
100100
* @param DNum Device id for the device (defaults to 0)
101101
*/
102102
DPPL_API
103-
void DPPLSetAsDefaultQueue (DPPLSyclDeviceType DeviceTy,
104-
size_t DNum);
103+
void DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclDeviceType DeviceTy,
104+
size_t DNum);
105105

106106
/*!
107107
* @brief Pushes a new sycl::queue object to the top of DPPL's thread-local
@@ -110,11 +110,11 @@ void DPPLSetAsDefaultQueue (DPPLSyclDeviceType DeviceTy,
110110
* DPPL maintains a thread-local stack of sycl::queue objects to facilitate
111111
* nested parallelism. The sycl::queue at the top of the stack is termed as the
112112
* currently activated queue, and is always the one returned by
113-
* DPPLGetCurrentQueue(). DPPLPushSyclQueueToStack creates a new sycl::queue
114-
* corresponding to the specified device and pushes it to the top of the stack.
115-
* A copy of the sycl::queue is returned to the caller wrapped inside the
116-
* opaque DPPLSyclQueueRef pointer. A runtime_error exception is thrown when
117-
* a new sycl::queue could not be created for the specified device.
113+
* DPPLQueueMgr_GetCurrentQueue(). DPPLPushSyclQueueToStack creates a new
114+
* sycl::queue corresponding to the specified device and pushes it to the top
115+
* of the stack. A copy of the sycl::queue is returned to the caller wrapped
116+
* inside the opaque DPPLSyclQueueRef pointer. A runtime_error exception is
117+
* thrown when a new sycl::queue could not be created for the specified device.
118118
*
119119
* @param DeviceTy The type of Sycl device (sycl_device_type)
120120
* @param DNum Device id for the device (defaults to 0)
@@ -123,21 +123,21 @@ void DPPLSetAsDefaultQueue (DPPLSyclDeviceType DeviceTy,
123123
* stack of sycl::queue objects.
124124
*/
125125
DPPL_API
126-
__dppl_give DPPLSyclQueueRef DPPLPushSyclQueue (DPPLSyclDeviceType DeviceTy,
127-
size_t DNum);
126+
__dppl_give DPPLSyclQueueRef
127+
DPPLQueueMgr_PushQueue (DPPLSyclDeviceType DeviceTy, size_t DNum);
128128

129129
/*!
130130
* @brief Pops the top of stack element from DPPL's stack of activated
131131
* sycl::queue objects.
132132
*
133133
* DPPLPopSyclQueue only removes the reference from the DPPL stack of
134134
* sycl::queue objects. Any instance of the popped queue that were previously
135-
* acquired by calling DPPLPushSyclQueue() or DPPLGetCurrentQueue() needs to be
136-
* freed separately. In addition, a runtime_error is thrown when the stack
137-
* contains only one sycl::queue, i.e., the default queue.
135+
* acquired by calling DPPLPushSyclQueue() or DPPLQueueMgr_GetCurrentQueue()
136+
* needs to be freed separately. In addition, a runtime_error is thrown when
137+
* the stack contains only one sycl::queue, i.e., the default queue.
138138
*
139139
*/
140140
DPPL_API
141-
void DPPLPopSyclQueue ();
141+
void DPPLQueueMgr_PopQueue ();
142142

143143
DPPL_C_EXTERN_C_END

backends/include/dppl_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ DPPL_C_EXTERN_C_BEGIN
3636
* @param str C string to be deleted
3737
*/
3838
DPPL_API
39-
void DPPLDeleteCString (__dppl_take const char* str);
39+
void DPPLCString_Delete (__dppl_take const char* str);
4040

4141
DPPL_C_EXTERN_C_END

backends/source/dppl_sycl_context_interface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ namespace
4242
* @param CtxtRef My Param doc
4343
* @return {return} My Param doc
4444
*/
45-
bool DPPLIsHostContext (__dppl_keep const DPPLSyclContextRef CtxtRef)
45+
bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef)
4646
{
47-
return unwrap(CtxtRef)->is_host();
47+
return unwrap(CtxRef)->is_host();
4848
}
4949

5050
/*!
5151
* @brief
5252
*
5353
* @param CtxtRef My Param doc
5454
*/
55-
void DPPLDeleteSyclContext (__dppl_take DPPLSyclContextRef CtxtRef)
55+
void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef)
5656
{
57-
delete unwrap(CtxtRef);
57+
delete unwrap(CtxRef);
5858
}

backends/source/dppl_sycl_device_interface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,41 @@ void dump_device_info (const device & Device)
6666
* vendor, and device profile are printed out. More attributed may be added
6767
* later.
6868
*/
69-
void DPPLDumpDeviceInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
69+
void DPPLDevice_DumpInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
7070
{
7171
auto Device = unwrap(DRef);
7272
dump_device_info(*Device);
7373
}
7474

7575

76-
void DPPLDeleteSyclDevice (__dppl_take DPPLSyclDeviceRef DRef)
76+
void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef)
7777
{
7878
delete unwrap(DRef);
7979
}
8080

81-
bool DPPLDeviceIsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef)
81+
bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef)
8282
{
8383
return unwrap(DRef)->is_accelerator();
8484
}
8585

86-
bool DPPLDeviceIsCPU (__dppl_keep const DPPLSyclDeviceRef DRef)
86+
bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef)
8787
{
8888
return unwrap(DRef)->is_cpu();
8989
}
9090

91-
bool DPPLDeviceIsGPU (__dppl_keep const DPPLSyclDeviceRef DRef)
91+
bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef)
9292
{
9393
return unwrap(DRef)->is_gpu();
9494
}
9595

9696

97-
bool DPPLDeviceIsHost (__dppl_keep const DPPLSyclDeviceRef DRef)
97+
bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef)
9898
{
9999
return unwrap(DRef)->is_host();
100100
}
101101

102102
__dppl_give const char*
103-
DPPLGetDeviceName (__dppl_keep const DPPLSyclDeviceRef DRef)
103+
DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef)
104104
{
105105
auto name = unwrap(DRef)->get_info<info::device::name>();
106106
auto cstr_name = new char [name.length()+1];
@@ -109,7 +109,7 @@ DPPLGetDeviceName (__dppl_keep const DPPLSyclDeviceRef DRef)
109109
}
110110

111111
__dppl_give const char*
112-
DPPLGetDeviceVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
112+
DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
113113
{
114114
auto vendor = unwrap(DRef)->get_info<info::device::name>();
115115
auto cstr_vendor = new char [vendor.length()+1];
@@ -118,15 +118,15 @@ DPPLGetDeviceVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
118118
}
119119

120120
__dppl_give const char*
121-
DPPLGetDeviceDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
121+
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
122122
{
123123
auto driver = unwrap(DRef)->get_info<info::device::driver_version>();
124124
auto cstr_driver = new char [driver.length()+1];
125125
std::strcpy (cstr_driver, driver.c_str());
126126
return cstr_driver;
127127
}
128128

129-
bool DPPLGetDeviceHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef)
129+
bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef)
130130
{
131131
return unwrap(DRef)->get_info<info::device::host_unified_memory>();
132132
}

backends/source/dppl_sycl_queue_interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ namespace
3939
} /* end of anonymous namespace */
4040

4141
__dppl_give DPPLSyclDeviceRef
42-
DPPLGetDeviceFromQueue (__dppl_keep const DPPLSyclQueueRef QRef)
42+
DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef)
4343
{
4444
auto Q = unwrap(QRef);
4545
auto Device = new device(Q->get_device());
4646
return reinterpret_cast<DPPLSyclDeviceRef>(Device);
4747
}
4848

4949
__dppl_give DPPLSyclContextRef
50-
DPPLGetContextFromQueue (__dppl_keep const DPPLSyclQueueRef QRef)
50+
DPPLQueue_GetContext (__dppl_keep const DPPLSyclQueueRef QRef)
5151
{
5252
auto Q = unwrap(QRef);
5353
auto Context = new context(Q->get_context());
@@ -57,7 +57,7 @@ DPPLGetContextFromQueue (__dppl_keep const DPPLSyclQueueRef QRef)
5757
/*!
5858
* Delete the passed in pointer after verifying it points to a sycl::queue.
5959
*/
60-
void DPPLDeleteSyclQueue (__dppl_take DPPLSyclQueueRef QRef)
60+
void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef)
6161
{
6262
delete unwrap(QRef);
6363
}

0 commit comments

Comments
 (0)