Skip to content

Add support for dpctl.dparray. #50

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

Merged
merged 45 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7dd904d
Add support for dpctl.dparray.
PokhodenkoSA Dec 4, 2020
26d5e2e
Fix build issues for dppy_rt.c
DrTodd13 Dec 9, 2020
a320b50
Name changes from dparray things to usmarray.
DrTodd13 Dec 9, 2020
f9de97a
Delete old backup file (#45)
1e-to Dec 4, 2020
b8c11f7
Del dppl dir in tests (#43)
1e-to Dec 4, 2020
16fb9b8
Revert "numba-dppy requires cffi"
PokhodenkoSA Dec 4, 2020
56e969a
Remove use of cffi
PokhodenkoSA Dec 4, 2020
0a56e08
Rename dppl to dppy (#42)
1e-to Dec 7, 2020
023fef9
Pass to rewrite Numpy function names to be able to overload them for …
reazulhoque Dec 9, 2020
059a5a3
Store allocation queue on a per-object basis.
DrTodd13 Dec 10, 2020
f895e1d
Merge branch 'main' into spokhode/dparray
PokhodenkoSA Dec 10, 2020
4e99a55
Add imports to usmarray module and fixed setup.py extension initializ…
PokhodenkoSA Dec 10, 2020
595f94b
Register is_usm_callback with dpctl to say whether a given Python obj…
DrTodd13 Dec 11, 2020
c87a94b
Remove printf.
DrTodd13 Dec 11, 2020
1214893
There were some spots where there was a silent assumption that the cl…
DrTodd13 Dec 11, 2020
a2b2bb7
Found another spot where the current module was being used rather tha…
DrTodd13 Dec 11, 2020
0769a97
Fix numba path
Dec 15, 2020
eb53c26
fix
Dec 15, 2020
f4333dd
Convert tests for USM array to unittest (#118)
PokhodenkoSA Dec 15, 2020
313727b
Small code fixes
PokhodenkoSA Dec 15, 2020
ff877fc
use include_path to find numba
Dec 15, 2020
f5b1989
Added loader lib for win
Dec 16, 2020
8b4a946
Merge branch 'main' into spokhode/dparray
PokhodenkoSA Dec 16, 2020
5d8dd39
Use unittest.TestCase as base class for TestUsmArray
PokhodenkoSA Dec 16, 2020
1303b5f
Merge branch 'main' into spokhode/dparray
PokhodenkoSA Dec 16, 2020
be6a2ca
Copy Numba array attribute code and replace array type with usmarray …
DrTodd13 Dec 16, 2020
2a1a0fb
Merge branch 'main' into spokhode/dparray
PokhodenkoSA Dec 17, 2020
5ddc665
Update meta.yaml
PokhodenkoSA Dec 17, 2020
883c713
Fixed the attribute typing issue. So now, transpose works.
DrTodd13 Dec 21, 2020
602f7e4
dpCtl >=0.5.1rc1
PokhodenkoSA Dec 22, 2020
0355b25
Remove expectedFailure for test_numba_usmarray_mul_add. It could fail…
PokhodenkoSA Dec 22, 2020
cd4058c
Revert "Update meta.yaml"
PokhodenkoSA Dec 22, 2020
9b4e707
Fix dpCtl library name on Windows
PokhodenkoSA Dec 22, 2020
f7b56d7
Fix checks for imported functions from dpCtl library.
PokhodenkoSA Dec 22, 2020
8fd8e5e
Include numba/.../*.h in C code
PokhodenkoSA Dec 22, 2020
4aa05b7
black formatter
PokhodenkoSA Dec 23, 2020
373d139
Merge branch 'main' into spokhode/dparray
PokhodenkoSA Dec 23, 2020
88cac15
Add ndarray.reshape test that is at the moment an expected failure.
DrTodd13 Jan 6, 2021
3781e17
Support for typing and lowering of member function of usmarray.ndarray.
DrTodd13 Jan 6, 2021
dfb3560
black formatter changes.
DrTodd13 Jan 7, 2021
384ebd4
Remove unused test.
DrTodd13 Jan 7, 2021
738a14f
Code review changes.
DrTodd13 Jan 7, 2021
3534b6e
black changes.
DrTodd13 Jan 7, 2021
68733f4
black changes.
DrTodd13 Jan 7, 2021
d56a463
Update numba_dppy/numpy_usm_shared.py
PokhodenkoSA Jan 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ https://intelpython.github.io/dpnp/
## Dependencies

* numba >=0.51 (IntelPython/numba)
* dpCtl 0.5.*
* dpCtl >=0.5.1
* dpNP 0.4.* (optional)
* llvm-spirv (SPIRV generation from LLVM IR)
* llvmdev (LLVM IR generation)
Expand Down
4 changes: 2 additions & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ requirements:
- setuptools
- cython
- numba
- dpctl 0.5.*
- dpctl >=0.5.1rc1
- dpnp 0.4.* # [linux]
run:
- python
- numba >=0.51
- dpctl 0.5.*
- dpctl >=0.5.1rc1
- spirv-tools
- llvm-spirv
- llvmdev
Expand Down
171 changes: 171 additions & 0 deletions numba_dppy/dppy_rt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#include "numba/_pymodule.h"
#include "numba/core/runtime/nrt_external.h"
#include "assert.h"
#include <stdio.h>
#if !defined _WIN32
#include <dlfcn.h>
#else
#include <windows.h>
#endif

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 neded.
int new_size = size + sizeof(void*);
// Get the current queue
void *cur_queue = get_queue_internal(); // this makes a copy
// Use that queue to allocate.
void *data = internal_allocator(new_size, cur_queue);
// 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.
internal_free(orig_data, obj_queue);
// Free the queue itself.
free_queue_internal(obj_queue);
}

void usmarray_memsys_init(void) {
#if !defined _WIN32
char *lib_name = "libDPCTLSyclInterface.so";
char *malloc_name = "DPCTLmalloc_shared";
char *free_name = "DPCTLfree_with_queue";
char *get_queue_name = "DPCTLQueueMgr_GetCurrentQueue";
char *free_queue_name = "DPCTLQueue_Delete";

void *sycldl = dlopen(lib_name, RTLD_NOW);
assert(sycldl != NULL);
internal_allocator = (NRT_external_malloc_func)dlsym(sycldl, malloc_name);
usmarray_allocator.malloc = save_queue_allocator;
if (internal_allocator == NULL) {
printf("Did not find %s in %s\n", malloc_name, lib_name);
exit(-1);
}

usmarray_allocator.realloc = NULL;

internal_free = (NRT_external_free_func)dlsym(sycldl, free_name);
usmarray_allocator.free = save_queue_deallocator;
if (internal_free == NULL) {
printf("Did not find %s in %s\n", free_name, lib_name);
exit(-1);
}

get_queue_internal = (void *(*)(void))dlsym(sycldl, get_queue_name);
if (get_queue_internal == NULL) {
printf("Did not find %s in %s\n", get_queue_name, lib_name);
exit(-1);
}
usmarray_allocator.opaque_data = NULL;

free_queue_internal = (void (*)(void*))dlsym(sycldl, free_queue_name);
if (free_queue_internal == NULL) {
printf("Did not find %s in %s\n", free_queue_name, lib_name);
exit(-1);
}
#else
char *lib_name = "DPCTLSyclInterface.dll";
char *malloc_name = "DPCTLmalloc_shared";
char *free_name = "DPCTLfree_with_queue";
char *get_queue_name = "DPCTLQueueMgr_GetCurrentQueue";
char *free_queue_name = "DPCTLQueue_Delete";

HMODULE sycldl = LoadLibrary(lib_name);
assert(sycldl != NULL);
internal_allocator = (NRT_external_malloc_func)GetProcAddress(sycldl, malloc_name);
usmarray_allocator.malloc = save_queue_allocator;
if (internal_allocator == NULL) {
printf("Did not find %s in %s\n", malloc_name, lib_name);
exit(-1);
}

usmarray_allocator.realloc = NULL;

internal_free = (NRT_external_free_func)GetProcAddress(sycldl, free_name);
usmarray_allocator.free = save_queue_deallocator;
if (internal_free == NULL) {
printf("Did not find %s in %s\n", free_name, lib_name);
exit(-1);
}

get_queue_internal = (void *(*)(void))GetProcAddress(sycldl, get_queue_name);
if (get_queue_internal == NULL) {
printf("Did not find %s in %s\n", get_queue_name, lib_name);
exit(-1);
}
usmarray_allocator.opaque_data = NULL;

free_queue_internal = (void (*)(void*))GetProcAddress(sycldl, free_queue_name);
if (free_queue_internal == NULL) {
printf("Did not find %s in %s\n", free_queue_name, lib_name);
exit(-1);
}
#endif
}

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());
}

static PyMethodDef ext_methods[] = {
#define declmethod_noargs(func) { #func , ( PyCFunction )func , METH_NOARGS, NULL }
declmethod_noargs(get_external_allocator),
{NULL},
#undef declmethod_noargs
};

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);

#undef _declpointer
return dct;
error:
Py_XDECREF(dct);
return NULL;
}

MOD_INIT(_dppy_rt) {
PyObject *m;
MOD_DEF(m, "numba_dppy._dppy_rt", "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);
}
Loading