diff --git a/.flake8 b/.flake8 index 86ad811269..ff25f5ba17 100644 --- a/.flake8 +++ b/.flake8 @@ -17,5 +17,4 @@ exclude = .git, __pycache__, _version.py, - numpy_usm_shared.py, lowerer.py, diff --git a/numba_dpex/dpctl_iface/kernel_launch_ops.py b/numba_dpex/dpctl_iface/kernel_launch_ops.py index 47253f2826..3adccc75d4 100644 --- a/numba_dpex/dpctl_iface/kernel_launch_ops.py +++ b/numba_dpex/dpctl_iface/kernel_launch_ops.py @@ -5,7 +5,6 @@ from numba.core import cgutils, types from numba.core.ir_utils import legalize_names -from numba_dpex import numpy_usm_shared as nus from numba_dpex import utils from numba_dpex.dpctl_iface import DpctlCAPIFnBuilder from numba_dpex.dpctl_iface._helpers import numba_type_to_dpctl_typenum @@ -251,79 +250,60 @@ def process_kernel_arg( context=self.context, type=types.voidptr ) - if isinstance(arg_type, nus.UsmSharedArrayType): - self._form_kernel_arg_and_arg_ty( + malloc_fn = DpctlCAPIFnBuilder.get_dpctl_malloc_shared( + builder=self.builder, context=self.context + ) + memcpy_fn = DpctlCAPIFnBuilder.get_dpctl_queue_memcpy( + builder=self.builder, context=self.context + ) + event_del_fn = DpctlCAPIFnBuilder.get_dpctl_event_delete( + builder=self.builder, context=self.context + ) + event_wait_fn = DpctlCAPIFnBuilder.get_dpctl_event_wait( + builder=self.builder, context=self.context + ) + + # Not known to be USM so we need to copy to USM. + buffer_name = "buffer_ptr" + str(self.cur_arg) + # Create void * to hold new USM buffer. + buffer_ptr = cgutils.alloca_once( + self.builder, + utils.get_llvm_type(context=self.context, type=types.voidptr), + name=buffer_name, + ) + # Setup the args to the USM allocator, size and SYCL queue. + args = [ + self.builder.load(total_size), + self.builder.load(sycl_queue_val), + ] + # Call USM shared allocator and store in buffer_ptr. + self.builder.store(self.builder.call(malloc_fn, args), buffer_ptr) + + if legal_names[var] in modified_arrays: + self.write_buffs.append((buffer_ptr, total_size, data_member)) + else: + self.read_only_buffs.append( + (buffer_ptr, total_size, data_member) + ) + + # We really need to detect when an array needs to be copied over + if index < self.num_inputs: + args = [ + self.builder.load(sycl_queue_val), + self.builder.load(buffer_ptr), self.builder.bitcast( self.builder.load(data_member), utils.get_llvm_type( context=self.context, type=types.voidptr ), ), - ty, - ) - else: - malloc_fn = DpctlCAPIFnBuilder.get_dpctl_malloc_shared( - builder=self.builder, context=self.context - ) - memcpy_fn = DpctlCAPIFnBuilder.get_dpctl_queue_memcpy( - builder=self.builder, context=self.context - ) - event_del_fn = DpctlCAPIFnBuilder.get_dpctl_event_delete( - builder=self.builder, context=self.context - ) - event_wait_fn = DpctlCAPIFnBuilder.get_dpctl_event_wait( - builder=self.builder, context=self.context - ) - - # Not known to be USM so we need to copy to USM. - buffer_name = "buffer_ptr" + str(self.cur_arg) - # Create void * to hold new USM buffer. - buffer_ptr = cgutils.alloca_once( - self.builder, - utils.get_llvm_type( - context=self.context, type=types.voidptr - ), - name=buffer_name, - ) - # Setup the args to the USM allocator, size and SYCL queue. - args = [ self.builder.load(total_size), - self.builder.load(sycl_queue_val), ] - # Call USM shared allocator and store in buffer_ptr. - self.builder.store( - self.builder.call(malloc_fn, args), buffer_ptr - ) - - if legal_names[var] in modified_arrays: - self.write_buffs.append( - (buffer_ptr, total_size, data_member) - ) - else: - self.read_only_buffs.append( - (buffer_ptr, total_size, data_member) - ) - - # We really need to detect when an array needs to be copied over - if index < self.num_inputs: - args = [ - self.builder.load(sycl_queue_val), - self.builder.load(buffer_ptr), - self.builder.bitcast( - self.builder.load(data_member), - utils.get_llvm_type( - context=self.context, type=types.voidptr - ), - ), - self.builder.load(total_size), - ] - event_ref = self.builder.call(memcpy_fn, args) - self.builder.call(event_wait_fn, [event_ref]) - self.builder.call(event_del_fn, [event_ref]) + event_ref = self.builder.call(memcpy_fn, args) + self.builder.call(event_wait_fn, [event_ref]) + self.builder.call(event_del_fn, [event_ref]) - self._form_kernel_arg_and_arg_ty( - self.builder.load(buffer_ptr), ty - ) + self._form_kernel_arg_and_arg_ty(self.builder.load(buffer_ptr), ty) # Handle shape shape_member = self.builder.gep( diff --git a/numba_dpex/dpctl_iface/usm_allocators_ext.c b/numba_dpex/dpctl_iface/usm_allocators_ext.c deleted file mode 100644 index fa93e0d67c..0000000000 --- a/numba_dpex/dpctl_iface/usm_allocators_ext.c +++ /dev/null @@ -1,358 +0,0 @@ -// SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation -// -// SPDX-License-Identifier: Apache-2.0 - -//===----------------------------------------------------------------------===// -/// -/// \file -/// A Python extension that defines an external allocator for Numba. The -/// new external allocator uses SYCL's USM shared allocator exposed by DPCTL's -/// C API (libDPCTLSyclInterface). The extension module is used by the -/// numpy_usm_shared module. -/// -//===----------------------------------------------------------------------===// - -#include "assert.h" -#include "numba/_pymodule.h" -#include "numba/core/runtime/nrt.h" -#include "numba/core/runtime/nrt_external.h" -#include -#include - -// clang-format off -#if defined __has_include - #if __has_include() - #include - #else - #include - #include - #include - #endif -#else - #include - #include - #include -#endif -// clang-format on - -NRT_ExternalAllocator usmarray_allocator; -NRT_external_malloc_func internal_allocator = NULL; -NRT_external_free_func internal_free = NULL; -void *(*get_queue_internal)(void) = NULL; -void (*free_queue_internal)(void *) = NULL; - -void *save_queue_allocator(size_t size, void *opaque) -{ - // Allocate a pointer-size more space than needed. - size_t new_size = size + sizeof(void *); - // Get a copy of the current queue - void *cur_queue = (void *)DPCTLQueueMgr_GetCurrentQueue(); - // Use that queue to allocate. - void *data = (void *)DPCTLmalloc_shared(new_size, cur_queue); - if (data == NULL) { - printf("Fatal: failed to allocate memory using DPCTLmalloc_shared.\n"); - exit(-1); - } - // Set first pointer-sized data in allocated space to be the current queue. - *(void **)data = cur_queue; - // Return the pointer after this queue in memory. - return (char *)data + sizeof(void *); -} - -void save_queue_deallocator(void *data, void *opaque) -{ - // Compute original allocation location by subtracting the length - // of the queue pointer from the data location that Numba thinks - // starts the object. - void *orig_data = (char *)data - sizeof(void *); - // Get the queue from the original data by derefencing the first qword. - void *obj_queue = *(void **)orig_data; - // Free the space using the correct queue. - DPCTLfree_with_queue(orig_data, obj_queue); - // Free the queue itself. - DPCTLQueue_Delete(obj_queue); -} - -void usmarray_memsys_init(void) -{ - usmarray_allocator.malloc = save_queue_allocator; - usmarray_allocator.realloc = NULL; - usmarray_allocator.free = save_queue_deallocator; - usmarray_allocator.opaque_data = NULL; -} - -void *usmarray_get_ext_allocator(void) { return (void *)&usmarray_allocator; } - -static PyObject *get_external_allocator(PyObject *self, PyObject *args) -{ - return PyLong_FromVoidPtr(usmarray_get_ext_allocator()); -} - -/* - * Internal structure used for allocation and deallocation. - * USM types: - * 0 - shared - * 1 - device - * 2 - host - */ -typedef struct -{ - int usm_type; - void *queue; -} AllocatorImpl; - -/* - * Allocate USM memory. - */ -static void *allocate(size_t size, void *opaque_data) -{ - AllocatorImpl *impl = (AllocatorImpl *)opaque_data; - void *data = 0; - - if (impl->usm_type == 0) { - data = (void *)DPCTLmalloc_shared(size, impl->queue); - if (data == NULL) { - printf( - "Fatal: failed to allocate memory using DPCTLmalloc_shared.\n"); - exit(-1); - } - } - else if (impl->usm_type == 1) { - data = (void *)DPCTLmalloc_host(size, impl->queue); - if (data == NULL) { - printf( - "Fatal: failed to allocate memory using DPCTLmalloc_host.\n"); - exit(-1); - } - } - else if (impl->usm_type == 2) { - data = (void *)DPCTLmalloc_device(size, impl->queue); - if (data == NULL) { - printf( - "Fatal: failed to allocate memory using DPCTLmalloc_device.\n"); - exit(-1); - } - } - - return data; -} - -/* - * Deallocate USM memory. - */ -static void deallocate(void *data, void *opaque_data) -{ - AllocatorImpl *impl = (AllocatorImpl *)opaque_data; - - DPCTLfree_with_queue(data, impl->queue); -} - -/* - * Create external allocator. - * NOTE: experimental. Could be deleted. - */ -static NRT_ExternalAllocator *create_allocator(int usm_type) -{ - AllocatorImpl *impl = (AllocatorImpl *)malloc(sizeof(AllocatorImpl)); - if (impl == NULL) { - printf("Fatal: failed to allocate memory for AllocatorImpl.\n"); - exit(-1); - } - impl->usm_type = usm_type; - impl->queue = (void *)DPCTLQueueMgr_GetCurrentQueue(); - - NRT_ExternalAllocator *allocator = - (NRT_ExternalAllocator *)malloc(sizeof(NRT_ExternalAllocator)); - if (allocator == NULL) { - printf("Fatal: failed to allocate memory for NRT_ExternalAllocator.\n"); - exit(-1); - } - allocator->malloc = allocate; - allocator->realloc = NULL; - allocator->free = deallocate; - allocator->opaque_data = impl; - - return allocator; -} - -/* - * Release external allocator. - * NOTE: experimental. Could be deleted. - */ -static void release_allocator(NRT_ExternalAllocator *allocator) -{ - AllocatorImpl *impl = (AllocatorImpl *)allocator->opaque_data; - DPCTLQueue_Delete(impl->queue); - free(impl); - free(allocator); -} - -/* - * The MemInfo structure. - * NOTE: copy from numba/core/runtime/nrt.c - */ -struct MemInfo -{ - size_t refct; - NRT_dtor_function dtor; - void *dtor_info; - void *data; - size_t size; /* only used for NRT allocated memory */ - NRT_ExternalAllocator *external_allocator; -}; - -/* - * Initialize MemInfo with data. - * NOTE: copy from numba/core/runtime/nrt.c - */ -void NRT_MemInfo_init(NRT_MemInfo *mi, - void *data, - size_t size, - NRT_dtor_function dtor, - void *dtor_info, - NRT_ExternalAllocator *external_allocator) -{ - mi->refct = 1; /* starts with 1 refct */ - mi->dtor = dtor; - mi->dtor_info = dtor_info; - mi->data = data; - mi->size = size; - mi->external_allocator = external_allocator; - NRT_Debug(nrt_debug_print("NRT_MemInfo_init mi=%p external_allocator=%p\n", - mi, external_allocator)); -} - -/* - * Allocate MemInfo and initialize. - * NOTE: copy from numba/core/runtime/nrt.c - */ -NRT_MemInfo *NRT_MemInfo_new(void *data, - size_t size, - NRT_dtor_function dtor, - void *dtor_info) -{ - NRT_MemInfo *mi = (NRT_MemInfo *)malloc(sizeof(NRT_MemInfo)); - if (mi == NULL) { - printf("Fatal: failed to allocate memory for NRT_MemInfo.\n"); - exit(-1); - } - NRT_Debug(nrt_debug_print("NRT_MemInfo_new mi=%p\n", mi)); - NRT_MemInfo_init(mi, data, size, dtor, dtor_info, NULL); - return mi; -} - -/* - * Destructor for allocated USM memory. - */ -static void dtor(void *ptr, size_t size, void *info) -{ - AllocatorImpl *impl = (AllocatorImpl *)info; - - DPCTLfree_with_queue(ptr, impl->queue); - DPCTLQueue_Delete(impl->queue); - free(impl); -} - -/* - * Debugging printf function used internally - * NOTE: copy from numba/core/runtime/nrt.c - */ -void nrt_debug_print(char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); -} - -/* - * Create MemInfo with allocated USM memory with given USM type and queue. - * USM types: - * 0 - shared - * 1 - device - * 2 - host - */ -static NRT_MemInfo *DPRT_MemInfo_new(size_t size, int usm_type, void *queue) -{ - NRT_Debug(nrt_debug_print("DPRT_MemInfo_new size=%d usm_type=%d queue=%p\n", - size, usm_type, queue)); - - AllocatorImpl *impl = (AllocatorImpl *)malloc(sizeof(AllocatorImpl)); - if (impl == NULL) { - printf("Fatal: failed to allocate memory for AllocatorImpl.\n"); - exit(-1); - } - impl->usm_type = usm_type; - impl->queue = queue; - - void *data = allocate(size, impl); - - return NRT_MemInfo_new(data, size, dtor, impl); -} - -/* - * Helper function for creating default queue - */ -void *create_queue() -{ - DPCTLSyclQueueRef queue = DPCTLQueueMgr_GetCurrentQueue(); - - NRT_Debug(nrt_debug_print("create_queue queue=%p\n", queue)); - - return queue; -} - -static PyMethodDef ext_methods[] = { -// clang-format off -#define declmethod_noargs(func) \ - { \ - #func, (PyCFunction)func, METH_NOARGS, NULL \ - } - declmethod_noargs(get_external_allocator), - {NULL}, -#undef declmethod_noargs -}; -// clang-format on - -static PyObject *build_c_helpers_dict(void) -{ - PyObject *dct = PyDict_New(); - if (dct == NULL) - goto error; - -#define _declpointer(name, value) \ - do { \ - PyObject *o = PyLong_FromVoidPtr(value); \ - if (o == NULL) \ - goto error; \ - if (PyDict_SetItemString(dct, name, o)) { \ - Py_DECREF(o); \ - goto error; \ - } \ - Py_DECREF(o); \ - } while (0) - - _declpointer("usmarray_get_ext_allocator", &usmarray_get_ext_allocator); - _declpointer("create_allocator", &create_allocator); - _declpointer("release_allocator", &release_allocator); - _declpointer("DPRT_MemInfo_new", &DPRT_MemInfo_new); - _declpointer("create_queue", &create_queue); - -#undef _declpointer - return dct; -error: - Py_XDECREF(dct); - return NULL; -} - -MOD_INIT(_usm_allocators_ext) -{ - PyObject *m = NULL; - MOD_DEF(m, "numba_dpex._usm_allocators_ext", "No docs", ext_methods) - if (m == NULL) - return MOD_ERROR_VAL; - usmarray_memsys_init(); - PyModule_AddObject(m, "c_helpers", build_c_helpers_dict()); - return MOD_SUCCESS_VAL(m); -} diff --git a/numba_dpex/numpy_usm_shared.py b/numba_dpex/numpy_usm_shared.py deleted file mode 100644 index e542e0c3cc..0000000000 --- a/numba_dpex/numpy_usm_shared.py +++ /dev/null @@ -1,840 +0,0 @@ -# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -import builtins -import functools -import importlib -import inspect -import sys -from ctypes.util import find_library -from inspect import getmembers, isbuiltin, isclass, isfunction -from numbers import Number -from types import BuiltinFunctionType as bftype -from types import FunctionType as ftype - -import dpctl.tensor.numpy_usm_shared as nus -import llvmlite.binding as llb -import llvmlite.llvmpy.core as lc -import numba -import numpy as np -from dpctl.tensor.numpy_usm_shared import class_list, functions_list, ndarray -from llvmlite import ir -from numba import types -from numba.core import cgutils, config, types, typing -from numba.core.datamodel.registry import ( - register_default as register_model_default, -) -from numba.core.imputils import builtin_registry as lower_registry -from numba.core.overload_glue import _overload_glue -from numba.core.pythonapi import box -from numba.core.typing.arraydecl import normalize_shape -from numba.core.typing.npydecl import registry as typing_registry -from numba.core.typing.templates import ( - AttributeTemplate, - CallableTemplate, - bound_function, -) -from numba.core.typing.templates import builtin_registry as templates_registry -from numba.core.typing.templates import signature -from numba.extending import ( - intrinsic, - lower_builtin, - overload_classmethod, - register_model, - type_callable, - typeof_impl, -) -from numba.np import numpy_support -from numba.np.arrayobj import _array_copy - -from numba_dpex.core.datamodel.models import ArrayModel -from numba_dpex.core.types import Array - -from .core.datamodel.models import dpex_data_model_manager - -debug = config.DEBUG - - -def dprint(*args): - if debug: - print(*args) - sys.stdout.flush() - - -import dpctl -from dpctl.memory import MemoryUSMShared - -import numba_dpex._usm_allocators_ext - -# Register the helper function in dppl_rt so that we can insert calls to them via llvmlite. -for ( - py_name, - c_address, -) in numba_dpex._usm_allocators_ext.c_helpers.items(): - llb.add_symbol(py_name, c_address) - - -class UsmSharedArrayType(Array): - """Creates a Numba type for Numpy arrays that are stored in USM shared - memory. We inherit from Numba's existing Numpy array type but overload - how this type is printed during dumping of typing information and we - implement the special __array_ufunc__ function to determine who this - type gets combined with scalars and regular Numpy types. - We re-use Numpy functions as well but those are going to return Numpy - arrays allocated in USM and we use the overloaded copy function to - convert such USM-backed Numpy arrays into typed USM arrays.""" - - def __init__( - self, - dtype, - ndim, - layout, - readonly=False, - name=None, - aligned=True, - addrspace=None, - ): - # This name defines how this type will be shown in Numba's type dumps. - name = "UsmArray:ndarray(%s, %sd, %s)" % (dtype, ndim, layout) - super(UsmSharedArrayType, self).__init__( - dtype, - ndim, - layout, - # py_type=ndarray, - readonly=readonly, - name=name, - addrspace=addrspace, - ) - - def copy(self, *args, **kwargs): - retty = super(UsmSharedArrayType, self).copy(*args, **kwargs) - if isinstance(retty, types.Array): - return UsmSharedArrayType( - dtype=retty.dtype, ndim=retty.ndim, layout=retty.layout - ) - else: - return retty - - # Tell Numba typing how to combine UsmSharedArrayType with other ndarray types. - def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): - if method == "__call__": - for inp in inputs: - if not isinstance( - inp, (UsmSharedArrayType, types.Array, types.Number) - ): - return None - - return UsmSharedArrayType - else: - return None - - @property - def box_type(self): - return ndarray - - -# This tells Numba how to create a UsmSharedArrayType when a usmarray is passed -# into a njit function. -@typeof_impl.register(ndarray) -def typeof_ta_ndarray(val, c): - try: - dtype = numpy_support.from_dtype(val.dtype) - except NotImplementedError: - raise ValueError("Unsupported array dtype: %s" % (val.dtype,)) - layout = numpy_support.map_layout(val) - readonly = not val.flags.writeable - return UsmSharedArrayType(dtype, val.ndim, layout, readonly=readonly) - - -# This tells Numba to use the default Numpy ndarray data layout for -# object of type UsmArray. -register_model(UsmSharedArrayType)(numba.core.datamodel.models.ArrayModel) -dpex_data_model_manager.register( - UsmSharedArrayType, numba.core.datamodel.models.ArrayModel -) - - -# This tells Numba how to convert from its native representation -# of a UsmArray in a njit function back to a Python UsmArray. -@box(UsmSharedArrayType) -def box_array(typ, val, c): - nativearycls = c.context.make_array(typ) - nativeary = nativearycls(c.context, c.builder, value=val) - if c.context.enable_nrt: - np_dtype = numpy_support.as_dtype(typ.dtype) - dtypeptr = c.env_manager.read_const(c.env_manager.add_const(np_dtype)) - # Steals NRT ref - newary = c.pyapi.nrt_adapt_ndarray_to_python(typ, val, dtypeptr) - return newary - else: - parent = nativeary.parent - c.pyapi.incref(parent) - return parent - - -@overload_classmethod(UsmSharedArrayType, "_allocate") -def _ol_array_allocate(cls, allocsize, align): - """Implements a Numba-only classmethod on the array type.""" - - def impl(cls, allocsize, align): - return allocator_UsmArray(allocsize, align) - - return impl - - -# This tells Numba to use this function when it needs to allocate a -# UsmArray in a njit function. -@intrinsic -def allocator_UsmArray(typingctx, allocsize, align): - def impl(context, builder, sig, args): - context.nrt._require_nrt() - size, align = args - - mod = builder.module - u32 = ir.IntType(32) - - # Get the Numba external allocator for USM memory. - ext_allocator_fnty = ir.FunctionType(cgutils.voidptr_t, []) - ext_allocator_fn = cgutils.get_or_insert_function( - mod, ext_allocator_fnty, name="usmarray_get_ext_allocator" - ) - ext_allocator = builder.call(ext_allocator_fn, []) - # Get the Numba function to allocate an aligned array with an external allocator. - fnty = ir.FunctionType( - cgutils.voidptr_t, [cgutils.intp_t, u32, cgutils.voidptr_t] - ) - fn = cgutils.get_or_insert_function( - mod, fnty, name="NRT_MemInfo_alloc_safe_aligned_external" - ) - fn.return_value.add_attribute("noalias") - if isinstance(align, builtins.int): - align = context.get_constant(types.uint32, align) - else: - assert align.type == u32, "align must be a uint32" - call = builder.call(fn, [size, align, ext_allocator]) - call.name = "allocate_UsmArray" - return call - - mip = types.MemInfoPointer(types.voidptr) # return untyped pointer - sig = typing.signature(mip, allocsize, align) - return sig, impl - - -_registered = False - - -def is_usm_callback(obj): - dprint("is_usm_callback:", obj, type(obj)) - if isinstance(obj, numba.core.runtime._nrt_python._MemInfo): - mobj = obj - while isinstance(mobj, numba.core.runtime._nrt_python._MemInfo): - ea = mobj.external_allocator - dppl_rt_allocator = ( - numba_dpex._usm_allocators_ext.get_external_allocator() - ) - dprint("Checking MemInfo:", ea) - if ea == dppl_rt_allocator: - return True - mobj = mobj.parent - if isinstance(mobj, ndarray): - mobj = mobj.base - return False - - -def numba_register(): - global _registered - if not _registered: - _registered = True - ndarray.add_external_usm_checker(is_usm_callback) - numba_register_typing() - numba_register_lower_builtin() - - -# Copy a function registered as a lowerer in Numba but change the -# "np" import in Numba to point to usmarray instead of NumPy. -def copy_func_for_usmarray(f, usmarray_mod): - import copy as cc - - # Make a copy so our change below doesn't affect anything else. - gglobals = cc.copy(f.__globals__) - # Make the "np"'s in the code use usmarray instead of Numba's default NumPy. - gglobals["np"] = usmarray_mod - # Create a new function using the original code but the new globals. - g = ftype(f.__code__, gglobals, None, f.__defaults__, f.__closure__) - # Some other tricks to make sure the function copy works. - g = functools.update_wrapper(g, f) - g.__kwdefaults__ = f.__kwdefaults__ - return g - - -def types_replace_array(x): - return tuple([z if z != types.Array else UsmSharedArrayType for z in x]) - - -def numba_register_lower_builtin(): - todo = [] - todo_builtin = [] - todo_getattr = [] - todo_array_member_func = [] - - for k, v in _overload_glue._registered.items(): - func = k - - for typs, impl in v._BIND_TYPES.items(): - ig = (impl, func, typs) - dprint( - "Numpy lowered registry functions:", - impl, - func, - type(func), - typs, - ) - # If it is a Numpy function... - if isinstance(func, ftype): - dprint("is ftype") - if func.__module__ == np.__name__: - dprint("is Numpy module") - # If we have overloaded that function in the usmarray module (always True right now)... - if func.__name__ in functions_list: - todo.append(ig) - if isinstance(func, bftype): - dprint("is bftype") - if func.__module__ == np.__name__: - dprint("is Numpy module") - # If we have overloaded that function in the usmarray module (always True right now)... - if func.__name__ in functions_list: - todo.append(ig) - if isinstance(func, str) and func.startswith("array."): - todo_array_member_func.append(ig) - - # For all Numpy identifiers that have been registered for typing in Numba... - # this registry contains functions, getattrs, setattrs, casts and constants... - for ig in lower_registry.functions: - impl, func, types = ig - dprint( - "Numpy lowered registry functions:", impl, func, type(func), types - ) - # If it is a Numpy function... - if isinstance(func, ftype): - dprint("is ftype") - if func.__module__ == np.__name__: - dprint("is Numpy module") - # If we have overloaded that function in the usmarray module (always True right now)... - if func.__name__ in functions_list: - todo.append(ig) - if isinstance(func, bftype): - dprint("is bftype") - if func.__module__ == np.__name__: - dprint("is Numpy module") - # If we have overloaded that function in the usmarray module (always True right now)... - if func.__name__ in functions_list: - todo.append(ig) - if isinstance(func, str) and func.startswith("array."): - todo_array_member_func.append(ig) - - for lg in lower_registry.getattrs: - func, attr, types = lg - dprint("Numpy lowered registry getattrs:", func, attr, types) - types_with_usmarray = types_replace_array(types) - if UsmSharedArrayType in types_with_usmarray: - dprint( - "lower_getattr:", - func, - type(func), - attr, - type(attr), - types, - type(types), - ) - todo_getattr.append((func, attr, types_with_usmarray)) - - for lg in todo_getattr: - lower_registry.getattrs.append(lg) - - for impl, func, types in todo + todo_builtin: - try: - usmarray_func = eval( - "dpctl.tensor.numpy_usm_shared." + func.__name__ - ) - except: - dprint("failed to eval", func.__name__) - continue - dprint( - "need to re-register lowerer for usmarray", - impl, - func, - types, - usmarray_func, - ) - new_impl = copy_func_for_usmarray(impl, nus) - lower_registry.functions.append((new_impl, usmarray_func, types)) - - for impl, func, types in todo_array_member_func: - types_with_usmarray = types_replace_array(types) - usmarray_func = "usm" + func - dprint( - "Registering lowerer for", impl, usmarray_func, types_with_usmarray - ) - new_impl = copy_func_for_usmarray(impl, nus) - lower_registry.functions.append( - (new_impl, usmarray_func, types_with_usmarray) - ) - - -def argspec_to_string(argspec): - first_default_arg = len(argspec.args) - len(argspec.defaults) - non_def = argspec.args[:first_default_arg] - arg_zip = list(zip(argspec.args[first_default_arg:], argspec.defaults)) - combined = [a + "=" + str(b) for a, b in arg_zip] - return ",".join(non_def + combined) - - -def numba_register_typing(): - todo = [] - todo_classes = [] - todo_getattr = [] - - for k, v in _overload_glue._registered.items(): - ig = (k, v._TYPER) - val, typ = ig - dprint("Numpy registered:", val, type(val), typ, type(typ)) - if isinstance(val, (ftype, bftype)): - # If we have overloaded that function in the usmarray module (always True right now)... - if val.__name__ in functions_list: - todo.append(ig) - - # For all Numpy identifiers that have been registered for typing in Numba... - for ig in typing_registry.globals: - val, typ = ig - - dprint("Numpy registered:", val, type(val), typ, type(typ)) - # If it is a Numpy function... - if isinstance(val, (ftype, bftype)): - # If we have overloaded that function in the usmarray module (always True right now)... - if val.__name__ in functions_list: - assert len(typ.templates) == 1 - todo.append((val, typ.templates[0])) - if isinstance(val, type): - if isinstance(typ, numba.core.types.functions.Function): - assert len(typ.templates) == 1 - todo.append((val, typ.templates[0])) - elif isinstance(typ, numba.core.types.functions.NumberClass): - pass - - for tgetattr in templates_registry.attributes: - dprint("Numpy getattr:", tgetattr, type(tgetattr), tgetattr.key) - if tgetattr.key == types.Array: - todo_getattr.append(tgetattr) - - for val, typ in todo_classes: - dprint("todo_classes:", val, typ, type(typ)) - - try: - dptype = eval("dpctl.tensor.numpy_usm_shared." + val.__name__) - except: - dprint("failed to eval", val.__name__) - continue - - typing_registry.register_global( - dptype, numba.core.types.NumberClass(typ.instance_type) - ) - - for val, typ in todo: - template = typ - try: - dpval = eval("dpctl.tensor.numpy_usm_shared." + val.__name__) - except: - dprint("failed to eval", val.__name__) - continue - dprint("--------------------------------------------------------------") - dprint("val:", val, type(val), "dir val", dir(val)) - dprint("typ:", typ, type(typ), "dir typ", dir(typ)) - dprint("template:", template, type(template)) - dprint("dpval:", dpval, type(dpval)) - dprint("--------------------------------------------------------------") - - class_name = "DparrayTemplate_" + val.__name__ - - @classmethod - def set_key_original(cls, key, original): - cls.key = key - cls.original = original - - def generic_impl(self): - original_typer = self.__class__.original.generic( - self.__class__.original - ) - ot_argspec = inspect.getfullargspec(original_typer) - astr = argspec_to_string(ot_argspec) - - typer_func = """def typer({}): - original_res = original_typer({}) - if isinstance(original_res, types.Array): - return UsmSharedArrayType( - dtype=original_res.dtype, - ndim=original_res.ndim, - layout=original_res.layout - ) - return original_res""".format( - astr, ",".join(ot_argspec.args) - ) - - try: - gs = globals() - ls = locals() - gs["original_typer"] = ls["original_typer"] - exec(typer_func, globals(), locals()) - except NameError as ne: - print("NameError in exec:", ne) - sys.exit(0) - except: - print("exec failed!", sys.exc_info()[0]) - sys.exit(0) - - try: - exec_res = eval("typer") - except NameError as ne: - print("NameError in eval:", ne) - sys.exit(0) - except: - print("eval failed!", sys.exc_info()[0]) - sys.exit(0) - - return exec_res - - new_usmarray_template = type( - class_name, - (template,), - {"set_class_vars": set_key_original, "generic": generic_impl}, - ) - - new_usmarray_template.set_class_vars(dpval, template) - - assert callable(dpval) - type_handler = types.Function(new_usmarray_template) - typing_registry.register_global(dpval, type_handler) - - # Handle usmarray attribute typing. - # This explicit register_attr of a copied/modified UsmArrayAttribute - # may be removed in the future in favor of the below commented out code - # once we get this registration code to run after everything is registered - # in Numba. Right now, the attribute registrations we need are happening - # after the registration callback that gets us here so we would miss the - # attribute registrations we need. - typing_registry.register_attr(UsmArrayAttribute) - - -class UsmArrayAttribute(AttributeTemplate): - key = UsmSharedArrayType - - def resolve_dtype(self, ary): - return types.DType(ary.dtype) - - def resolve_itemsize(self, ary): - return types.intp - - def resolve_shape(self, ary): - return types.UniTuple(types.intp, ary.ndim) - - def resolve_strides(self, ary): - return types.UniTuple(types.intp, ary.ndim) - - def resolve_ndim(self, ary): - return types.intp - - def resolve_size(self, ary): - return types.intp - - def resolve_flat(self, ary): - return types.NumpyFlatType(ary) - - def resolve_ctypes(self, ary): - return types.ArrayCTypes(ary) - - def resolve_flags(self, ary): - return types.ArrayFlags(ary) - - def convert_array_to_usmarray(self, retty): - if isinstance(retty, types.Array): - return UsmSharedArrayType( - dtype=retty.dtype, ndim=retty.ndim, layout=retty.layout - ) - else: - return retty - - def resolve_T(self, ary): - if ary.ndim <= 1: - retty = ary - else: - layout = {"C": "F", "F": "C"}.get(ary.layout, "A") - retty = ary.copy(layout=layout) - return retty - - def resolve_real(self, ary): - return self._resolve_real_imag(ary, attr="real") - - def resolve_imag(self, ary): - return self._resolve_real_imag(ary, attr="imag") - - def _resolve_real_imag(self, ary, attr): - if ary.dtype in types.complex_domain: - return ary.copy(dtype=ary.dtype.underlying_float, layout="A") - elif ary.dtype in types.number_domain: - res = ary.copy(dtype=ary.dtype) - if attr == "imag": - res = res.copy(readonly=True) - return res - else: - msg = "cannot access .{} of array of {}" - raise TypingError(msg.format(attr, ary.dtype)) - - @bound_function("usmarray.copy") - def resolve_copy(self, ary, args, kws): - assert not args - assert not kws - retty = ary.copy(layout="C", readonly=False) - return signature(retty) - - @bound_function("usmarray.transpose") - def resolve_transpose(self, ary, args, kws): - def sentry_shape_scalar(ty): - if ty in types.number_domain: - # Guard against non integer type - if not isinstance(ty, types.Integer): - raise TypeError("transpose() arg cannot be {0}".format(ty)) - return True - else: - return False - - assert not kws - if len(args) == 0: - return signature(self.resolve_T(ary)) - - if len(args) == 1: - (shape,) = args - - if sentry_shape_scalar(shape): - assert ary.ndim == 1 - return signature(ary, *args) - - if isinstance(shape, types.NoneType): - return signature(self.resolve_T(ary)) - - shape = normalize_shape(shape) - if shape is None: - return - - assert ary.ndim == shape.count - return signature(self.resolve_T(ary).copy(layout="A"), shape) - - else: - if any(not sentry_shape_scalar(a) for a in args): - raise TypeError( - "transpose({0}) is not supported".format(", ".join(args)) - ) - assert ary.ndim == len(args) - return signature(self.resolve_T(ary).copy(layout="A"), *args) - - @bound_function("usmarray.item") - def resolve_item(self, ary, args, kws): - assert not kws - # We don't support explicit arguments as that's exactly equivalent - # to regular indexing. The no-argument form is interesting to - # allow some degree of genericity when writing functions. - if not args: - return signature(ary.dtype) - - @bound_function("usmarray.itemset") - def resolve_itemset(self, ary, args, kws): - assert not kws - # We don't support explicit arguments as that's exactly equivalent - # to regular indexing. The no-argument form is interesting to - # allow some degree of genericity when writing functions. - if len(args) == 1: - return signature(types.none, ary.dtype) - - @bound_function("usmarray.nonzero") - def resolve_nonzero(self, ary, args, kws): - assert not args - assert not kws - # 0-dim arrays return one result array - ndim = max(ary.ndim, 1) - retty = types.UniTuple(UsmSharedArrayType(types.intp, 1, "C"), ndim) - return signature(retty) - - @bound_function("usmarray.reshape") - def resolve_reshape(self, ary, args, kws): - def sentry_shape_scalar(ty): - if ty in types.number_domain: - # Guard against non integer type - if not isinstance(ty, types.Integer): - raise TypeError("reshape() arg cannot be {0}".format(ty)) - return True - else: - return False - - assert not kws - if ary.layout not in "CF": - # only work for contiguous array - raise TypeError("reshape() supports contiguous array only") - - if len(args) == 1: - # single arg - (shape,) = args - - if sentry_shape_scalar(shape): - ndim = 1 - else: - shape = normalize_shape(shape) - if shape is None: - return - ndim = shape.count - retty = ary.copy(ndim=ndim) - return signature(retty, shape) - - elif len(args) == 0: - # no arg - raise TypeError("reshape() take at least one arg") - - else: - # vararg case - if any(not sentry_shape_scalar(a) for a in args): - raise TypeError( - "reshape({0}) is not supported".format( - ", ".join(map(str, args)) - ) - ) - - retty = ary.copy(ndim=len(args)) - return signature(retty, *args) - - @bound_function("usmarray.sort") - def resolve_sort(self, ary, args, kws): - assert not args - assert not kws - if ary.ndim == 1: - return signature(types.none) - - @bound_function("usmarray.argsort") - def resolve_argsort(self, ary, args, kws): - assert not args - kwargs = dict(kws) - kind = kwargs.pop("kind", types.StringLiteral("quicksort")) - if not isinstance(kind, types.StringLiteral): - raise errors.TypingError('"kind" must be a string literal') - if kwargs: - msg = "Unsupported keywords: {!r}" - raise TypingError(msg.format([k for k in kwargs.keys()])) - if ary.ndim == 1: - - def argsort_stub(kind="quicksort"): - pass - - pysig = utils.pysignature(argsort_stub) - sig = signature( - UsmSharedArrayType(types.intp, 1, "C"), kind - ).replace(pysig=pysig) - return sig - - @bound_function("usmarray.view") - def resolve_view(self, ary, args, kws): - from .npydecl import parse_dtype - - assert not kws - (dtype,) = args - dtype = parse_dtype(dtype) - if dtype is None: - return - retty = ary.copy(dtype=dtype) - return signature(retty, *args) - - @bound_function("usmarray.astype") - def resolve_astype(self, ary, args, kws): - from .npydecl import parse_dtype - - assert not kws - (dtype,) = args - dtype = parse_dtype(dtype) - if dtype is None: - return - if not self.context.can_convert(ary.dtype, dtype): - raise TypeError( - "astype(%s) not supported on %s: " - "cannot convert from %s to %s" % (dtype, ary, ary.dtype, dtype) - ) - layout = ary.layout if ary.layout in "CF" else "C" - # reset the write bit irrespective of whether the cast type is the same - # as the current dtype, this replicates numpy - retty = ary.copy(dtype=dtype, layout=layout, readonly=False) - return signature(retty, *args) - - @bound_function("usmarray.ravel") - def resolve_ravel(self, ary, args, kws): - # Only support no argument version (default order='C') - assert not kws - assert not args - return signature(ary.copy(ndim=1, layout="C")) - - @bound_function("usmarray.flatten") - def resolve_flatten(self, ary, args, kws): - # Only support no argument version (default order='C') - assert not kws - assert not args - return signature(ary.copy(ndim=1, layout="C")) - - @bound_function("usmarray.take") - def resolve_take(self, ary, args, kws): - assert not kws - (argty,) = args - if isinstance(argty, types.Integer): - sig = signature(ary.dtype, *args) - elif isinstance(argty, UsmSharedArrayType): - sig = signature(argty.copy(layout="C", dtype=ary.dtype), *args) - elif isinstance(argty, types.List): # 1d lists only - sig = signature(UsmSharedArrayType(ary.dtype, 1, "C"), *args) - elif isinstance(argty, types.BaseTuple): - sig = signature( - UsmSharedArrayType(ary.dtype, np.ndim(argty), "C"), *args - ) - else: - raise TypeError("take(%s) not supported for %s" % argty) - return sig - - def generic_resolve(self, ary, attr): - # Resolution of other attributes, for record arrays - if isinstance(ary.dtype, types.Record): - if attr in ary.dtype.fields: - return ary.copy(dtype=ary.dtype.typeof(attr), layout="A") - - -@typing_registry.register_global(nus.as_ndarray) -class DparrayAsNdarray(CallableTemplate): - def generic(self): - def typer(arg): - return types.Array( - dtype=arg.dtype, ndim=arg.ndim, layout=arg.layout - ) - - return typer - - -@typing_registry.register_global(nus.from_ndarray) -class DparrayFromNdarray(CallableTemplate): - def generic(self): - def typer(arg): - return UsmSharedArrayType( - dtype=arg.dtype, ndim=arg.ndim, layout=arg.layout - ) - - return typer - - -@lower_registry.lower(nus.as_ndarray, UsmSharedArrayType) -def usmarray_conversion_as(context, builder, sig, args): - return _array_copy(context, builder, sig, args) - - -@lower_registry.lower(nus.from_ndarray, types.Array) -def usmarray_conversion_from(context, builder, sig, args): - return _array_copy(context, builder, sig, args) diff --git a/numba_dpex/tests/core/runtime/test_usm_allocators_ext.py b/numba_dpex/tests/core/runtime/test_usm_allocators_ext.py deleted file mode 100644 index 19498af8cb..0000000000 --- a/numba_dpex/tests/core/runtime/test_usm_allocators_ext.py +++ /dev/null @@ -1,107 +0,0 @@ -# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -"""Tests for numba_dpex._usm_allocators_ext -""" - - -def test_members(): - from numba_dpex import _usm_allocators_ext - - members = ["c_helpers", "get_external_allocator"] - - for member in members: - assert hasattr(_usm_allocators_ext, member) - - -def test_c_helpers(): - from numba_dpex._usm_allocators_ext import c_helpers - - functions = [ - "usmarray_get_ext_allocator", - "create_allocator", - "release_allocator", - "DPRT_MemInfo_new", - "create_queue", - ] - - assert len(functions) == len(c_helpers) - - for fn_name in functions: - assert fn_name in c_helpers - assert isinstance(c_helpers[fn_name], int) - - -def test_allocator(): - from ctypes import POINTER, PYFUNCTYPE, Structure, c_int, c_size_t, c_void_p - - from numba_dpex._usm_allocators_ext import c_helpers - - class NRT_ExternalAllocator(Structure): - _fields_ = [ - ("malloc", PYFUNCTYPE(c_void_p, c_size_t, c_void_p)), - ("realloc", c_void_p), - ("free", PYFUNCTYPE(None, c_void_p, c_void_p)), - ("opaque_data", c_void_p), - ] - - fnty = PYFUNCTYPE(POINTER(NRT_ExternalAllocator), c_int) - create_allocator = fnty(c_helpers["create_allocator"]) - - fnty = PYFUNCTYPE(None, c_void_p) - release_allocator = fnty(c_helpers["release_allocator"]) - - for usm_type in (0, 1, 2): - allocator = create_allocator(usm_type) - assert allocator - assert allocator.contents.malloc - assert allocator.contents.realloc is None - assert allocator.contents.free - assert allocator.contents.opaque_data - - data = allocator.contents.malloc(10, allocator.contents.opaque_data) - assert data - allocator.contents.free(data, allocator.contents.opaque_data) - - release_allocator(allocator) - - -def test_meminfo(): - from ctypes import POINTER, PYFUNCTYPE, Structure, c_int, c_size_t, c_void_p - - from numba.core.runtime import _nrt_python - - from numba_dpex._usm_allocators_ext import c_helpers - - class MemInfo(Structure): - _fields_ = [ - ("refct", c_size_t), - ("dtor", c_void_p), - ("dtor_info", c_void_p), - ("data", c_void_p), - ("size", c_size_t), - ("external_allocator", c_void_p), - ] - - fnty = PYFUNCTYPE(POINTER(MemInfo), c_size_t, c_int, c_void_p) - DPRT_MemInfo_new = fnty(c_helpers["DPRT_MemInfo_new"]) - - create_queue = PYFUNCTYPE(c_void_p)(c_helpers["create_queue"]) - - fnty = PYFUNCTYPE(None, POINTER(MemInfo)) - MemInfo_release = fnty(_nrt_python.c_helpers["MemInfo_release"]) - - for usm_type in (0, 1, 2): - queue = create_queue() - mip = DPRT_MemInfo_new(10, usm_type, queue) - mi = mip.contents - - assert mi.refct == 1 - assert mi.dtor - assert mi.dtor_info - assert mi.data - assert mi.size == 10 - assert not mi.external_allocator - - MemInfo_release(mip) diff --git a/numba_dpex/tests/njit_tests/dpnp_ndarray/test_boxing.py b/numba_dpex/tests/njit_tests/dpnp_ndarray/test_boxing.py index 7e195bf640..5fd2392e89 100644 --- a/numba_dpex/tests/njit_tests/dpnp_ndarray/test_boxing.py +++ b/numba_dpex/tests/njit_tests/dpnp_ndarray/test_boxing.py @@ -7,7 +7,6 @@ """ import pytest -from dpctl.tensor.numpy_usm_shared import ndarray as dpctl_ndarray from dpnp import ndarray as dpnp_ndarray from numba import njit @@ -17,7 +16,6 @@ @pytest.mark.parametrize( "array", [ - dpctl_ndarray([1]), pytest.param(dpnp_ndarray([1]), marks=dpnp_mark), ], ) diff --git a/numba_dpex/tests/test_no_copy_usm_shared.py b/numba_dpex/tests/test_no_copy_usm_shared.py deleted file mode 100644 index 3d8ffe0206..0000000000 --- a/numba_dpex/tests/test_no_copy_usm_shared.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright 2020 - 2022 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -import dpctl -import dpctl.tensor.numpy_usm_shared as usmarray -import numpy as np -import pytest -from numba import prange -from numba.core import compiler, cpu -from numba.core.registry import cpu_target - -from numba_dpex.core.pipelines.offload_compiler import OffloadCompiler -from numba_dpex.tests._helper import skip_no_opencl_gpu - - -def fn(a): - for i in prange(a.size): - a[i] += 1 - return a - - -@skip_no_opencl_gpu -def test_no_copy_usm_shared(capfd): - a = usmarray.ones(10, dtype=np.int64) - b = np.ones(10, dtype=np.int64) - # f = njit(fn) - - flags = compiler.Flags() - flags.no_compile = True - flags.no_cpython_wrapper = True - flags.nrt = False - flags.auto_parallel = cpu.ParallelOptions(True) - - typingctx = cpu_target.typing_context - targetctx = cpu_target.target_context - args = typingctx.resolve_argument_type(a) - - device = dpctl.SyclDevice("opencl:gpu:0") - - with dpctl.device_context(device): - cres = compiler.compile_extra( - typingctx=typingctx, - targetctx=targetctx, - func=fn, - args=tuple([args]), - return_type=args, - flags=flags, - locals={}, - pipeline_class=OffloadCompiler, - ) - - assert "DPCTLQueue_Memcpy" not in cres.library.get_llvm_str() - - args = typingctx.resolve_argument_type(b) - cres = compiler.compile_extra( - typingctx=typingctx, - targetctx=targetctx, - func=fn, - args=tuple([args]), - return_type=args, - flags=flags, - locals={}, - pipeline_class=OffloadCompiler, - ) - - assert "DPCTLQueue_Memcpy" in cres.library.get_llvm_str() diff --git a/numba_dpex/tests/test_usmarray.py b/numba_dpex/tests/test_usmarray.py deleted file mode 100644 index 80c0b51070..0000000000 --- a/numba_dpex/tests/test_usmarray.py +++ /dev/null @@ -1,210 +0,0 @@ -# Copyright 2020 - 2022 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -import dpctl.tensor.numpy_usm_shared as usmarray -import numba -import numpy -import pytest - - -@numba.njit() -def numba_mul_add(a): - return a * 2.0 + 13 - - -@numba.njit() -def numba_add_const(a): - return a + 13 - - -@numba.njit() -def numba_mul(a, b): # a is usmarray, b is numpy - return a * b - - -@numba.njit() -def numba_mul_usmarray_asarray(a, b): # a is usmarray, b is numpy - return a * usmarray.asarray(b) - - -@numba.njit -def numba_usmarray_as_ndarray(a): - return usmarray.as_ndarray(a) - - -@numba.njit -def numba_usmarray_from_ndarray(a): - return usmarray.from_ndarray(a) - - -@numba.njit() -def numba_usmarray_ones(): - return usmarray.ones(10) - - -@numba.njit -def numba_usmarray_empty(): - return usmarray.empty((10, 10)) - - -@numba.njit() -def numba_identity(a): - return a - - -@numba.njit -def numba_shape(x): - return x.shape - - -@numba.njit -def numba_T(x): - return x.T - - -@numba.njit -def numba_reshape(x): - return x.reshape((4, 3)) - - -class TestUsmArray: - def ndarray(self): - """Create NumPy array""" - return numpy.ones(10) - - def usmarray(self): - """Create dpCtl USM array""" - return usmarray.ones(10) - - def test_python_numpy(self): - """Testing Python Numpy""" - z2 = numba_mul_add.py_func(self.ndarray()) - assert type(z2) == numpy.ndarray, z2 - - def test_numba_numpy(self): - """Testing Numba Numpy""" - z2 = numba_mul_add(self.ndarray()) - assert type(z2) == numpy.ndarray, z2 - - def test_usmarray_ones(self): - """Testing usmarray ones""" - a = usmarray.ones(10) - assert isinstance(a, usmarray.ndarray), type(a) - assert usmarray.has_array_interface(a) - - def test_usmarray_usmarray_as_ndarray(self): - """Testing usmarray.usmarray.as_ndarray""" - nd1 = self.usmarray().as_ndarray() - assert type(nd1) == numpy.ndarray, nd1 - - def test_usmarray_as_ndarray(self): - """Testing usmarray.as_ndarray""" - nd2 = usmarray.as_ndarray(self.usmarray()) - assert type(nd2) == numpy.ndarray, nd2 - - def test_usmarray_from_ndarray(self): - """Testing usmarray.from_ndarray""" - nd2 = usmarray.as_ndarray(self.usmarray()) - dp1 = usmarray.from_ndarray(nd2) - assert isinstance(dp1, usmarray.ndarray), type(dp1) - assert usmarray.has_array_interface(dp1) - - def test_usmarray_multiplication(self): - """Testing usmarray multiplication""" - c = self.usmarray() * 5 - assert isinstance(c, usmarray.ndarray), type(c) - assert usmarray.has_array_interface(c) - - def test_python_usmarray_mul_add(self): - """Testing Python usmarray""" - c = self.usmarray() * 5 - b = numba_mul_add.py_func(c) - assert isinstance(b, usmarray.ndarray), type(b) - assert usmarray.has_array_interface(b) - - @pytest.mark.skip(reason="Fails if run tests in bunch") - def test_numba_usmarray_mul_add(self): - """Testing Numba usmarray""" - c = self.usmarray() * 5 - b = numba_mul_add(c) - assert isinstance(b, usmarray.ndarray), type(b) - assert usmarray.has_array_interface(b) - - def test_python_mixing_usmarray_and_numpy_ndarray(self): - """Testing Python mixing usmarray and numpy.ndarray""" - h = numba_mul.py_func(self.usmarray(), self.ndarray()) - assert isinstance(h, usmarray.ndarray), type(h) - assert usmarray.has_array_interface(h) - - def test_numba_usmarray_2(self): - """Testing Numba usmarray 2""" - d = numba_identity(self.usmarray()) - assert isinstance(d, usmarray.ndarray), type(d) - assert usmarray.has_array_interface(d) - - @pytest.mark.xfail - def test_numba_usmarray_constructor_from_numpy_ndarray(self): - """Testing Numba usmarray constructor from numpy.ndarray""" - e = numba_mul_usmarray_asarray(self.usmarray(), self.ndarray()) - assert isinstance(e, usmarray.ndarray), type(e) - - def test_numba_mixing_usmarray_and_constant(self): - """Testing Numba mixing usmarray and constant""" - g = numba_add_const(self.usmarray()) - assert isinstance(g, usmarray.ndarray), type(g) - assert usmarray.has_array_interface(g) - - def test_numba_mixing_usmarray_and_numpy_ndarray(self): - """Testing Numba mixing usmarray and numpy.ndarray""" - h = numba_mul(self.usmarray(), self.ndarray()) - assert isinstance(h, usmarray.ndarray), type(h) - assert usmarray.has_array_interface(h) - - @pytest.mark.skip - def test_numba_usmarray_functions(self): - """Testing Numba usmarray functions""" - f = numba_usmarray_ones() - assert isinstance(f, usmarray.ndarray), type(f) - assert usmarray.has_array_interface(f) - - def test_numba_usmarray_as_ndarray(self): - """Testing Numba usmarray.as_ndarray""" - nd3 = numba_usmarray_as_ndarray(self.usmarray()) - assert type(nd3) == numpy.ndarray, nd3 - - def test_numba_usmarray_from_ndarray(self): - """Testing Numba usmarray.from_ndarray""" - nd3 = numba_usmarray_as_ndarray(self.usmarray()) - dp2 = numba_usmarray_from_ndarray(nd3) - assert isinstance(dp2, usmarray.ndarray), type(dp2) - assert usmarray.has_array_interface(dp2) - - @pytest.mark.skip - def test_numba_usmarray_empty(self): - """Testing Numba usmarray.empty""" - dp3 = numba_usmarray_empty() - assert isinstance(dp3, usmarray.ndarray), type(dp3) - assert usmarray.has_array_interface(dp3) - - @pytest.mark.skip - def test_numba_usmarray_shape(self): - """Testing Numba usmarray.shape""" - s1 = numba_shape(numba_usmarray_empty()) - assert isinstance(s1, tuple), type(s1) - assert s1 == (10, 10) - - @pytest.mark.skip - def test_numba_usmarray_T(self): - """Testing Numba usmarray.T""" - dp4 = numba_T(numba_usmarray_empty()) - assert isinstance(dp4, usmarray.ndarray), type(dp4) - assert usmarray.has_array_interface(dp4) - - @pytest.mark.xfail - def test_numba_usmarray_reshape(self): - """Testing Numba usmarray.reshape()""" - a = usmarray.ones(12) - s1 = numba_reshape(a) - assert isinstance(s1, usmarray.ndarray), type(s1) - assert s1.shape == (4, 3) diff --git a/setup.py b/setup.py index 44560eb640..eadf54d1c7 100644 --- a/setup.py +++ b/setup.py @@ -45,16 +45,6 @@ def get_ext_modules(): if IS_LIN: dpctl_runtime_library_dirs.append(os.path.dirname(dpctl.__file__)) - ext_usm_alloc = Extension( - name="numba_dpex._usm_allocators_ext", - sources=["numba_dpex/dpctl_iface/usm_allocators_ext.c"], - include_dirs=[numba.core.extending.include_path(), dpctl.get_include()], - libraries=["DPCTLSyclInterface"], - library_dirs=[os.path.dirname(dpctl.__file__)], - runtime_library_dirs=dpctl_runtime_library_dirs, - ) - ext_modules += [ext_usm_alloc] - if dpnp_present: dpnp_lib_path = [] dpnp_lib_path += [os.path.dirname(dpnp.__file__)] @@ -212,11 +202,7 @@ def _llvm_spirv(): "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Compilers", ], - entry_points={ - "numba_extensions": [ - "init = numba_dpex.numpy_usm_shared:numba_register", - ] - }, + entry_points={}, ) setup(**metadata)