@@ -160,7 +160,8 @@ cdef class Memory:
160
160
self .queue = None
161
161
self .refobj = None
162
162
163
- cdef _cinit_alloc(self , Py_ssize_t nbytes, bytes ptr_type, SyclQueue queue):
163
+ cdef _cinit_alloc(self , Py_ssize_t alignment, Py_ssize_t nbytes,
164
+ bytes ptr_type, SyclQueue queue):
164
165
cdef DPPLSyclUSMRef p
165
166
166
167
self ._cinit_empty()
@@ -170,11 +171,23 @@ cdef class Memory:
170
171
queue = get_current_queue()
171
172
172
173
if (ptr_type == b" shared" ):
173
- p = DPPLmalloc_shared(nbytes, queue.get_queue_ref())
174
+ if alignment > 0 :
175
+ p = DPPLaligned_alloc_shared(alignment, nbytes,
176
+ queue.get_queue_ref())
177
+ else :
178
+ p = DPPLmalloc_shared(nbytes, queue.get_queue_ref())
174
179
elif (ptr_type == b" host" ):
175
- p = DPPLmalloc_host(nbytes, queue.get_queue_ref())
180
+ if alignment > 0 :
181
+ p = DPPLaligned_alloc_host(alignment, nbytes,
182
+ queue.get_queue_ref())
183
+ else :
184
+ p = DPPLmalloc_host(nbytes, queue.get_queue_ref())
176
185
elif (ptr_type == b" device" ):
177
- p = DPPLmalloc_device(nbytes, queue.get_queue_ref())
186
+ if (alignment > 0 ):
187
+ p = DPPLaligned_alloc_device(alignment, nbytes,
188
+ queue.get_queue_ref())
189
+ else :
190
+ p = DPPLmalloc_device(nbytes, queue.get_queue_ref())
178
191
else :
179
192
raise RuntimeError (" Pointer type is unknown: {}" \
180
193
.format(ptr_type.decode(" UTF-8" )))
@@ -391,10 +404,19 @@ cdef class Memory:
391
404
392
405
393
406
cdef class MemoryUSMShared(Memory):
407
+ """
408
+ MemoryUSMShared(nbytes, alignment=0, queue=None) allocates nbytes of USM shared memory.
409
+
410
+ Non-positive alignments are not used (malloc_shared is used instead).
411
+ The queue=None the current `dpctl.get_current_queue()` is used to allocate memory.
394
412
395
- def __cinit__ (self , other , SyclQueue queue = None ):
396
- if isinstance (other, int ):
397
- self ._cinit_alloc(< Py_ssize_t> other, b" shared" , queue)
413
+ MemoryUSMShared(usm_obj) constructor create instance from `usm_obj` expected to
414
+ implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
415
+ USM memory.
416
+ """
417
+ def __cinit__ (self , other , *, Py_ssize_t alignment = 0 , SyclQueue queue = None ):
418
+ if (isinstance (other, int )):
419
+ self ._cinit_alloc(alignment, < Py_ssize_t> other, b" shared" , queue)
398
420
else :
399
421
self ._cinit_other(other)
400
422
@@ -404,9 +426,9 @@ cdef class MemoryUSMShared(Memory):
404
426
405
427
cdef class MemoryUSMHost(Memory):
406
428
407
- def __cinit__ (self , other , SyclQueue queue = None ):
408
- if isinstance (other, int ):
409
- self ._cinit_alloc(< Py_ssize_t> other, b" host" , queue)
429
+ def __cinit__ (self , other , *, Py_ssize_t alignment = 0 , SyclQueue queue = None ):
430
+ if ( isinstance (other, int ) ):
431
+ self ._cinit_alloc(alignment, < Py_ssize_t> other, b" host" , queue)
410
432
else :
411
433
self ._cinit_other(other)
412
434
@@ -416,8 +438,8 @@ cdef class MemoryUSMHost(Memory):
416
438
417
439
cdef class MemoryUSMDevice(Memory):
418
440
419
- def __cinit__ (self , other , SyclQueue queue = None ):
420
- if isinstance (other, int ):
421
- self ._cinit_alloc(< Py_ssize_t> other, b" device" , queue)
441
+ def __cinit__ (self , other , *, Py_ssize_t alignment = 0 , SyclQueue queue = None ):
442
+ if ( isinstance (other, int ) ):
443
+ self ._cinit_alloc(alignment, < Py_ssize_t> other, b" device" , queue)
422
444
else :
423
445
self ._cinit_other(other)
0 commit comments