From 6d434f6600c5ecf99c813fedfb57163ff79321ec Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 26 Nov 2020 06:46:07 -0600 Subject: [PATCH 1/8] fix warning #50 --- backends/source/dppl_sycl_context_interface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backends/source/dppl_sycl_context_interface.cpp b/backends/source/dppl_sycl_context_interface.cpp index 78c71f5ad0..5f5b4ff54a 100644 --- a/backends/source/dppl_sycl_context_interface.cpp +++ b/backends/source/dppl_sycl_context_interface.cpp @@ -47,7 +47,11 @@ bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef) { - return unwrap(CtxRef)->is_host(); + auto Ctx = unwrap(CtxRef) + if (Ctx) { + return Ctx->is_host(); + } + return false; } void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef) From 1d3e887983cdc3af5316af4b06f4a4831aa4ca12 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 30 Nov 2020 04:47:26 -0600 Subject: [PATCH 2/8] fix warnings #42 and #50 --- backends/source/dppl_sycl_context_interface.cpp | 2 +- backends/source/dppl_sycl_platform_interface.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backends/source/dppl_sycl_context_interface.cpp b/backends/source/dppl_sycl_context_interface.cpp index 5f5b4ff54a..c160d72065 100644 --- a/backends/source/dppl_sycl_context_interface.cpp +++ b/backends/source/dppl_sycl_context_interface.cpp @@ -47,7 +47,7 @@ bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef) { - auto Ctx = unwrap(CtxRef) + auto Ctx = unwrap(CtxRef); if (Ctx) { return Ctx->is_host(); } diff --git a/backends/source/dppl_sycl_platform_interface.cpp b/backends/source/dppl_sycl_platform_interface.cpp index 89b1377fa8..2e68c56823 100644 --- a/backends/source/dppl_sycl_platform_interface.cpp +++ b/backends/source/dppl_sycl_platform_interface.cpp @@ -148,7 +148,12 @@ size_t DPPLPlatform_GetNumNonHostPlatforms () size_t DPPLPlatform_GetNumNonHostBackends () { - return get_set_of_non_hostbackends().size(); + auto be_set = get_set_of_non_hostbackends(); + + if (be_set.empty()) + return 0; + + return be_set.size(); } __dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends () From 3d2dbd6e367df122938f9a510b85908943353a82 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Dec 2020 17:26:35 -0600 Subject: [PATCH 3/8] Examples added (#197) * Added Cython examples 1. Cython/sycl_direct_linkage Example of native extension "cdef import"-ing sycl C++ classes directly from CL/sycl.hpp Queue is created within the function, adding measurable overhead. Extension uses GEMV to compute column-wise total of a C-contiguous matrix, and illustrates linking to oneMKL. 2. Cython/sycl_bufer Example of native extension building on the above, but illustrating getting the queue from dpctl. 3. Cython/usm_memory Example of native extension allocating USM shared memory via dpctl, and using it as a buffer underlying NumPy array. Cython functions dispatches to a SYCL code that works with USM pointer. One function populates USM memory underneath NumPy array with random numbers using ``oneapi::mkl::rng::device`` function used in SYCL kernel, with random number being parameters of European vanilla options. The second function uses SYCL to price these options using Black-Scholes formula. * updated create_sycl_queues.py to run on current dpctl * Extended sycl_buffer example to implement column-wise summation without MKL * few examples illustrating MemoryUSM* objects * have it black's way * Adjusted examples section of global README.md --- README.md | 10 +- examples/cython/sycl_buffer/README.md | 80 +++++++++ .../cython/sycl_buffer/_buffer_example.pyx | 28 +++ examples/cython/sycl_buffer/bench.py | 51 ++++++ examples/cython/sycl_buffer/run.py | 22 +++ examples/cython/sycl_buffer/setup.py | 67 +++++++ .../cython/sycl_buffer/use_sycl_buffer.cpp | 109 +++++++++++ examples/cython/sycl_buffer/use_sycl_buffer.h | 7 + .../sycl_direct_linkage/_buffer_example.pyx | 25 +++ examples/cython/sycl_direct_linkage/run.py | 10 ++ examples/cython/sycl_direct_linkage/setup.py | 67 +++++++ .../sycl_direct_linkage/sycl_function.cpp | 51 ++++++ .../sycl_direct_linkage/sycl_function.hpp | 3 + examples/cython/usm_memory/README.md | 28 +++ examples/cython/usm_memory/blackscholes.pyx | 76 ++++++++ .../usm_memory/reference_black_scholes.py | 39 ++++ examples/cython/usm_memory/run.py | 76 ++++++++ examples/cython/usm_memory/setup.py | 67 +++++++ .../cython/usm_memory/sycl_blackscholes.cpp | 170 ++++++++++++++++++ .../cython/usm_memory/sycl_blackscholes.hpp | 10 ++ examples/{ => python}/create_sycl_queues.py | 13 +- examples/python/usm_memory_allocation.py | 22 +++ examples/python/usm_memory_host_access.py | 38 ++++ examples/python/usm_memory_operation.py | 30 ++++ 24 files changed, 1091 insertions(+), 8 deletions(-) create mode 100644 examples/cython/sycl_buffer/README.md create mode 100644 examples/cython/sycl_buffer/_buffer_example.pyx create mode 100644 examples/cython/sycl_buffer/bench.py create mode 100644 examples/cython/sycl_buffer/run.py create mode 100644 examples/cython/sycl_buffer/setup.py create mode 100644 examples/cython/sycl_buffer/use_sycl_buffer.cpp create mode 100644 examples/cython/sycl_buffer/use_sycl_buffer.h create mode 100644 examples/cython/sycl_direct_linkage/_buffer_example.pyx create mode 100644 examples/cython/sycl_direct_linkage/run.py create mode 100644 examples/cython/sycl_direct_linkage/setup.py create mode 100644 examples/cython/sycl_direct_linkage/sycl_function.cpp create mode 100644 examples/cython/sycl_direct_linkage/sycl_function.hpp create mode 100644 examples/cython/usm_memory/README.md create mode 100644 examples/cython/usm_memory/blackscholes.pyx create mode 100644 examples/cython/usm_memory/reference_black_scholes.py create mode 100644 examples/cython/usm_memory/run.py create mode 100644 examples/cython/usm_memory/setup.py create mode 100644 examples/cython/usm_memory/sycl_blackscholes.cpp create mode 100644 examples/cython/usm_memory/sycl_blackscholes.hpp rename examples/{ => python}/create_sycl_queues.py (80%) create mode 100644 examples/python/usm_memory_allocation.py create mode 100644 examples/python/usm_memory_host_access.py create mode 100644 examples/python/usm_memory_operation.py diff --git a/README.md b/README.md index 4a09b2b7bc..e8ef93908b 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,17 @@ Examples ======== See examples in folder `examples`. -Run examples: +Run python examples: ```bash -python examples/create_sycl_queues.py +for script in `ls examples/python/`; do echo "executing ${script}"; python examples/python/${script}; done ``` +Examples of building Cython extensions with DPC++ compiler, that interoperate with dpCtl can be found in +folder `cython`. + +Each example in `cython` folder can be built using `CC=clang CXX=dpcpp python setup.py build_ext --inplace`. +Please refer to `run.py` script in respective folders to execute extensions. + Tests ===== See tests in folder `dpctl/tests`. diff --git a/examples/cython/sycl_buffer/README.md b/examples/cython/sycl_buffer/README.md new file mode 100644 index 0000000000..47e682d8cb --- /dev/null +++ b/examples/cython/sycl_buffer/README.md @@ -0,0 +1,80 @@ +#1 Example of SYCL extension working NumPy array input via SYCL buffers + + +#2 Decription + +Cython function expecting a 2D array in C-contiguous layout that +computes column-wise total by using SYCL oneMKL (as GEMV call with +an all units vector). + +Example illustrates compiling SYCL extension, linking to oneMKL. + + +#2 Compiling + +``` +# make sure oneAPI is activated, $ONEAPI_ROOT must be set +CC=clang CXX=dpcpp python setup.py build_ext --inplace +``` + + +#2 Running + +``` +# SYCL_BE=PI_OPENCL sets SYCL backend to OpenCL to avoid a +# transient issue with MKL's using the default Level-0 backend +(idp) [08:16:12 ansatnuc04 simple]$ SYCL_BE=PI_OPENCL ipython +Python 3.7.7 (default, Jul 14 2020, 22:02:37) +Type 'copyright', 'credits' or 'license' for more information +IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help. + +In [1]: import syclbuffer as sb, numpy as np, dpctl + +In [2]: x = np.random.randn(10**4, 2500) + +In [3]: %time m1 = np.sum(x, axis=0) +CPU times: user 22.3 ms, sys: 160 µs, total: 22.5 ms +Wall time: 21.2 ms + +In [4]: %time m = sb.columnwise_total(x) # first time is slower, due to JIT overhead +CPU times: user 207 ms, sys: 36.1 ms, total: 243 ms +Wall time: 248 ms + +In [5]: %time m = sb.columnwise_total(x) +CPU times: user 8.89 ms, sys: 4.12 ms, total: 13 ms +Wall time: 12.4 ms + +In [6]: %time m = sb.columnwise_total(x) +CPU times: user 4.82 ms, sys: 8.06 ms, total: 12.9 ms +Wall time: 12.3 ms +``` + +Running bench.py: + +``` +========== Executing warm-up ========== +NumPy result: [1. 1. 1. ... 1. 1. 1.] +SYCL(Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz) result: [1. 1. 1. ... 1. 1. 1.] +SYCL(Intel(R) Gen9 HD Graphics NEO) result: [1. 1. 1. ... 1. 1. 1.] +Times for 'opencl:cpu:0' +[2.864787499012891, 2.690436460019555, 2.5902308400254697, 2.5802528870408423, 2.538990616973024] +Times for 'opencl:gpu:0' +[1.9769684099592268, 2.3491444009705447, 2.293720397981815, 2.391633405990433, 1.9465659779962152] +Times for NumPy +[3.4011058019823395, 3.07286038500024, 3.0390414349967614, 3.0305576199898496, 3.002687797998078] +``` + +Running run.py: + +``` +(idp) [09:14:53 ansatnuc04 sycl_buffer]$ SYCL_BE=PI_OPENCL python run.py +Result computed by NumPy +[ 0.27170187 -23.36798583 7.31326489 -1.95121928] +Result computed by SYCL extension +[ 0.27170187 -23.36798583 7.31326489 -1.95121928] + +Running on: Intel(R) Gen9 HD Graphics NEO +[ 0.27170187 -23.36798583 7.31326489 -1.95121928] +Running on: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz +[ 0.27170187 -23.36798583 7.31326489 -1.95121928] +``` \ No newline at end of file diff --git a/examples/cython/sycl_buffer/_buffer_example.pyx b/examples/cython/sycl_buffer/_buffer_example.pyx new file mode 100644 index 0000000000..d1ade59c92 --- /dev/null +++ b/examples/cython/sycl_buffer/_buffer_example.pyx @@ -0,0 +1,28 @@ +cimport numpy as cnp +import numpy as np + +cimport dpctl as c_dpctl +import dpctl + +cdef extern from "use_sycl_buffer.h": + int c_columnwise_total(c_dpctl.DPPLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil + int c_columnwise_total_no_mkl(c_dpctl.DPPLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil + +def columnwise_total(double[:, ::1] v, method='mkl'): + cdef cnp.ndarray res_array = np.empty((v.shape[1],), dtype='d') + cdef double[::1] res_memslice = res_array + cdef int ret_status + cdef c_dpctl.SyclQueue q + cdef c_dpctl.DPPLSyclQueueRef q_ref + + q = c_dpctl.get_current_queue() + q_ref = q.get_queue_ref() + + if method == 'mkl': + with nogil: + ret_status = c_columnwise_total(q_ref, v.shape[0], v.shape[1], &v[0,0], &res_memslice[0]) + else: + with nogil: + ret_status = c_columnwise_total_no_mkl(q_ref, v.shape[0], v.shape[1], &v[0,0], &res_memslice[0]) + + return res_array diff --git a/examples/cython/sycl_buffer/bench.py b/examples/cython/sycl_buffer/bench.py new file mode 100644 index 0000000000..0c6d94d189 --- /dev/null +++ b/examples/cython/sycl_buffer/bench.py @@ -0,0 +1,51 @@ +import dpctl +import syclbuffer as sb +import numpy as np + +X = np.full((10 ** 4, 4098), 1e-4, dtype="d") + +# warm-up +print("=" * 10 + " Executing warm-up " + "=" * 10) +print("NumPy result: ", X.sum(axis=0)) + +dpctl.set_default_queue("opencl", "cpu", 0) +print( + "SYCL({}) result: {}".format( + dpctl.get_current_queue().get_sycl_device().get_device_name(), + sb.columnwise_total(X), + ) +) + +dpctl.set_default_queue("opencl", "gpu", 0) +print( + "SYCL({}) result: {}".format( + dpctl.get_current_queue().get_sycl_device().get_device_name(), + sb.columnwise_total(X), + ) +) + +import timeit + +print("Times for 'opencl:cpu:0'") +print( + timeit.repeat( + stmt="sb.columnwise_total(X)", + setup='dpctl.set_default_queue("opencl", "cpu", 0); ' + "sb.columnwise_total(X)", # ensure JIT compilation is not counted + number=100, + globals=globals(), + ) +) + +print("Times for 'opencl:gpu:0'") +print( + timeit.repeat( + stmt="sb.columnwise_total(X)", + setup='dpctl.set_default_queue("opencl", "gpu", 0); sb.columnwise_total(X)', + number=100, + globals=globals(), + ) +) + +print("Times for NumPy") +print(timeit.repeat(stmt="X.sum(axis=0)", number=100, globals=globals())) diff --git a/examples/cython/sycl_buffer/run.py b/examples/cython/sycl_buffer/run.py new file mode 100644 index 0000000000..4e279a84e2 --- /dev/null +++ b/examples/cython/sycl_buffer/run.py @@ -0,0 +1,22 @@ +import syclbuffer as sb +import numpy as np + +X = np.random.randn(100, 4) + +print("Result computed by NumPy") +print(X.sum(axis=0)) +print("Result computed by SYCL extension") +print(sb.columnwise_total(X)) + + +print("") +# controlling where to offload +import dpctl + +with dpctl.device_context("opencl:gpu"): + print("Running on: ", dpctl.get_current_queue().get_sycl_device().get_device_name()) + print(sb.columnwise_total(X)) + +with dpctl.device_context("opencl:cpu"): + print("Running on: ", dpctl.get_current_queue().get_sycl_device().get_device_name()) + print(sb.columnwise_total(X)) diff --git a/examples/cython/sycl_buffer/setup.py b/examples/cython/sycl_buffer/setup.py new file mode 100644 index 0000000000..ef9b6f3b78 --- /dev/null +++ b/examples/cython/sycl_buffer/setup.py @@ -0,0 +1,67 @@ +import sys +from os.path import join, exists, abspath, dirname +from os import getcwd +from os import environ +from Cython.Build import cythonize + + +def configuration(parent_package="", top_path=None): + from numpy.distutils.misc_util import Configuration + from numpy.distutils.system_info import get_info + import numpy as np + import dpctl + + config = Configuration("", parent_package, top_path) + + oneapi_root = environ.get("ONEAPI_ROOT", None) + if not oneapi_root: + raise ValueError("ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi") + + mkl_info = { + "include_dirs": [join(oneapi_root, "mkl", "include")], + "library_dirs": [ + join(oneapi_root, "mkl", "lib"), + join(oneapi_root, "mkl", "lib", "intel64"), + ], + "libraries": [ + "mkl_sycl", + "mkl_intel_ilp64", + "mkl_tbb_thread", + "mkl_core", + "tbb", + "iomp5", + ], + } + + mkl_include_dirs = mkl_info.get("include_dirs") + mkl_library_dirs = mkl_info.get("library_dirs") + mkl_libraries = mkl_info.get("libraries") + + pdir = dirname(__file__) + wdir = join(pdir) + + eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"] + + config.add_extension( + name="syclbuffer", + sources=[ + join(pdir, "_buffer_example.pyx"), + join(wdir, "use_sycl_buffer.cpp"), + join(wdir, "use_sycl_buffer.h"), + ], + include_dirs=[wdir, np.get_include(), dpctl.get_include()] + mkl_include_dirs, + libraries=["sycl"] + mkl_libraries, + runtime_library_dirs=mkl_library_dirs, + extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'], + extra_link_args=["-fPIC"], + language="c++", + ) + + config.ext_modules = cythonize(config.ext_modules, include_path=[pdir, wdir]) + return config + + +if __name__ == "__main__": + from numpy.distutils.core import setup + + setup(configuration=configuration) diff --git a/examples/cython/sycl_buffer/use_sycl_buffer.cpp b/examples/cython/sycl_buffer/use_sycl_buffer.cpp new file mode 100644 index 0000000000..0c42332ea7 --- /dev/null +++ b/examples/cython/sycl_buffer/use_sycl_buffer.cpp @@ -0,0 +1,109 @@ +#include +#include "use_sycl_buffer.h" +#include +#include "dppl_sycl_types.h" + +int +c_columnwise_total(DPPLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { + + sycl::queue q = *(reinterpret_cast(q_ref)); + + sycl::buffer mat_buffer = sycl::buffer(mat, sycl::range<1>(n * m)); + sycl::buffer ct_buffer = sycl::buffer(ct, sycl::range<1>(m)); + + double *ones = reinterpret_cast(malloc(n * sizeof(double))); + { + sycl::buffer ones_buffer = sycl::buffer(ones, sycl::range<1>(n)); + + try { + auto ev = q.submit([&](sycl::handler &cgh) { + auto ones_acc = ones_buffer.get_access(cgh); + cgh.fill(ones_acc, double(1.0)); + }); + + ev.wait_and_throw(); + } + catch (sycl::exception const& e) { + std::cout << "\t\tCaught synchronous SYCL exception during fill:\n" + << e.what() << std::endl << "OpenCL status: " << e.get_cl_code() << std::endl; + goto cleanup; + } + + try { + oneapi::mkl::blas::row_major::gemv( + q, + oneapi::mkl::transpose::trans, + n, m, double(1.0), mat_buffer, m, + ones_buffer, 1, + double(0.0), ct_buffer, 1); + q.wait(); + } + catch (sycl::exception const &e) { + std::cout << "\t\tCaught synchronous SYCL exception during GEMV:\n" + << e.what() << std::endl << "OpenCL status: " << e.get_cl_code() << std::endl; + goto cleanup; + } + } + + free(ones); + return 0; + + cleanup: + free(ones); + return -1; +} + +inline size_t upper_multiple(size_t n, size_t wg) { return wg * ((n + wg - 1)/wg); } + +int +c_columnwise_total_no_mkl(DPPLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { + + sycl::queue q = *(reinterpret_cast(q_ref)); + + sycl::buffer mat_buffer = sycl::buffer(mat, sycl::range<2>(n, m)); + sycl::buffer ct_buffer = sycl::buffer(ct, sycl::range<1>(m)); + + auto e = q.submit( + [&](sycl::handler &h) { + sycl::accessor ct_acc {ct_buffer, h, sycl::write_only}; + h.parallel_for( + sycl::range<1>(m), + [=](sycl::id<1> i){ + ct_acc[i] = 0.0; + }); + }); + + constexpr size_t wg = 256; + auto e2 = q.submit( + [&](sycl::handler &h) { + + sycl::accessor mat_acc {mat_buffer, h, sycl::read_only}; + sycl::accessor ct_acc {ct_buffer, h}; + h.depends_on(e); + + sycl::range<2> global {upper_multiple(n, wg), m}; + sycl::range<2> local {wg, 1}; + + h.parallel_for( + sycl::nd_range<2>(global, local), + [=](sycl::nd_item<2> it) { + size_t i = it.get_global_id(0); + size_t j = it.get_global_id(1); + double group_sum = sycl::ONEAPI::reduce( + it.get_group(), + (i < n) ? mat_acc[it.get_global_id()] : 0.0, + std::plus() + ); + if (it.get_local_id(0) == 0) { + sycl::ONEAPI::atomic_ref< + double, + sycl::ONEAPI::memory_order::relaxed, + sycl::ONEAPI::memory_scope::system, + sycl::access::address_space::global_space>(ct_acc[j]) += group_sum; + } + }); + }); + + e2.wait_and_throw(); + return 0; +} diff --git a/examples/cython/sycl_buffer/use_sycl_buffer.h b/examples/cython/sycl_buffer/use_sycl_buffer.h new file mode 100644 index 0000000000..f3ee924861 --- /dev/null +++ b/examples/cython/sycl_buffer/use_sycl_buffer.h @@ -0,0 +1,7 @@ +#include +#include "dppl_sycl_types.h" + +extern int c_columnwise_total( + DPPLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); +extern int c_columnwise_total_no_mkl( + DPPLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); diff --git a/examples/cython/sycl_direct_linkage/_buffer_example.pyx b/examples/cython/sycl_direct_linkage/_buffer_example.pyx new file mode 100644 index 0000000000..e9aca0fcfe --- /dev/null +++ b/examples/cython/sycl_direct_linkage/_buffer_example.pyx @@ -0,0 +1,25 @@ +cimport numpy as cnp +import numpy as np +from cython.operator cimport dereference as deref + +cdef extern from "CL/sycl.hpp" namespace "cl::sycl": + cdef cppclass queue nogil: + pass + +cdef extern from "sycl_function.hpp": + int c_columnwise_total(queue& q, size_t n, size_t m, double *m, double *ct) nogil + +def columnwise_total(double[:, ::1] v): + cdef cnp.ndarray res_array = np.empty((v.shape[1],), dtype='d') + cdef double[::1] res_memslice = res_array + cdef int ret_status + cdef queue* q + + q = new queue() + + with nogil: + ret_status = c_columnwise_total(deref(q), v.shape[0], v.shape[1], &v[0,0], &res_memslice[0]) + + del q + + return res_array diff --git a/examples/cython/sycl_direct_linkage/run.py b/examples/cython/sycl_direct_linkage/run.py new file mode 100644 index 0000000000..ed9597add1 --- /dev/null +++ b/examples/cython/sycl_direct_linkage/run.py @@ -0,0 +1,10 @@ +import syclbuffer as sb +import numpy as np + +X = np.random.randn(20, 10) + +# compute column-wise total with NumPy's own host code +print(X.sum(axis=0)) + +# compute column-wise total with SYCL extension +print(sb.columnwise_total(X)) diff --git a/examples/cython/sycl_direct_linkage/setup.py b/examples/cython/sycl_direct_linkage/setup.py new file mode 100644 index 0000000000..495838b1fd --- /dev/null +++ b/examples/cython/sycl_direct_linkage/setup.py @@ -0,0 +1,67 @@ +import sys +from os.path import join, exists, abspath, dirname +from os import getcwd +from os import environ +from Cython.Build import cythonize + + +def configuration(parent_package="", top_path=None): + from numpy.distutils.misc_util import Configuration + from numpy.distutils.system_info import get_info + import numpy as np + import dpctl + + config = Configuration("", parent_package, top_path) + + oneapi_root = environ.get("ONEAPI_ROOT", None) + if not oneapi_root: + raise ValueError("ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi") + + mkl_info = { + "include_dirs": [join(oneapi_root, "mkl", "include")], + "library_dirs": [ + join(oneapi_root, "mkl", "lib"), + join(oneapi_root, "mkl", "lib", "intel64"), + ], + "libraries": [ + "mkl_sycl", + "mkl_intel_ilp64", + "mkl_tbb_thread", + "mkl_core", + "tbb", + "iomp5", + ], + } + + mkl_include_dirs = mkl_info.get("include_dirs") + mkl_library_dirs = mkl_info.get("library_dirs") + mkl_libraries = mkl_info.get("libraries") + + pdir = dirname(__file__) + wdir = join(pdir) + + eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"] + + config.add_extension( + name="syclbuffer_naive", + sources=[ + join(pdir, "_buffer_example.pyx"), + join(pdir, "sycl_function.cpp"), + join(pdir, "sycl_function.hpp"), + ], + include_dirs=[wdir, np.get_include(), dpctl.get_include()] + mkl_include_dirs, + libraries=["sycl"] + mkl_libraries, + runtime_library_dirs=mkl_library_dirs, + extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'], + extra_link_args=["-fPIC"], + language="c++", + ) + + config.ext_modules = cythonize(config.ext_modules, include_path=[pdir, wdir]) + return config + + +if __name__ == "__main__": + from numpy.distutils.core import setup + + setup(configuration=configuration) diff --git a/examples/cython/sycl_direct_linkage/sycl_function.cpp b/examples/cython/sycl_direct_linkage/sycl_function.cpp new file mode 100644 index 0000000000..d9d8065f3e --- /dev/null +++ b/examples/cython/sycl_direct_linkage/sycl_function.cpp @@ -0,0 +1,51 @@ +#include +#include "sycl_function.hpp" +#include "mkl_blas_sycl.hpp" +#include "mkl.h" + +int c_columnwise_total(cl::sycl::queue &q, size_t n, size_t m, double *mat, double *ct) { + sycl::buffer mat_buffer = sycl::buffer(mat, sycl::range<1>(n * m)); + sycl::buffer ct_buffer = sycl::buffer(ct, sycl::range<1>(m)); + + double *ones = reinterpret_cast(malloc(n * sizeof(double))); + { + sycl::buffer ones_buffer = sycl::buffer(ones, sycl::range<1>(n)); + + try { + auto ev = q.submit([&](sycl::handler &cgh) { + auto ones_acc = ones_buffer.get_access(cgh); + cgh.fill(ones_acc, double(1.0)); + }); + + ev.wait_and_throw(); + } + catch (sycl::exception const& e) { + std::cout << "\t\tCaught synchronous SYCL exception during fill:\n" + << e.what() << std::endl << "OpenCL status: " << e.get_cl_code() << std::endl; + goto cleanup; + } + + try { + oneapi::mkl::blas::row_major::gemv( + q, + oneapi::mkl::transpose::trans, + n, m, double(1.0), mat_buffer, m, + ones_buffer, 1, + double(0.0), ct_buffer, 1); + q.wait(); + } + catch (sycl::exception const &e) { + std::cout << "\t\tCaught synchronous SYCL exception during GEMV:\n" + << e.what() << std::endl << "OpenCL status: " << e.get_cl_code() << std::endl; + goto cleanup; + } + } + + free(ones); + return 0; + + cleanup: + free(ones); + return -1; +} + diff --git a/examples/cython/sycl_direct_linkage/sycl_function.hpp b/examples/cython/sycl_direct_linkage/sycl_function.hpp new file mode 100644 index 0000000000..51e5e8474b --- /dev/null +++ b/examples/cython/sycl_direct_linkage/sycl_function.hpp @@ -0,0 +1,3 @@ +#include + +int c_columnwise_total(cl::sycl::queue&, size_t n, size_t m, double *mat, double *ct); diff --git a/examples/cython/usm_memory/README.md b/examples/cython/usm_memory/README.md new file mode 100644 index 0000000000..be3a7c6ce4 --- /dev/null +++ b/examples/cython/usm_memory/README.md @@ -0,0 +1,28 @@ +#1 Example of working with USM memory + +#2 Description + +#2 Building + +Make sure oneAPI is activated. Environment variable `$ONEAPI_ROOT` must be set. + + +``` +$ CC=clang CXX=dpcpp LD_SHARED="dpcpp -shared" python setup.py build_ext --inplace +``` + +#2 Running + +``` +$ python run.py +``` + +which gives sample output: + +``` +True +Using : Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz +Elapsed: 0.9255791641771793 +Using : Intel(R) Gen9 +Elapsed: 0.32811625860631466 +``` \ No newline at end of file diff --git a/examples/cython/usm_memory/blackscholes.pyx b/examples/cython/usm_memory/blackscholes.pyx new file mode 100644 index 0000000000..6495265461 --- /dev/null +++ b/examples/cython/usm_memory/blackscholes.pyx @@ -0,0 +1,76 @@ +# cython: language_level=3 +# distutils: language=c++ + +cimport dpctl as c_dpctl +cimport dpctl._memory as c_dpctl_mem +cimport numpy as cnp +from cython cimport floating + +import dpctl +import numpy as np + +cdef extern from "sycl_blackscholes.hpp": + cdef void cpp_blackscholes[T](c_dpctl.DPPLSyclQueueRef, size_t n_opts, T* option_params, T* callput) + cdef void cpp_populate_params[T](c_dpctl.DPPLSyclQueueRef, size_t n_opts, T* option_params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) + +def black_scholes_price(floating[:, ::1] option_params): + cdef size_t n_opts = option_params.shape[0] + cdef size_t n_params = option_params.shape[1] + cdef c_dpctl.SyclQueue q + cdef c_dpctl.DPPLSyclQueueRef q_ptr + cdef c_dpctl_mem.MemoryUSMShared mobj + cdef floating[:, :] call_put_prices + cdef cnp.ndarray callput_arr + cdef double* dp1 + cdef double* dp2 + cdef float* fp1 + cdef float* fp2 + + if (n_params != 5): + raise ValueError(( + "Array of option parameters has unexpected number of columns {} != 5. " + "Each row must specify (current_price, strike_price, maturity, interest_rate, volatility)." + ).format(n_params)) + + q = c_dpctl.get_current_queue() + q_ptr = q.get_queue_ref() + if (floating is double): + mobj = c_dpctl_mem.MemoryUSMShared(nbytes=2*n_opts * sizeof(double)) + callput_arr = np.ndarray((n_opts, 2), buffer=mobj, dtype='d') + call_put_prices = callput_arr + dp1 = &option_params[0,0] + dp2 = &call_put_prices[0,0]; + cpp_blackscholes[double](q_ptr, n_opts, dp1, dp2) + elif (floating is float): + mobj = c_dpctl_mem.MemoryUSMShared(nbytes=2*n_opts * sizeof(float)) + callput_arr = np.ndarray((n_opts, 2), buffer=mobj, dtype='f') + call_put_prices = callput_arr + fp1 = &option_params[0,0] + fp2 = &call_put_prices[0,0] + cpp_blackscholes[float](q_ptr, n_opts, fp1, fp2) + + return callput_arr + +def populate_params(floating[:, ::1] option_params, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, int seed): + cdef size_t n_opts = option_params.shape[0] + cdef size_t n_params = option_params.shape[1] + + cdef c_dpctl.SyclQueue q + cdef c_dpctl.DPPLSyclQueueRef q_ptr + cdef double* dp + cdef float* fp + + if (n_params != 5): + raise ValueError(( + "Array of option parameters has unexpected number of columns {} != 5. " + "Each row must specify (current_price, strike_price, maturity, interest_rate, volatility)." + ).format(n_params)) + + q = c_dpctl.get_current_queue() + q_ptr = q.get_queue_ref() + if (floating is double): + dp = &option_params[0,0] + cpp_populate_params[double](q_ptr, n_opts, dp, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed) + elif (floating is float): + fp = &option_params[0,0] + cpp_populate_params[float](q_ptr, n_opts, fp, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed) diff --git a/examples/cython/usm_memory/reference_black_scholes.py b/examples/cython/usm_memory/reference_black_scholes.py new file mode 100644 index 0000000000..ae01312932 --- /dev/null +++ b/examples/cython/usm_memory/reference_black_scholes.py @@ -0,0 +1,39 @@ +import math + + +def ref_python_black_scholes(price, strike, t, rate, vol): + mr = -rate + sig_sig_two = vol * vol * 2 + + P = price + S = strike + T = t + + a = math.log(P / S) + b = T * mr + + z = T * sig_sig_two + c = 0.25 * z + y = 1 / math.sqrt(z) + + Se = math.exp(b) * S + + w1 = (a - b + c) * y + w2 = (a - b - c) * y + + if w1 > 0: + d1 = 0.5 * math.erfc(-w1) + d1c = 1.0 - d1 + else: + d1c = 0.5 * math.erfc(w1) + d1 = 1.0 - d1c + if w2 > 0: + d2 = 0.5 * math.erfc(-w2) + d2c = 1.0 - d2 + else: + d2c = 0.5 * math.erfc(w2) + d2 = 1.0 - d2c + + call = P * d1 - Se * d2 + put = Se * d2c - P * d1c + return (call, put) diff --git a/examples/cython/usm_memory/run.py b/examples/cython/usm_memory/run.py new file mode 100644 index 0000000000..422c4baaf1 --- /dev/null +++ b/examples/cython/usm_memory/run.py @@ -0,0 +1,76 @@ +# coding: utf-8 +import dpctl._memory as dpctl_mem +import blackscholes_usm as bs +import numpy as np, dpctl +from reference_black_scholes import ref_python_black_scholes + + +def gen_option_params(n_opts, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, dtype): + usm_mem = dpctl_mem.MemoryUSMShared(n_opts * 5 * np.dtype(dtype).itemsize) + # usm_mem2 = dpctl_mem.MemoryUSMDevice(n_opts * 5 * np.dtype(dtype).itemsize) + params = np.ndarray(shape=(n_opts, 5), buffer=usm_mem, dtype=dtype) + seed = 1234 + bs.populate_params(params, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed) + return params + + +# ==== dry run === +usm_mem = dpctl_mem.MemoryUSMShared(3 * 5 * np.dtype("d").itemsize) +opts = np.ndarray((3, 5), buffer=usm_mem, dtype="d") +# copy from Host NumPy to USM buffer +opts[:, :] = np.array( + [ + [81.2, 81.8, 29, 0.01, 0.02], + [24.24, 22.1, 10, 0.02, 0.08], + [100, 100, 30, 0.01, 0.12], + ] +) +# GPU computation +Xgpu = bs.black_scholes_price(opts) + +# compute prices in CPython +X_ref = np.array([ref_python_black_scholes(*opt) for opt in opts], dtype="d") + +print(np.allclose(Xgpu, X_ref, atol=1e-5)) + +n_opts = 3 * 10 ** 6 + +# compute on CPU sycl device +import timeit + +for _ in range(3): + + dpctl.set_default_queue("opencl", "cpu", 0) + print( + "Using : {}".format( + dpctl.get_current_queue().get_sycl_device().get_device_name() + ) + ) + + t0 = timeit.default_timer() + opts1 = gen_option_params( + n_opts, 20.0, 30.0, 22.0, 29.0, 18.0, 24.0, 0.01, 0.05, 0.01, 0.05, "d" + ) + X1 = bs.black_scholes_price(opts1) + t1 = timeit.default_timer() + + print("Elapsed: {}".format(t1 - t0)) + + # compute on GPU sycl device + dpctl.set_default_queue("level0", "gpu", 0) + print( + "Using : {}".format( + dpctl.get_current_queue().get_sycl_device().get_device_name() + ) + ) + + t0 = timeit.default_timer() + opts2 = gen_option_params( + n_opts, 20.0, 30.0, 22.0, 29.0, 18.0, 24.0, 0.01, 0.05, 0.01, 0.05, "d" + ) + X2 = bs.black_scholes_price(opts2) + t1 = timeit.default_timer() + print("Elapsed: {}".format(t1 - t0)) + +print(np.abs(opts1 - opts2).max()) +print(np.abs(X2 - X1).max()) diff --git a/examples/cython/usm_memory/setup.py b/examples/cython/usm_memory/setup.py new file mode 100644 index 0000000000..4f3fced830 --- /dev/null +++ b/examples/cython/usm_memory/setup.py @@ -0,0 +1,67 @@ +import sys +from os.path import join, exists, abspath, dirname +from os import getcwd +from os import environ +from Cython.Build import cythonize + + +def configuration(parent_package="", top_path=None): + from numpy.distutils.misc_util import Configuration + from numpy.distutils.system_info import get_info + import numpy as np + import dpctl + + config = Configuration("", parent_package, top_path) + + oneapi_root = environ.get("ONEAPI_ROOT", None) + if not oneapi_root: + raise ValueError("ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi") + + mkl_info = { + "include_dirs": [join(oneapi_root, "mkl", "include")], + "library_dirs": [ + join(oneapi_root, "mkl", "lib"), + join(oneapi_root, "mkl", "lib", "intel64"), + ], + "libraries": [ + "mkl_sycl", + "mkl_intel_ilp64", + "mkl_tbb_thread", + "mkl_core", + "tbb", + "iomp5", + ], + } + + mkl_include_dirs = mkl_info.get("include_dirs") + mkl_library_dirs = mkl_info.get("library_dirs") + mkl_libraries = mkl_info.get("libraries") + + pdir = dirname(__file__) + wdir = join(pdir) + + eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"] + + config.add_extension( + name="blackscholes_usm", + sources=[ + join(pdir, "blackscholes.pyx"), + join(wdir, "sycl_blackscholes.cpp"), + join(wdir, "sycl_blackscholes.hpp"), + ], + include_dirs=[wdir, np.get_include(), dpctl.get_include()] + mkl_include_dirs, + libraries=["sycl"] + mkl_libraries, + runtime_library_dirs=mkl_library_dirs, + extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'], + extra_link_args=["-fPIC"], + language="c++", + ) + + config.ext_modules = cythonize(config.ext_modules, include_path=[pdir, wdir]) + return config + + +if __name__ == "__main__": + from numpy.distutils.core import setup + + setup(configuration=configuration) diff --git a/examples/cython/usm_memory/sycl_blackscholes.cpp b/examples/cython/usm_memory/sycl_blackscholes.cpp new file mode 100644 index 0000000000..550a01c622 --- /dev/null +++ b/examples/cython/usm_memory/sycl_blackscholes.cpp @@ -0,0 +1,170 @@ +#include +#include "dppl_sycl_types.h" +#include "sycl_blackscholes.hpp" +#include "mkl_rng_sycl_device.hpp" + +template +class black_scholes_kernel; + +constexpr int n_params = 5; +constexpr int n_params_next_pow2 = 8; + +constexpr int n_prices = 2; +constexpr int PRICE = 0; +constexpr int STRIKE = 1; +constexpr int MATURITY = 2; +constexpr int RATE = 3; +constexpr int VOLATILITY = 4; +constexpr int CALL = 0; +constexpr int PUT = 1; + +template +extern void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T* callput) { + using data_t = T; + + sycl::queue q = *(reinterpret_cast(q_ptr)); + + auto ctx = q.get_context(); + { + sycl::usm::alloc params_type = sycl::get_pointer_type(params, ctx); + if (params_type != sycl::usm::alloc::shared) { + throw std::runtime_error("Input option_params to cpp_blackscholes is not a USM-shared pointer."); + } + } + { + sycl::usm::alloc callput_type = sycl::get_pointer_type(callput, ctx); + if (callput_type != sycl::usm::alloc::shared) { + throw std::runtime_error("Input callput to cpp_blackscholes is not a USM-shared pointer."); + } + } + + auto e = q.submit( + [&](sycl::handler &cgh){ + + data_t zero = data_t(0), one = data_t(1), two = data_t(2); + data_t quarter = one / data_t(4); + data_t half = one / two; + + cgh.parallel_for>( + sycl::range<1>(n_opts), + [=](sycl::id<1> idx) { + const size_t i = n_params * idx[0]; + const data_t opt_price = params[i + PRICE]; + const data_t opt_strike = params[i + STRIKE]; + const data_t opt_maturity = params[i + MATURITY]; + const data_t opt_rate = params[i + RATE]; + const data_t opt_volatility = params[i + VOLATILITY]; + data_t a, b, c, y, z, e, d1, d1c, d2, d2c, w1, w2; + data_t mr = -opt_rate, sig_sig_two = two * opt_volatility * opt_volatility; + + a = cl::sycl::log( opt_price / opt_strike ); + b = opt_maturity * mr; + z = opt_maturity * sig_sig_two; + + c = quarter * z; + e = cl::sycl::exp( b ); + y = cl::sycl::rsqrt( z ); + + a = b - a; + w1 = ( a - c ) * y; + w2 = ( a + c ) * y; + + if (w1 < zero) { + d1 = cl::sycl::erfc(w1) * half; + d1c = one - d1; + } else { + d1c = cl::sycl::erfc(-w1) * half; + d1 = one - d1c; + } + if (w2 < zero) { + d2 = cl::sycl::erfc(w2) * half; + d2c = one - d2; + } else { + d2c = cl::sycl::erfc(-w2) * half; + d2 = one - d2c; + } + + e *= opt_strike; + data_t call_price = opt_price * d1 - e * d2; + data_t put_price = e * d2c - opt_price * d1c; + + const size_t callput_i = n_prices * idx[0]; + callput[callput_i + CALL] = call_price; + callput[callput_i + PUT ] = put_price; + }); + }); + + e.wait_and_throw(); + + return; +} + +template +void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) { + sycl::queue q = *(reinterpret_cast(q_ptr)); + + auto ctx = q.get_context(); + { + sycl::usm::alloc params_type = sycl::get_pointer_type(params, ctx); + if (params_type != sycl::usm::alloc::shared) { + throw std::runtime_error("Input option_params to cpp_blackscholes is not a USM-shared pointer."); + } + } + + sycl::event e = q.submit( + [&](sycl::handler &cgh) { + cgh.parallel_for( + sycl::range<1>(n_opts), + [=](sycl::item<1> idx) { + size_t i = n_params * idx.get_id(0); + size_t j = n_params_next_pow2 * idx.get_id(0); + + // create engine to sample 5 parameters per workers + oneapi::mkl::rng::device::philox4x32x10 engine(seed, j); + oneapi::mkl::rng::device::uniform distr; + + sycl::vec res = oneapi::mkl::rng::device::generate(distr, engine); + + { + const int pos = PRICE; + auto u = res[pos]; + params[i + pos] = pl * u + ph * (T(1)-u); + } + { + const int pos = STRIKE; + auto u = res[pos]; + params[i + pos] = sl * u + sh * (T(1)-u); + } + { + const int pos = MATURITY; + auto u = res[pos]; + params[i + pos] = tl * u + th * (T(1)-u); + } + { + const int pos = RATE; + auto u = res[pos]; + params[i + pos] = rl * u + rh * (T(1)-u); + } + { + const int pos = VOLATILITY; + auto u = res[pos]; + params[i + pos] = vl * u + vh * (T(1)-u); + } + }); + }); + + e.wait_and_throw(); +} + +// instantation for object files to not be empty + +template void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, double* params, double* callput); +template void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, float* params, float* callput); + + +template void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, double* params, + double pl, double ph, double sl, double sh, double tl, double th, + double rl, double rh, double vl, double vh, int seed); +template void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, float* params, + float pl, float ph, float sl, float sh, float tl, float th, + float rl, float rh, float vl, float vh, int seed); diff --git a/examples/cython/usm_memory/sycl_blackscholes.hpp b/examples/cython/usm_memory/sycl_blackscholes.hpp new file mode 100644 index 0000000000..36594810dc --- /dev/null +++ b/examples/cython/usm_memory/sycl_blackscholes.hpp @@ -0,0 +1,10 @@ +#include +#include "dppl_sycl_types.h" + +template +extern void cpp_blackscholes(DPPLSyclQueueRef q, size_t n_opts, T* params, T* callput); + +template +extern void cpp_populate_params(DPPLSyclQueueRef q, size_t n_opts, T* params, + T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, + int seed); diff --git a/examples/create_sycl_queues.py b/examples/python/create_sycl_queues.py similarity index 80% rename from examples/create_sycl_queues.py rename to examples/python/create_sycl_queues.py index 6fc6cdc9fa..bdf8368044 100644 --- a/examples/create_sycl_queues.py +++ b/examples/python/create_sycl_queues.py @@ -1,10 +1,11 @@ from __future__ import print_function -from dpctl import runtime, device_context, device_type +import dpctl +from dpctl import device_context, device_type # Global runtime object inside dpctl -rt = runtime +rt = dpctl # Print metadata about the runtime rt.dump() @@ -19,11 +20,11 @@ # the with device_context scope gets reset to what ever context was set # at entry of the scope. For this case, the context would go back to the # default context -with device_context(device_type.cpu, 0) as cpu_queue: +with device_context("opencl:cpu:0") as cpu_queue: print("========================================") print("Current context inside with scope") print("========================================") - rt.dump_queue(cpu_queue) + cpu_queue.get_sycl_device().dump_device_info() # Note the current context can be either directly accessed by using # the "cpu_queue" object, or it can be accessed via the runtime's @@ -31,10 +32,10 @@ print("========================================") print("Looking up current context using runtime") print("========================================") - rt.dump_queue(rt.get_current_queue()) + rt.get_current_queue().get_sycl_device().dump_device_info() print("========================================") print("Current context after exiting with scope") print("========================================") -rt.dump_queue(rt.get_current_queue()) +rt.get_current_queue().get_sycl_device().dump_device_info() diff --git a/examples/python/usm_memory_allocation.py b/examples/python/usm_memory_allocation.py new file mode 100644 index 0000000000..82b989f50b --- /dev/null +++ b/examples/python/usm_memory_allocation.py @@ -0,0 +1,22 @@ +import dpctl +import dpctl.memory as dpmem + +# allocate USM-shared byte-buffer +ms = dpmem.MemoryUSMShared(16) + +# allocate USM-device byte-buffer +md = dpmem.MemoryUSMDevice(16) + +# allocate USM-host byte-buffer +mh = dpmem.MemoryUSMHost(16) + +# specify alignment +mda = dpmem.MemoryUSMDevice(128, alignment=16) + +# allocate using given queue, +# i.e. on the device and bound to the context stored in the queue +mdq = dpmem.MemoryUSMDevice(256, queue=mda._queue) + +# information about device associate with USM buffer +print("Allocation performed on device:") +mda._queue.get_sycl_device().dump_device_info() diff --git a/examples/python/usm_memory_host_access.py b/examples/python/usm_memory_host_access.py new file mode 100644 index 0000000000..c38807be20 --- /dev/null +++ b/examples/python/usm_memory_host_access.py @@ -0,0 +1,38 @@ +import dpctl +import dpctl.memory as dpmem + +# USM-shared and USM-host pointers are host-accessible, +# meaning they are accessible from Python, therefore +# they implement Pyton buffer protocol + +# allocate 1K of USM-shared buffer +ms = dpmem.MemoryUSMShared(1024) + +# create memoryview into USM-shared buffer +msv = memoryview(ms) + +# populate buffer from host one byte at a type +for i in range(len(ms)): + ir = i % 256 + msv[i] = ir ** 2 % 256 + +mh = dpmem.MemoryUSMHost(64) +mhv = memoryview(mh) + +# copy content of block of USM-shared buffer to +# USM-host buffer +mhv[:] = msv[78 : 78 + len(mh)] + +print("Byte-values of the USM-host buffer") +print(list(mhv)) + +# USM-device buffer is not host accessible +md = dpmem.MemoryUSMDevice(16) +try: + mdv = memoryview(md) +except Exception as e: + print("") + print( + "An expected exception was raised during attempted construction of memoryview from USM-device memory object." + ) + print("\t", e) diff --git a/examples/python/usm_memory_operation.py b/examples/python/usm_memory_operation.py new file mode 100644 index 0000000000..efdb7861fd --- /dev/null +++ b/examples/python/usm_memory_operation.py @@ -0,0 +1,30 @@ +import dpctl +import dpctl.memory as dpmem +import numpy as np + +ms = dpmem.MemoryUSMShared(32) +md = dpmem.MemoryUSMDevice(32) + +host_buf = np.random.randint(0, 42, dtype=np.uint8, size=32) + +# copy host byte-like object to USM-device buffer +md.copy_from_host(host_buf) + +# copy USM-device buffer to USM-shared buffer in parallel (using sycl::queue::memcpy) +ms.copy_from_device(md) + +# build numpy array reusing host-accessible USM-shared memory +X = np.ndarray((len(ms),), buffer=ms, dtype=np.uint8) + +# Display Python object NumPy ndarray is viewing into +print("numpy.ndarray.base: ", X.base) +print("") + +# Print content of the view +print("View..........: ", X) + +# Print content of the original host buffer +print("host_buf......: ", host_buf) + +# use copy_to_host to retrieve memory of USM-device memory +print("copy_to_host(): ", md.copy_to_host()) From 45959f938436a86797253018db606944188d7cba Mon Sep 17 00:00:00 2001 From: Elena Totmenina Date: Fri, 4 Dec 2020 23:27:55 +0300 Subject: [PATCH 4/8] Rename dppl to dpctl (#201) * Rename dppl to dpctl * Formatting fixes Co-authored-by: etotmeni --- .gitignore | 4 +- MANIFEST.in | 2 +- backends/include/dppl_sycl_enum_types.h | 91 ---- backends/tests/test_sycl_device_interface.cpp | 397 ------------------ backends/tests/test_sycl_queue_interface.cpp | 379 ----------------- conda-recipe/build.sh | 4 +- docs/CMakeLists.txt | 2 +- docs/Doxyfile.in | 6 +- docs/conf.in | 80 ++-- {backends => dpctl-capi}/.gitignore | 0 {backends => dpctl-capi}/CMakeLists.txt | 36 +- {backends => dpctl-capi}/dbg_build.sh | 0 .../helper/include/dpctl_utils_helper.h | 8 +- .../helper/source/dpctl_utils_helper.cpp | 10 +- .../include/Support/CBindingWrapping.h | 4 +- .../include/Support/DllExport.h | 10 +- .../include/Support/ExternC.h | 10 +- .../include/Support/MemOwnershipAttrs.h | 46 +- .../include/dpctl_data_types.h | 2 +- .../include/dpctl_sycl_context_interface.h | 42 +- .../include/dpctl_sycl_device_interface.h | 102 ++--- dpctl-capi/include/dpctl_sycl_enum_types.h | 91 ++++ .../include/dpctl_sycl_event_interface.h | 24 +- .../include/dpctl_sycl_kernel_interface.h | 32 +- .../include/dpctl_sycl_platform_interface.h | 38 +- .../include/dpctl_sycl_program_interface.h | 50 +-- .../include/dpctl_sycl_queue_interface.h | 126 +++--- .../include/dpctl_sycl_queue_manager.h | 102 ++--- .../include/dpctl_sycl_types.h | 26 +- .../include/dpctl_sycl_usm_interface.h | 80 ++-- .../include/dpctl_utils.h | 18 +- .../source/dpctl_sycl_context_interface.cpp | 30 +- .../source/dpctl_sycl_device_interface.cpp | 58 +-- .../source/dpctl_sycl_event_interface.cpp | 12 +- .../source/dpctl_sycl_kernel_interface.cpp | 16 +- .../source/dpctl_sycl_platform_interface.cpp | 32 +- .../source/dpctl_sycl_program_interface.cpp | 38 +- .../source/dpctl_sycl_queue_interface.cpp | 112 ++--- .../source/dpctl_sycl_queue_manager.cpp | 124 +++--- .../source/dpctl_sycl_usm_interface.cpp | 64 +-- .../source/dpctl_utils.cpp | 10 +- {backends => dpctl-capi}/tests/CMakeLists.txt | 2 +- .../tests/multi_kernel.spv | Bin {backends => dpctl-capi}/tests/test_main.cpp | 0 .../tests/test_sycl_device_interface.cpp | 397 ++++++++++++++++++ .../tests/test_sycl_kernel_interface.cpp | 76 ++-- .../tests/test_sycl_platform_interface.cpp | 32 +- .../tests/test_sycl_program_interface.cpp | 104 ++--- .../tests/test_sycl_queue_interface.cpp | 379 +++++++++++++++++ .../tests/test_sycl_queue_manager.cpp | 156 +++---- .../tests/test_sycl_usm_interface.cpp | 104 ++--- dpctl/__init__.pxd | 2 +- dpctl/_backend.pxd | 352 ++++++++-------- dpctl/_sycl_core.pxd | 42 +- dpctl/_sycl_core.pyx | 204 ++++----- dpctl/memory/_memory.pxd | 8 +- dpctl/memory/_memory.pyx | 48 +-- dpctl/tests/test_sycl_device.py | 2 +- .../cython/sycl_buffer/_buffer_example.pyx | 6 +- .../cython/sycl_buffer/use_sycl_buffer.cpp | 6 +- examples/cython/sycl_buffer/use_sycl_buffer.h | 6 +- examples/cython/usm_memory/blackscholes.pyx | 8 +- .../cython/usm_memory/sycl_blackscholes.cpp | 14 +- .../cython/usm_memory/sycl_blackscholes.hpp | 6 +- scripts/build_backend.py | 8 +- scripts/build_for_develop.bat | 8 +- scripts/build_for_develop.sh | 8 +- setup.cfg | 2 +- setup.py | 28 +- 69 files changed, 2164 insertions(+), 2162 deletions(-) delete mode 100644 backends/include/dppl_sycl_enum_types.h delete mode 100644 backends/tests/test_sycl_device_interface.cpp delete mode 100644 backends/tests/test_sycl_queue_interface.cpp rename {backends => dpctl-capi}/.gitignore (100%) rename {backends => dpctl-capi}/CMakeLists.txt (86%) rename {backends => dpctl-capi}/dbg_build.sh (100%) rename backends/helper/include/dppl_utils_helper.h => dpctl-capi/helper/include/dpctl_utils_helper.h (83%) rename backends/helper/source/dppl_utils_helper.cpp => dpctl-capi/helper/source/dpctl_utils_helper.cpp (87%) rename {backends => dpctl-capi}/include/Support/CBindingWrapping.h (95%) rename {backends => dpctl-capi}/include/Support/DllExport.h (81%) rename {backends => dpctl-capi}/include/Support/ExternC.h (82%) rename {backends => dpctl-capi}/include/Support/MemOwnershipAttrs.h (62%) rename backends/include/dppl_data_types.h => dpctl-capi/include/dpctl_data_types.h (97%) rename backends/include/dppl_sycl_context_interface.h => dpctl-capi/include/dpctl_sycl_context_interface.h (63%) rename backends/include/dppl_sycl_device_interface.h => dpctl-capi/include/dpctl_sycl_device_interface.h (70%) create mode 100644 dpctl-capi/include/dpctl_sycl_enum_types.h rename backends/include/dppl_sycl_event_interface.h => dpctl-capi/include/dpctl_sycl_event_interface.h (68%) rename backends/include/dppl_sycl_kernel_interface.h => dpctl-capi/include/dpctl_sycl_kernel_interface.h (71%) rename backends/include/dppl_sycl_platform_interface.h => dpctl-capi/include/dpctl_sycl_platform_interface.h (64%) rename backends/include/dppl_sycl_program_interface.h => dpctl-capi/include/dpctl_sycl_program_interface.h (74%) rename backends/include/dppl_sycl_queue_interface.h => dpctl-capi/include/dpctl_sycl_queue_interface.h (68%) rename backends/include/dppl_sycl_queue_manager.h => dpctl-capi/include/dpctl_sycl_queue_manager.h (67%) rename backends/include/dppl_sycl_types.h => dpctl-capi/include/dpctl_sycl_types.h (65%) rename backends/include/dppl_sycl_usm_interface.h => dpctl-capi/include/dpctl_sycl_usm_interface.h (66%) rename backends/include/dppl_utils.h => dpctl-capi/include/dpctl_utils.h (81%) rename backends/source/dppl_sycl_context_interface.cpp => dpctl-capi/source/dpctl_sycl_context_interface.cpp (68%) rename backends/source/dppl_sycl_device_interface.cpp => dpctl-capi/source/dpctl_sycl_device_interface.cpp (75%) rename backends/source/dppl_sycl_event_interface.cpp => dpctl-capi/source/dpctl_sycl_event_interface.cpp (80%) rename backends/source/dppl_sycl_kernel_interface.cpp => dpctl-capi/source/dpctl_sycl_kernel_interface.cpp (80%) rename backends/source/dppl_sycl_platform_interface.cpp => dpctl-capi/source/dpctl_sycl_platform_interface.cpp (84%) rename backends/source/dppl_sycl_program_interface.cpp => dpctl-capi/source/dpctl_sycl_program_interface.cpp (79%) rename backends/source/dppl_sycl_queue_interface.cpp => dpctl-capi/source/dpctl_sycl_queue_interface.cpp (72%) rename backends/source/dppl_sycl_queue_manager.cpp => dpctl-capi/source/dpctl_sycl_queue_manager.cpp (78%) rename backends/source/dppl_sycl_usm_interface.cpp => dpctl-capi/source/dpctl_sycl_usm_interface.cpp (58%) rename backends/source/dppl_utils.cpp => dpctl-capi/source/dpctl_utils.cpp (76%) rename {backends => dpctl-capi}/tests/CMakeLists.txt (91%) rename {backends => dpctl-capi}/tests/multi_kernel.spv (100%) rename {backends => dpctl-capi}/tests/test_main.cpp (100%) create mode 100644 dpctl-capi/tests/test_sycl_device_interface.cpp rename {backends => dpctl-capi}/tests/test_sycl_kernel_interface.cpp (51%) rename {backends => dpctl-capi}/tests/test_sycl_platform_interface.cpp (58%) rename {backends => dpctl-capi}/tests/test_sycl_program_interface.cpp (65%) create mode 100644 dpctl-capi/tests/test_sycl_queue_interface.cpp rename {backends => dpctl-capi}/tests/test_sycl_queue_manager.cpp (54%) rename {backends => dpctl-capi}/tests/test_sycl_usm_interface.cpp (52%) diff --git a/.gitignore b/.gitignore index 28f872d7aa..8db869bfb6 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,7 @@ var/ *.egg-info/ .installed.cfg *.egg -dppl_conda_pkg +dpctl_conda_pkg # PyInstaller # Usually these files are written by a python script from a template @@ -81,4 +81,4 @@ target/ .python-version # generated Cython files -_dppl_bindings* \ No newline at end of file +_dpctl_bindings* diff --git a/MANIFEST.in b/MANIFEST.in index 43d8bddba4..2890d77617 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ include versioneer.py recursive-include dpctl/include *.h *.hpp include dpctl/*.pxd -include dpctl/*DPPL*Interface.* +include dpctl/*DPCTL*Interface.* include dpctl/tests/input_files/* global-exclude *.cpp diff --git a/backends/include/dppl_sycl_enum_types.h b/backends/include/dppl_sycl_enum_types.h deleted file mode 100644 index 0d8d73f091..0000000000 --- a/backends/include/dppl_sycl_enum_types.h +++ /dev/null @@ -1,91 +0,0 @@ -//===--- dppl_sycl_enum_types.h - DPPL-SYCL interface ---*---C++ -----*----===// -// -// Python Data Parallel Processing Library (PyDPPL) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This header defines DPPL specficif enum types that wrap corresponding Sycl -/// enum classes. These enums are defined primarily so that Python extensions -/// that use DPPL do not have to include Sycl headers directly. -/// -//===----------------------------------------------------------------------===// - -#pragma once - -#include "Support/ExternC.h" - -DPPL_C_EXTERN_C_BEGIN - -/*! - * @brief Redefinition of DPC++-specific Sycl backend types. - * - */ -enum DPPLSyclBackendType -{ - DPPL_UNKNOWN_BACKEND = 0x0, - DPPL_OPENCL = 1 << 16, - DPPL_HOST = 1 << 15, - DPPL_LEVEL_ZERO = 1 << 14, - DPPL_CUDA = 1 << 13 -}; - -/*! - * @brief DPPL device types that are equivalent to Sycl's device_type. - * - */ -enum DPPLSyclDeviceType -{ - DPPL_CPU = 1 << 0, - DPPL_GPU = 1 << 1, - DPPL_ACCELERATOR = 1 << 2, - DPPL_CUSTOM = 1 << 3, - DPPL_AUTOMATIC = 1 << 4, - DPPL_HOST_DEVICE = 1 << 5, - DPPL_ALL = 1 << 6 - // IMP: before adding new values here look at DPPLSyclBackendType enum. The - // values should not overlap. -}; - -/*! - * @brief Supported types for kernel arguments to be passed to a Sycl kernel - * using DPPL. - * - * \todo Add support for sycl::buffer - * - */ -typedef enum -{ - DPPL_CHAR, - DPPL_SIGNED_CHAR, - DPPL_UNSIGNED_CHAR, - DPPL_SHORT, - DPPL_INT, - DPPL_UNSIGNED_INT, - DPPL_UNSIGNED_INT8, - DPPL_LONG, - DPPL_UNSIGNED_LONG, - DPPL_LONG_LONG, - DPPL_UNSIGNED_LONG_LONG, - DPPL_SIZE_T, - DPPL_FLOAT, - DPPL_DOUBLE, - DPPL_LONG_DOUBLE, - DPPL_VOID_PTR -} DPPLKernelArgType; - -DPPL_C_EXTERN_C_END diff --git a/backends/tests/test_sycl_device_interface.cpp b/backends/tests/test_sycl_device_interface.cpp deleted file mode 100644 index f4ff03d2a9..0000000000 --- a/backends/tests/test_sycl_device_interface.cpp +++ /dev/null @@ -1,397 +0,0 @@ -//===----- test_sycl_device_interface.cpp - dpctl-C_API interface -*- C++ -*-===// -// -// Python Data Parallel Processing Library (PyDPPL) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file has unit test cases for functions defined in -/// dppl_sycl_device_interface.h. -/// -//===----------------------------------------------------------------------===// - -#include "dppl_sycl_device_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" -#include "dppl_utils.h" - -#include -#include - -using namespace cl::sycl; - - -struct TestDPPLSyclDeviceInterface : public ::testing::Test -{ - DPPLSyclDeviceRef OpenCL_cpu = nullptr; - DPPLSyclDeviceRef OpenCL_gpu = nullptr; - DPPLSyclDeviceRef OpenCL_Level0_gpu = nullptr; - - TestDPPLSyclDeviceInterface () - { - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU)) { - auto Q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_CPU, 0); - OpenCL_cpu = DPPLQueue_GetDevice(Q); - DPPLQueue_Delete(Q); - } - - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) { - auto Q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - OpenCL_gpu = DPPLQueue_GetDevice(Q); - DPPLQueue_Delete(Q); - } - - if(DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU)) { - auto Q = DPPLQueueMgr_GetQueue(DPPL_LEVEL_ZERO, DPPL_GPU, 0); - OpenCL_Level0_gpu = DPPLQueue_GetDevice(Q); - DPPLQueue_Delete(Q); - } - } - - ~TestDPPLSyclDeviceInterface () - { - DPPLDevice_Delete(OpenCL_cpu); - DPPLDevice_Delete(OpenCL_gpu); - DPPLDevice_Delete(OpenCL_Level0_gpu); - } - -}; - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetDriverInfo) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto DriverInfo = DPPLDevice_GetDriverInfo(OpenCL_cpu); - EXPECT_TRUE(DriverInfo != nullptr); - DPPLCString_Delete(DriverInfo); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetDriverInfo) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto DriverInfo = DPPLDevice_GetDriverInfo(OpenCL_gpu); - EXPECT_TRUE(DriverInfo != nullptr); - DPPLCString_Delete(DriverInfo); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetDriverInfo) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto DriverInfo = DPPLDevice_GetDriverInfo(OpenCL_Level0_gpu); - EXPECT_TRUE(DriverInfo != nullptr); - DPPLCString_Delete(DriverInfo); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetMaxComputeUnits) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto n = DPPLDevice_GetMaxComputeUnits(OpenCL_cpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetMaxComputeUnits) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto n = DPPLDevice_GetMaxComputeUnits(OpenCL_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetMaxComputeUnits) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto n = DPPLDevice_GetMaxComputeUnits(OpenCL_Level0_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkItemDims) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto n = DPPLDevice_GetMaxWorkItemDims(OpenCL_cpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkItemDims) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto n = DPPLDevice_GetMaxWorkItemDims(OpenCL_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkItemDims) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto n = DPPLDevice_GetMaxWorkItemDims(OpenCL_Level0_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkItemSizes) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto item_sizes = DPPLDevice_GetMaxWorkItemSizes(OpenCL_cpu); - EXPECT_TRUE(item_sizes != nullptr); - DPPLSize_t_Array_Delete(item_sizes); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkItemSizes) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto item_sizes = DPPLDevice_GetMaxWorkItemSizes(OpenCL_gpu); - EXPECT_TRUE(item_sizes != nullptr); - DPPLSize_t_Array_Delete(item_sizes); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkItemSizes) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto item_sizes = DPPLDevice_GetMaxWorkItemSizes(OpenCL_Level0_gpu); - EXPECT_TRUE(item_sizes != nullptr); - DPPLSize_t_Array_Delete(item_sizes); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkGroupSize) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto n = DPPLDevice_GetMaxWorkGroupSize(OpenCL_cpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkGroupSize) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto n = DPPLDevice_GetMaxWorkGroupSize(OpenCL_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkGroupSize) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto n = DPPLDevice_GetMaxWorkGroupSize(OpenCL_Level0_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetMaxNumSubGroups) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto n = DPPLDevice_GetMaxNumSubGroups(OpenCL_cpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetMaxNumSubGroups) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto n = DPPLDevice_GetMaxNumSubGroups(OpenCL_gpu); - EXPECT_TRUE(n > 0); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetMaxNumSubGroups) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto n = DPPLDevice_GetMaxNumSubGroups(OpenCL_Level0_gpu); - EXPECT_TRUE(n > 0); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_HasInt64BaseAtomics) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto atomics = DPPLDevice_HasInt64BaseAtomics(OpenCL_cpu); - auto D = reinterpret_cast(OpenCL_cpu); - auto has_atomics= D->has(aspect::int64_base_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_HasInt64BaseAtomics) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto atomics = DPPLDevice_HasInt64BaseAtomics(OpenCL_gpu); - auto D = reinterpret_cast(OpenCL_gpu); - auto has_atomics= D->has(aspect::int64_base_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_HasInt64BaseAtomics) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto atomics = DPPLDevice_HasInt64BaseAtomics(OpenCL_Level0_gpu); - auto D = reinterpret_cast(OpenCL_Level0_gpu); - auto has_atomics= D->has(aspect::int64_base_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_HasInt64ExtendedAtomics) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto atomics = DPPLDevice_HasInt64ExtendedAtomics(OpenCL_cpu); - auto D = reinterpret_cast(OpenCL_cpu); - auto has_atomics= D->has(aspect::int64_extended_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_HasInt64ExtendedAtomics) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL GPU device found."); - - auto atomics = DPPLDevice_HasInt64ExtendedAtomics(OpenCL_gpu); - auto D = reinterpret_cast(OpenCL_gpu); - auto has_atomics= D->has(aspect::int64_extended_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -//TODO: Update when DPC++ properly supports aspects -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_HasInt64ExtendedAtomics) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto atomics = DPPLDevice_HasInt64ExtendedAtomics(OpenCL_Level0_gpu); - auto D = reinterpret_cast(OpenCL_Level0_gpu); - auto has_atomics= D->has(aspect::int64_extended_atomics); - EXPECT_TRUE(has_atomics == atomics); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetName) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto DevName = DPPLDevice_GetName(OpenCL_cpu); - EXPECT_TRUE(DevName != nullptr); - DPPLCString_Delete(DevName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetName) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto DevName = DPPLDevice_GetName(OpenCL_gpu); - EXPECT_TRUE(DevName != nullptr); - DPPLCString_Delete(DevName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetName) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto DevName = DPPLDevice_GetName(OpenCL_Level0_gpu); - EXPECT_TRUE(DevName != nullptr); - DPPLCString_Delete(DevName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_GetVendorName) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto VendorName = DPPLDevice_GetVendorName(OpenCL_cpu); - EXPECT_TRUE(VendorName != nullptr); - DPPLCString_Delete(VendorName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_GetVendorName) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - auto VendorName = DPPLDevice_GetVendorName(OpenCL_gpu); - EXPECT_TRUE(VendorName != nullptr); - DPPLCString_Delete(VendorName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_GetVendorName) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - auto VendorName = DPPLDevice_GetVendorName(OpenCL_Level0_gpu); - EXPECT_TRUE(VendorName != nullptr); - DPPLCString_Delete(VendorName); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLCPU_IsCPU) -{ - if(!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - EXPECT_TRUE(DPPLDevice_IsCPU(OpenCL_cpu)); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckOCLGPU_IsGPU) -{ - if(!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - EXPECT_TRUE(DPPLDevice_IsGPU(OpenCL_gpu)); -} - -TEST_F (TestDPPLSyclDeviceInterface, CheckLevel0GPU_IsGPU) -{ - if(!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no Level0 GPU device found."); - - EXPECT_TRUE(DPPLDevice_IsGPU(OpenCL_Level0_gpu)); -} - diff --git a/backends/tests/test_sycl_queue_interface.cpp b/backends/tests/test_sycl_queue_interface.cpp deleted file mode 100644 index 43ae46a29a..0000000000 --- a/backends/tests/test_sycl_queue_interface.cpp +++ /dev/null @@ -1,379 +0,0 @@ -//===-------- test_sycl_queue_interface.cpp - dpctl-C_API ---*--- C++ --*--===// -// -// Data Parallel Control Library (dpCtl) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file has unit test cases for functions defined in -/// dppl_sycl_queue_interface.h. -/// -//===----------------------------------------------------------------------===// - -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_event_interface.h" -#include "dppl_sycl_kernel_interface.h" -#include "dppl_sycl_program_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" -#include "dppl_sycl_usm_interface.h" -#include "Support/CBindingWrapping.h" -#include -#include - -using namespace cl::sycl; - -namespace -{ -constexpr size_t SIZE = 1024; - -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPPLSyclUSMRef); - -void add_kernel_checker (const float *a, const float *b, const float *c) -{ - // Validate the data - for(auto i = 0ul; i < SIZE; ++i) { - EXPECT_EQ(c[i], a[i] + b[i]); - } -} - -void axpy_kernel_checker (const float *a, const float *b, const float *c, - float d) -{ - for(auto i = 0ul; i < SIZE; ++i) { - EXPECT_EQ(c[i], a[i] + d*b[i]); - } -} - -bool has_devices () -{ - bool ret = false; - for (auto &p : platform::get_platforms()) { - if (p.is_host()) - continue; - if(!p.get_devices().empty()) { - ret = true; - break; - } - } - return ret; -} - -} - -struct TestDPPLSyclQueueInterface : public ::testing::Test -{ - const char *CLProgramStr = R"CLC( - kernel void init_arr (global float *a) { - size_t index = get_global_id(0); - a[index] = (float)index; - } - - kernel void add (global float* a, global float* b, global float* c) { - size_t index = get_global_id(0); - c[index] = a[index] + b[index]; - } - - kernel void axpy (global float* a, global float* b, - global float* c, float d) { - size_t index = get_global_id(0); - c[index] = a[index] + d*b[index]; - } - )CLC"; - const char *CompileOpts ="-cl-fast-relaxed-math"; - - TestDPPLSyclQueueInterface () - { } - - ~TestDPPLSyclQueueInterface () - { } -}; - -TEST_F (TestDPPLSyclQueueInterface, CheckAreEq) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto nOclGPU = DPPLQueueMgr_GetNumQueues(DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU); - if(!nOclGPU) - GTEST_SKIP_("Skipping: No OpenCL GPUs available.\n"); - - auto Q1 = DPPLQueueMgr_GetCurrentQueue(); - auto Q2 = DPPLQueueMgr_GetCurrentQueue(); - EXPECT_TRUE(DPPLQueue_AreEq(Q1, Q2)); - - auto Def_Q = DPPLQueueMgr_SetAsDefaultQueue( - DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU, - 0 - ); - auto OclGPU_Q0 = DPPLQueueMgr_PushQueue( - DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU, - 0 - ); - auto OclGPU_Q1 = DPPLQueueMgr_PushQueue( - DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU, - 0 - ); - EXPECT_TRUE(DPPLQueue_AreEq(Def_Q, OclGPU_Q0)); - EXPECT_TRUE(DPPLQueue_AreEq(Def_Q, OclGPU_Q1)); - EXPECT_TRUE(DPPLQueue_AreEq(OclGPU_Q0, OclGPU_Q1)); - DPPLQueue_Delete(Def_Q); - DPPLQueue_Delete(OclGPU_Q0); - DPPLQueue_Delete(OclGPU_Q1); - DPPLQueueMgr_PopQueue(); - DPPLQueueMgr_PopQueue(); -} - -TEST_F (TestDPPLSyclQueueInterface, CheckAreEq2) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto nOclGPU = DPPLQueueMgr_GetNumQueues(DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU); - auto nOclCPU = DPPLQueueMgr_GetNumQueues(DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_CPU); - if(!nOclGPU || !nOclCPU) - GTEST_SKIP_("OpenCL GPUs and CPU not available.\n"); - auto GPU_Q = DPPLQueueMgr_PushQueue( - DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_GPU, - 0 - ); - auto CPU_Q = DPPLQueueMgr_PushQueue( - DPPLSyclBackendType::DPPL_OPENCL, - DPPLSyclDeviceType::DPPL_CPU, - 0 - ); - EXPECT_FALSE(DPPLQueue_AreEq(GPU_Q, CPU_Q)); - DPPLQueueMgr_PopQueue(); - DPPLQueueMgr_PopQueue(); -} - -TEST_F (TestDPPLSyclQueueInterface, CheckGetBackend) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto Q1 = DPPLQueueMgr_GetCurrentQueue(); - auto BE = DPPLQueue_GetBackend(Q1); - EXPECT_TRUE((BE == DPPL_OPENCL) || - (BE == DPPL_LEVEL_ZERO) || - (BE == DPPL_CUDA) || - (BE == DPPL_HOST) - ); - DPPLQueue_Delete(Q1); - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); - EXPECT_TRUE(DPPLQueue_GetBackend(Q) == DPPL_OPENCL); - DPPLQueue_Delete(Q); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); - EXPECT_TRUE(DPPLQueue_GetBackend(Q) == DPPL_OPENCL); - DPPLQueue_Delete(Q); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_LEVEL_ZERO, DPPL_GPU, 0); - EXPECT_TRUE(DPPLQueue_GetBackend(Q) == DPPL_LEVEL_ZERO); - DPPLQueue_Delete(Q); - DPPLQueueMgr_PopQueue(); - } -} - -TEST_F (TestDPPLSyclQueueInterface, CheckGetContext) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto Q1 = DPPLQueueMgr_GetCurrentQueue(); - auto Ctx = DPPLQueue_GetContext(Q1); - ASSERT_TRUE(Ctx != nullptr); - DPPLQueue_Delete(Q1); - DPPLContext_Delete(Ctx); - - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto OclGpuCtx = DPPLQueue_GetContext(Q); - ASSERT_TRUE(OclGpuCtx != nullptr); - DPPLQueue_Delete(Q); - DPPLContext_Delete(OclGpuCtx); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); - auto OclCpuCtx = DPPLQueue_GetContext(Q); - ASSERT_TRUE(OclCpuCtx != nullptr); - DPPLQueue_Delete(Q); - DPPLContext_Delete(OclCpuCtx); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_LEVEL_ZERO, DPPL_GPU, 0); - auto L0Ctx = DPPLQueue_GetContext(Q); - ASSERT_TRUE(Ctx != nullptr); - DPPLQueue_Delete(Q); - DPPLContext_Delete(L0Ctx); - DPPLQueueMgr_PopQueue(); - } -} - -TEST_F (TestDPPLSyclQueueInterface, CheckGetDevice) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto Q1 = DPPLQueueMgr_GetCurrentQueue(); - auto D = DPPLQueue_GetDevice(Q1); - ASSERT_TRUE(D != nullptr); - DPPLQueue_Delete(Q1); - DPPLDevice_Delete(D); - - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto OCLGPU_D = DPPLQueue_GetDevice(Q); - ASSERT_TRUE(OCLGPU_D != nullptr); - EXPECT_TRUE(DPPLDevice_IsGPU(OCLGPU_D)); - DPPLQueue_Delete(Q); - DPPLDevice_Delete(OCLGPU_D); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); - auto OCLCPU_D = DPPLQueue_GetDevice(Q); - ASSERT_TRUE(OCLCPU_D != nullptr); - EXPECT_TRUE(DPPLDevice_IsCPU(OCLCPU_D)); - DPPLQueue_Delete(Q); - DPPLDevice_Delete(OCLCPU_D); - DPPLQueueMgr_PopQueue(); - } - if(DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU)) { - auto Q = DPPLQueueMgr_PushQueue(DPPL_LEVEL_ZERO, DPPL_GPU, 0); - auto L0GPU_D = DPPLQueue_GetDevice(Q); - ASSERT_TRUE(L0GPU_D != nullptr); - EXPECT_TRUE(DPPLDevice_IsGPU(L0GPU_D)); - DPPLQueue_Delete(Q); - DPPLDevice_Delete(L0GPU_D); - DPPLQueueMgr_PopQueue(); - } -} - -TEST_F (TestDPPLSyclQueueInterface, CheckSubmit) -{ - if(!has_devices()) - GTEST_SKIP_("Skipping: No Sycl devices.\n"); - - auto nOpenCLGpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU); - - if(!nOpenCLGpuQ) - GTEST_SKIP_("Skipping: No OpenCL GPU device.\n"); - - auto Queue = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(Queue); - auto PRef = DPPLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, - CompileOpts); - ASSERT_TRUE(PRef != nullptr); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "init_arr")); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "add")); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "axpy")); - - auto InitKernel = DPPLProgram_GetKernel(PRef, "init_arr"); - auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); - auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); - - // Create the input args - auto a = DPPLmalloc_shared(SIZE, Queue); - ASSERT_TRUE(a != nullptr); - auto b = DPPLmalloc_shared(SIZE, Queue); - ASSERT_TRUE(b != nullptr); - auto c = DPPLmalloc_shared(SIZE, Queue); - ASSERT_TRUE(c != nullptr); - - // Initialize a,b - DPPLKernelArgType argTypes[] = {DPPL_VOID_PTR}; - size_t Range[] = {SIZE}; - void *arg1[1] = { unwrap(a) }; - void *arg2[1] = { unwrap(b) }; - - auto E1 = DPPLQueue_SubmitRange(InitKernel, Queue, arg1, argTypes, 1, - Range, 1, nullptr, 0); - auto E2 = DPPLQueue_SubmitRange(InitKernel, Queue, arg2, argTypes, 1, - Range, 1, nullptr, 0); - ASSERT_TRUE(E1 != nullptr); - ASSERT_TRUE(E2 != nullptr); - - DPPLQueue_Wait(Queue); - - // Submit the add kernel - void *args[3] = { unwrap(a), unwrap(b), unwrap(c) }; - DPPLKernelArgType addKernelArgTypes[] = { - DPPL_VOID_PTR, - DPPL_VOID_PTR, - DPPL_VOID_PTR - }; - - auto E3 = DPPLQueue_SubmitRange(AddKernel, Queue, args, - addKernelArgTypes, 3, Range, 1, nullptr, 0); - ASSERT_TRUE(E3 != nullptr); - DPPLQueue_Wait(Queue); - - // Verify the result of "add" - add_kernel_checker((float*)a, (float*)b, (float*)c); - - // Create kernel args for axpy - float d = 10.0; - void *args2[4] = { unwrap(a), unwrap(b), unwrap(c) , (void*)&d }; - DPPLKernelArgType addKernelArgTypes2[] = { - DPPL_VOID_PTR, - DPPL_VOID_PTR, - DPPL_VOID_PTR, - DPPL_FLOAT - }; - auto E4 = DPPLQueue_SubmitRange(AxpyKernel, Queue, args2, - addKernelArgTypes2, 4, Range, 1, - nullptr, 0); - ASSERT_TRUE(E4 != nullptr); - DPPLQueue_Wait(Queue); - - // Verify the result of "axpy" - axpy_kernel_checker((float*)a, (float*)b, (float*)c, d); - - // clean ups - DPPLEvent_Delete(E1); - DPPLEvent_Delete(E2); - DPPLEvent_Delete(E3); - DPPLEvent_Delete(E4); - - DPPLKernel_Delete(AddKernel); - DPPLKernel_Delete(AxpyKernel); - DPPLKernel_Delete(InitKernel); - - DPPLfree_with_queue((DPPLSyclUSMRef)a, Queue); - DPPLfree_with_queue((DPPLSyclUSMRef)b, Queue); - DPPLfree_with_queue((DPPLSyclUSMRef)c, Queue); - - DPPLQueue_Delete(Queue); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); -} - diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 1c962f6ddd..67278d2115 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,11 +1,11 @@ #!/bin/bash -# We need dpcpp to compile dppl_sycl_interface +# We need dpcpp to compile dpctl_sycl_interface if [ ! -z "${ONEAPI_ROOT}" ]; then # Suppress error b/c it could fail on Ubuntu 18.04 source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true else - echo "DPCPP is needed to build DPPL. Abort!" + echo "DPCPP is needed to build DPCTL. Abort!" exit 1 fi diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index bce3c2ed5d..f62ad49123 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -25,7 +25,7 @@ if (GIT_FOUND) ) endif (GIT_FOUND) -set(DOXYGEN_INPUT_DIR ../backends) +set(DOXYGEN_INPUT_DIR ../dpctl-capi) set(DOXYGEN_OUTPUT_DIR ${DOC_OUTPUT_DIR}/doxygen) set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/html/index.html) set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index af529c829b..781451d69e 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -917,9 +917,9 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = ../backends/build -EXCLUDE += ../backends/install -EXCLUDE += ../backends/tests +EXCLUDE = ../dpctl-capi/build +EXCLUDE += ../dpctl-capi/install +EXCLUDE += ../dpctl-capi/tests # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/docs/conf.in b/docs/conf.in index 6a05eae7af..5153349d14 100644 --- a/docs/conf.in +++ b/docs/conf.in @@ -12,9 +12,9 @@ import textwrap # -- Project information ----------------------------------------------------- -project = 'Data-parallel Control (dpctl)' -copyright = '2020, Intel Corp.' -author = 'Intel Corp.' +project = "Data-parallel Control (dpctl)" +copyright = "2020, Intel Corp." +author = "Intel Corp." version = "@CURRENT_RELEASE@" # The full version, including alpha/beta/rc tags @@ -29,81 +29,83 @@ release = "@CURRENT_RELEASE@" extensions = [ "breathe", "exhale", - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.viewcode', - 'sphinx.ext.githubpages', - 'sphinx.ext.autodoc', - 'sphinx.ext.napoleon' + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", + "sphinx.ext.githubpages", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", ] # Breathe Configuration breathe_default_project = "dpCtl-CAPI" # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # Setup the exhale extension exhale_args = { # These arguments are required - "containmentFolder": "./api", - "rootFileName": "dpCtl-CAPI_root.rst", - "rootFileTitle": "dpCtl C API", - "doxygenStripFromPath": "..", - "createTreeView": True, + "containmentFolder": "./api", + "rootFileName": "dpCtl-CAPI_root.rst", + "rootFileTitle": "dpCtl C API", + "doxygenStripFromPath": "..", + "createTreeView": True, "exhaleExecutesDoxygen": True, - #"exhaleUseDoxyfile": True, - "exhaleDoxygenStdin": textwrap.dedent(''' - INPUT = ../backends/include + # "exhaleUseDoxyfile": True, + "exhaleDoxygenStdin": textwrap.dedent( + """ + INPUT = ../dpctl-capi/include REPEAT_BRIEF=YES OPTIMIZE_OUTPUT_FOR_C=YES OPTIMIZE_OUTPUT_JAVA= NO EXTRACT_ALL=YES - EXCLUDE= ../backends/build - EXCLUDE+= ../backends/install - EXCLUDE+= ../backends/tests + EXCLUDE= ../dpctl-capi/build + EXCLUDE+= ../dpctl-capi/install + EXCLUDE+= ../dpctl-capi/tests EXCLUDE_PATTERNS = CMakeLists.txt - ''') + """ + ), } -highlight_language = 'c' +highlight_language = "c" # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" html_theme_options = { - 'canonical_url': '', - 'analytics_id': '', - 'display_version': True, - 'prev_next_buttons_location': 'bottom', - 'style_external_links': False, - 'logo_only': False, + "canonical_url": "", + "analytics_id": "", + "display_version": True, + "prev_next_buttons_location": "bottom", + "style_external_links": False, + "logo_only": False, # Toc options - 'collapse_navigation': True, - 'sticky_navigation': True, - 'navigation_depth': 4, - 'includehidden': True, - 'titles_only': False + "collapse_navigation": True, + "sticky_navigation": True, + "navigation_depth": 4, + "includehidden": True, + "titles_only": False, } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] diff --git a/backends/.gitignore b/dpctl-capi/.gitignore similarity index 100% rename from backends/.gitignore rename to dpctl-capi/.gitignore diff --git a/backends/CMakeLists.txt b/dpctl-capi/CMakeLists.txt similarity index 86% rename from backends/CMakeLists.txt rename to dpctl-capi/CMakeLists.txt index de5af9fb73..b327f271c9 100644 --- a/backends/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -34,7 +34,7 @@ function (check_for_dpcpp) message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}") endforeach() else() - message(FATAL_ERROR "DPCPP needed to build dppl_sycl_interface") + message(FATAL_ERROR "DPCPP needed to build dpctl_sycl_interface") endif() endfunction() @@ -65,24 +65,24 @@ else() endif() add_library( - DPPLSyclInterface + DPCTLSyclInterface SHARED - source/dppl_sycl_context_interface.cpp - source/dppl_sycl_device_interface.cpp - source/dppl_sycl_event_interface.cpp - source/dppl_sycl_kernel_interface.cpp - source/dppl_sycl_platform_interface.cpp - source/dppl_sycl_program_interface.cpp - source/dppl_sycl_queue_interface.cpp - source/dppl_sycl_queue_manager.cpp - source/dppl_sycl_usm_interface.cpp - source/dppl_utils.cpp - helper/source/dppl_utils_helper.cpp + source/dpctl_sycl_context_interface.cpp + source/dpctl_sycl_device_interface.cpp + source/dpctl_sycl_event_interface.cpp + source/dpctl_sycl_kernel_interface.cpp + source/dpctl_sycl_platform_interface.cpp + source/dpctl_sycl_program_interface.cpp + source/dpctl_sycl_queue_interface.cpp + source/dpctl_sycl_queue_manager.cpp + source/dpctl_sycl_usm_interface.cpp + source/dpctl_utils.cpp + helper/source/dpctl_utils_helper.cpp ) -# Install DPPLSyclInterface +# Install DPCTLSyclInterface target_include_directories( - DPPLSyclInterface + DPCTLSyclInterface PRIVATE ${CMAKE_SOURCE_DIR}/include/ ${CMAKE_SOURCE_DIR}/helper/include/ @@ -95,12 +95,12 @@ if(WIN32) ${DPCPP_ROOT}/include/sycl ) target_include_directories( - DPPLSyclInterface + DPCTLSyclInterface PUBLIC ${DPCPP_ROOT}/include/sycl ) target_link_libraries( - DPPLSyclInterface + DPCTLSyclInterface PRIVATE ${DPCPP_ROOT}/lib/sycl.lib PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib ) @@ -108,7 +108,7 @@ endif() install( TARGETS - DPPLSyclInterface + DPCTLSyclInterface LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/" ) diff --git a/backends/dbg_build.sh b/dpctl-capi/dbg_build.sh similarity index 100% rename from backends/dbg_build.sh rename to dpctl-capi/dbg_build.sh diff --git a/backends/helper/include/dppl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h similarity index 83% rename from backends/helper/include/dppl_utils_helper.h rename to dpctl-capi/helper/include/dpctl_utils_helper.h index 1ddd898696..de2a8d0490 100644 --- a/backends/helper/include/dppl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -1,4 +1,4 @@ -//===------------------- dppl_utils.h - dpctl-C_API ---*--- C++ -----*-----===// +//===------------------ dpctl_utils.h - dpctl-C_API ---*--- C++ -----*-----===// // // Data Parallel Control Library (dpCtl) // @@ -19,7 +19,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file defines common helper functions used in other places in DPPL. +/// This file defines common helper functions used in other places in DPCTL. //===----------------------------------------------------------------------===// #pragma once @@ -27,5 +27,5 @@ #include using namespace cl::sycl; -std::string DPPL_DeviceTypeToStr(info::device_type devTy); -info::device_type DPPL_StrToDeviceType(std::string devTyStr); +std::string DPCTL_DeviceTypeToStr(info::device_type devTy); +info::device_type DPCTL_StrToDeviceType(std::string devTyStr); diff --git a/backends/helper/source/dppl_utils_helper.cpp b/dpctl-capi/helper/source/dpctl_utils_helper.cpp similarity index 87% rename from backends/helper/source/dppl_utils_helper.cpp rename to dpctl-capi/helper/source/dpctl_utils_helper.cpp index 90991b2ccd..5303a28d30 100644 --- a/backends/helper/source/dppl_utils_helper.cpp +++ b/dpctl-capi/helper/source/dpctl_utils_helper.cpp @@ -1,4 +1,4 @@ -//===------ dppl_utils_helper.cpp - dpctl-C_API ----*---- C++ -----*-----===// +//===------ dpctl_utils_helper.cpp - dpctl-C_API ----*---- C++ -----*-----===// // // Data Parallel Control Library (dpCtl) // @@ -19,11 +19,11 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file implements the helper functions defined in dppl_utils_helper.h. +/// This file implements the helper functions defined in dpctl_utils_helper.h. /// //===----------------------------------------------------------------------===// -#include "dppl_utils_helper.h" +#include "dpctl_utils_helper.h" #include #include @@ -32,7 +32,7 @@ using namespace cl::sycl; /*! * Transforms enum info::device_type to string. */ -std::string DPPL_DeviceTypeToStr(info::device_type devTy) +std::string DPCTL_DeviceTypeToStr(info::device_type devTy) { std::stringstream ss; switch (devTy) @@ -61,7 +61,7 @@ std::string DPPL_DeviceTypeToStr(info::device_type devTy) /*! * Transforms string to enum info::device_type. */ -info::device_type DPPL_StrToDeviceType(std::string devTyStr) +info::device_type DPCTL_StrToDeviceType(std::string devTyStr) { info::device_type devTy; if (devTyStr == "cpu") { diff --git a/backends/include/Support/CBindingWrapping.h b/dpctl-capi/include/Support/CBindingWrapping.h similarity index 95% rename from backends/include/Support/CBindingWrapping.h rename to dpctl-capi/include/Support/CBindingWrapping.h index 16ed9b5293..601bb4ef02 100644 --- a/backends/include/Support/CBindingWrapping.h +++ b/dpctl-capi/include/Support/CBindingWrapping.h @@ -1,4 +1,4 @@ -//===----- Support/CBindingWrapping.h - DPPL-SYCL interface --*-- C ---*---===// +//===---- Support/CBindingWrapping.h - DPCTL-SYCL interface --*-- C ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -19,7 +19,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file declares the wrapping macros for the DPPL C interface. +/// This file declares the wrapping macros for the DPCTL C interface. /// //===----------------------------------------------------------------------===// diff --git a/backends/include/Support/DllExport.h b/dpctl-capi/include/Support/DllExport.h similarity index 81% rename from backends/include/Support/DllExport.h rename to dpctl-capi/include/Support/DllExport.h index de82311320..c396ea85aa 100644 --- a/backends/include/Support/DllExport.h +++ b/dpctl-capi/include/Support/DllExport.h @@ -1,4 +1,4 @@ -//===---------- Support/DllExport.h - DPPL-SYCL interface ---*--- C ---*---===// +//===--------- Support/DllExport.h - DPCTL-SYCL interface ---*--- C ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -26,11 +26,11 @@ #pragma once #ifdef _WIN32 -# ifdef DPPLSyclInterface_EXPORTS -# define DPPL_API __declspec(dllexport) +# ifdef DPCTLSyclInterface_EXPORTS +# define DPCTL_API __declspec(dllexport) # else -# define DPPL_API __declspec(dllimport) +# define DPCTL_API __declspec(dllimport) # endif #else -# define DPPL_API +# define DPCTL_API #endif diff --git a/backends/include/Support/ExternC.h b/dpctl-capi/include/Support/ExternC.h similarity index 82% rename from backends/include/Support/ExternC.h rename to dpctl-capi/include/Support/ExternC.h index 76baef7871..104bd2d010 100644 --- a/backends/include/Support/ExternC.h +++ b/dpctl-capi/include/Support/ExternC.h @@ -1,4 +1,4 @@ -//===------------ Support/ExternC.h - DPPL-SYCL interface ---*--- C ---*---===// +//===----------- Support/ExternC.h - DPCTL-SYCL interface ---*--- C ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -26,9 +26,9 @@ #pragma once #ifdef __cplusplus -#define DPPL_C_EXTERN_C_BEGIN extern "C" { -#define DPPL_C_EXTERN_C_END } +#define DPCTL_C_EXTERN_C_BEGIN extern "C" { +#define DPCTL_C_EXTERN_C_END } #else -#define DPPL_C_EXTERN_C_BEGIN -#define DPPL_C_EXTERN_C_END +#define DPCTL_C_EXTERN_C_BEGIN +#define DPCTL_C_EXTERN_C_END #endif diff --git a/backends/include/Support/MemOwnershipAttrs.h b/dpctl-capi/include/Support/MemOwnershipAttrs.h similarity index 62% rename from backends/include/Support/MemOwnershipAttrs.h rename to dpctl-capi/include/Support/MemOwnershipAttrs.h index f0579fdd46..478adb2f12 100644 --- a/backends/include/Support/MemOwnershipAttrs.h +++ b/dpctl-capi/include/Support/MemOwnershipAttrs.h @@ -1,4 +1,4 @@ -//===----- dppl_mem_ownership_attrs.h - DPPL-SYCL interface --*-- C++ --*--===// +//===--- dpctl_mem_ownership_attrs.h - DPCTL-SYCL interface --*-- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -22,7 +22,7 @@ /// This file defines a group of macros that serve as attributes indicating the /// type of ownership of a pointer. The macros are modeled after similar /// attributes defines in Integer Set Library (isl) and serve the purpose of -/// helping a programmer understand the semantics of a DPPL function. +/// helping a programmer understand the semantics of a DPCTL function. /// //===----------------------------------------------------------------------===// #pragma once @@ -34,52 +34,52 @@ */ /*! - * @def __dppl_give - * @brief The __dppl_give attribute indicates that a new object is returned and + * @def __dpctl_give + * @brief The __dpctl_give attribute indicates that a new object is returned and * the caller now owns the object. * - * The __dppl_give attribute informs a user that the function is allocating a + * The __dpctl_give attribute informs a user that the function is allocating a * new object and returning it to the user. The user now owns the object and to * free the object, he/she should make sure to use it exactly once as a value - * for a __dppl_take argument. However, the user is free to use the object as - * he/she likes as a value to __dppl_keep arguments. + * for a __dpctl_take argument. However, the user is free to use the object as + * he/she likes as a value to __dpctl_keep arguments. * */ -#ifndef __dppl_give -#define __dppl_give +#ifndef __dpctl_give +#define __dpctl_give #endif /*! - * @def __dppl_take - * @brief The __dppl_take attribute indicates that the function "takes" over the + * @def __dpctl_take + * @brief The __dpctl_take attribute indicates that the function "takes" over the * ownership of the object and the user must not use the object as an argument * to another function. * - * The __dppl_take attribute mens that the function destroys it before the + * The __dpctl_take attribute mens that the function destroys it before the * function returns, and the caller must not use the object again in any other - * function. If the pointer annotated with __dppl_take is NULL then it is + * function. If the pointer annotated with __dpctl_take is NULL then it is * treated as an error, since it may prevent the normal behavior of the * function. * */ -#ifndef __dppl_take -#define __dppl_take +#ifndef __dpctl_take +#define __dpctl_take #endif /*! - * @def __dppl_keep - * @brief The __dppl_keep attribute indicates that the function only uses the + * @def __dpctl_keep + * @brief The __dpctl_keep attribute indicates that the function only uses the * object and does not destroy it before returning. * */ -#ifndef __dppl_keep -#define __dppl_keep +#ifndef __dpctl_keep +#define __dpctl_keep #endif /*! - * @def __dppl_null - * @brief The __dppl_null attribute indicates that a NULL value is returned. + * @def __dpctl_null + * @brief The __dpctl_null attribute indicates that a NULL value is returned. * */ -#ifndef __dppl_null -#define __dppl_null +#ifndef __dpctl_null +#define __dpctl_null #endif /** @} */ diff --git a/backends/include/dppl_data_types.h b/dpctl-capi/include/dpctl_data_types.h similarity index 97% rename from backends/include/dppl_data_types.h rename to dpctl-capi/include/dpctl_data_types.h index 69691ebe09..9322e559dd 100644 --- a/backends/include/dppl_data_types.h +++ b/dpctl-capi/include/dpctl_data_types.h @@ -1,4 +1,4 @@ -//===------------------ dppl_data_types.h - dpctl-C_API ----*---- C ---*---===// +//===----------------- dpctl_data_types.h - dpctl-C_API ----*---- C ---*---===// // // Data Parallel Control Library (dpCtl) // diff --git a/backends/include/dppl_sycl_context_interface.h b/dpctl-capi/include/dpctl_sycl_context_interface.h similarity index 63% rename from backends/include/dppl_sycl_context_interface.h rename to dpctl-capi/include/dpctl_sycl_context_interface.h index bb0226225f..bc6be629b3 100644 --- a/backends/include/dppl_sycl_context_interface.h +++ b/dpctl-capi/include/dpctl_sycl_context_interface.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_context_interface.h - dpctl-C_API --*--C++ --*--===// +//===---------- dpctl_sycl_context_interface.h - dpctl-C_API --*--C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -25,27 +25,27 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" -#include "dppl_sycl_platform_interface.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" +#include "dpctl_sycl_platform_interface.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" #include -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! - * @brief Checks if two DPPLSyclContextRef objects point to the same + * @brief Checks if two DPCTLSyclContextRef objects point to the same * sycl::context. * * @param CtxRef1 First opaque pointer to the sycl context. * @param CtxRef2 Second opaque pointer to the sycl context. * @return True if the underlying sycl::context are same, false otherwise. */ -DPPL_API -bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, - __dppl_keep const DPPLSyclContextRef CtxRef2); +DPCTL_API +bool DPCTLContext_AreEq (__dpctl_keep const DPCTLSyclContextRef CtxRef1, + __dpctl_keep const DPCTLSyclContextRef CtxRef2); /*! * @brief Returns true if this SYCL context is a host context. @@ -53,26 +53,26 @@ bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, * @param CtxRef An opaque pointer to a sycl::context. * @return True if the SYCL context is a host context, else False. */ -DPPL_API -bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef); +DPCTL_API +bool DPCTLContext_IsHost (__dpctl_keep const DPCTLSyclContextRef CtxRef); /*! - * @brief Returns the sycl backend for the DPPLSyclContextRef pointer. + * @brief Returns the sycl backend for the DPCTLSyclContextRef pointer. * * @param CtxRef An opaque pointer to a sycl::context. - * @return The sycl backend for the DPPLSyclContextRef returned as - * a DPPLSyclBackendType enum type. + * @return The sycl backend for the DPCTLSyclContextRef returned as + * a DPCTLSyclBackendType enum type. */ -DPPL_API -DPPLSyclBackendType -DPPLContext_GetBackend (__dppl_keep const DPPLSyclContextRef CtxRef); +DPCTL_API +DPCTLSyclBackendType +DPCTLContext_GetBackend (__dpctl_keep const DPCTLSyclContextRef CtxRef); /*! * @brief Delete the pointer after casting it to sycl::context * - * @param CtxRef The DPPLSyclContextRef pointer to be deleted. + * @param CtxRef The DPCTLSyclContextRef pointer to be deleted. */ -DPPL_API -void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef); +DPCTL_API +void DPCTLContext_Delete (__dpctl_take DPCTLSyclContextRef CtxRef); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h similarity index 70% rename from backends/include/dppl_sycl_device_interface.h rename to dpctl-capi/include/dpctl_sycl_device_interface.h index 1a5a43ab84..3b647075f6 100644 --- a/backends/include/dppl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -1,4 +1,4 @@ -//===---------- dppl_sycl_device_interface.h - dpctl-C_API ---*---C++ -*---===// +//===--------- dpctl_sycl_device_interface.h - dpctl-C_API ---*---C++ -*---===// // // Data Parallel Control Library (dpCtl) // @@ -27,30 +27,30 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_enum_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_enum_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Prints out some of the info::deivice attributes for the device. * - * @param DRef A DPPLSyclDeviceRef pointer. + * @param DRef A DPCTLSyclDeviceRef pointer. */ -DPPL_API -void DPPLDevice_DumpInfo (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +void DPCTLDevice_DumpInfo (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! - * @brief Deletes a DPPLSyclDeviceRef pointer after casting to to sycl::device. + * @brief Deletes a DPCTLSyclDeviceRef pointer after casting to to sycl::device. * - * @param DRef The DPPLSyclDeviceRef pointer to be freed. + * @param DRef The DPCTLSyclDeviceRef pointer to be freed. */ -DPPL_API -void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef); +DPCTL_API +void DPCTLDevice_Delete (__dpctl_take DPCTLSyclDeviceRef DRef); /*! * @brief Returns true if this SYCL device is an OpenCL device and the device @@ -59,8 +59,8 @@ void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return True if the device type is an accelerator, else False. */ -DPPL_API -bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +bool DPCTLDevice_IsAccelerator (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns true if this SYCL device is an OpenCL device and the device @@ -69,8 +69,8 @@ bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return True if the device type is a cpu, else False. */ -DPPL_API -bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +bool DPCTLDevice_IsCPU (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns true if this SYCL device is an OpenCL device and the device @@ -79,8 +79,8 @@ bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return True if the device type is a gpu, else False. */ -DPPL_API -bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +bool DPCTLDevice_IsGPU (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns true if this SYCL device is a host device. @@ -88,8 +88,8 @@ bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return True if the device is a host device, else False. */ -DPPL_API -bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +bool DPCTLDevice_IsHost (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns the OpenCL software driver version as a C string. @@ -98,9 +98,9 @@ bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef); * @return A C string in the form major_number.minor.number that corresponds * to the OpenCL driver version if this is a OpenCL device. */ -DPPL_API -__dppl_give const char* -DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +__dpctl_give const char* +DPCTLDevice_GetDriverInfo (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper over device.get_info(). @@ -108,9 +108,9 @@ DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns the valid result if device exists else returns 0. */ -DPPL_API +DPCTL_API uint32_t -DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_GetMaxComputeUnits (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper for get_info(). @@ -118,9 +118,9 @@ DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns the valid result if device exists else returns 0. */ -DPPL_API +DPCTL_API uint32_t -DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_GetMaxWorkItemDims (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper for get_info(). @@ -128,9 +128,9 @@ DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns the valid result if device exists else returns NULL. */ -DPPL_API -__dppl_keep size_t* -DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +__dpctl_keep size_t* +DPCTLDevice_GetMaxWorkItemSizes (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper for get_info(). @@ -138,9 +138,9 @@ DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns the valid result if device exists else returns 0. */ -DPPL_API +DPCTL_API size_t -DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_GetMaxWorkGroupSize (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper over device.get_info. @@ -148,9 +148,9 @@ DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns the valid result if device exists else returns 0. */ -DPPL_API +DPCTL_API uint32_t -DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_GetMaxNumSubGroups (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper over device.get_info. @@ -158,9 +158,9 @@ DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns true if device has int64_base_atomics else returns false. */ -DPPL_API +DPCTL_API bool -DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_HasInt64BaseAtomics (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Wrapper over device.get_info. @@ -168,9 +168,9 @@ DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return Returns true if device has int64_extended_atomics else returns false. */ -DPPL_API +DPCTL_API bool -DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTLDevice_HasInt64ExtendedAtomics (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns a C string for the device name. @@ -178,9 +178,9 @@ DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return A C string containing the OpenCL device name. */ -DPPL_API -__dppl_give const char* -DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +__dpctl_give const char* +DPCTLDevice_GetName (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns a C string corresponding to the vendor name. @@ -188,9 +188,9 @@ DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef); * @param DRef Opaque pointer to a sycl::device * @return A C string containing the OpenCL device vendor name. */ -DPPL_API -__dppl_give const char* -DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +__dpctl_give const char* +DPCTLDevice_GetVendorName (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! * @brief Returns True if the device and the host share a unified memory @@ -200,18 +200,18 @@ DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef); * @return Boolean indicating if the device shares a unified memory subsystem * with the host. */ -DPPL_API -bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef); +DPCTL_API +bool DPCTLDevice_IsHostUnifiedMemory (__dpctl_keep const DPCTLSyclDeviceRef DRef); /*! - * @brief Checks if two DPPLSyclDeviceRef objects point to the same + * @brief Checks if two DPCTLSyclDeviceRef objects point to the same * sycl::device. * * @param DevRef1 First opaque pointer to the sycl device. * @param DevRef2 Second opaque pointer to the sycl device. * @return True if the underlying sycl::device are same, false otherwise. */ -DPPL_API -bool DPPLDevice_AreEq (__dppl_keep const DPPLSyclDeviceRef DevRef1, - __dppl_keep const DPPLSyclDeviceRef DevRef2); -DPPL_C_EXTERN_C_END +DPCTL_API +bool DPCTLDevice_AreEq (__dpctl_keep const DPCTLSyclDeviceRef DevRef1, + __dpctl_keep const DPCTLSyclDeviceRef DevRef2); +DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/include/dpctl_sycl_enum_types.h b/dpctl-capi/include/dpctl_sycl_enum_types.h new file mode 100644 index 0000000000..96edbabd9f --- /dev/null +++ b/dpctl-capi/include/dpctl_sycl_enum_types.h @@ -0,0 +1,91 @@ +//===- dpctl_sycl_enum_types.h - DPCTL-SYCL interface ---*---C++ -----*----===// +// +// Python Data Parallel Processing Library (PyDPCTL) +// +// Copyright 2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This header defines DPCTL specficif enum types that wrap corresponding Sycl +/// enum classes. These enums are defined primarily so that Python extensions +/// that use DPCTL do not have to include Sycl headers directly. +/// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "Support/ExternC.h" + +DPCTL_C_EXTERN_C_BEGIN + +/*! + * @brief Redefinition of DPC++-specific Sycl backend types. + * + */ +enum DPCTLSyclBackendType +{ + DPCTL_UNKNOWN_BACKEND = 0x0, + DPCTL_OPENCL = 1 << 16, + DPCTL_HOST = 1 << 15, + DPCTL_LEVEL_ZERO = 1 << 14, + DPCTL_CUDA = 1 << 13 +}; + +/*! + * @brief DPCTL device types that are equivalent to Sycl's device_type. + * + */ +enum DPCTLSyclDeviceType +{ + DPCTL_CPU = 1 << 0, + DPCTL_GPU = 1 << 1, + DPCTL_ACCELERATOR = 1 << 2, + DPCTL_CUSTOM = 1 << 3, + DPCTL_AUTOMATIC = 1 << 4, + DPCTL_HOST_DEVICE = 1 << 5, + DPCTL_ALL = 1 << 6 + // IMP: before adding new values here look at DPCTLSyclBackendType enum. The + // values should not overlap. +}; + +/*! + * @brief Supported types for kernel arguments to be passed to a Sycl kernel + * using DPCTL. + * + * \todo Add support for sycl::buffer + * + */ +typedef enum +{ + DPCTL_CHAR, + DPCTL_SIGNED_CHAR, + DPCTL_UNSIGNED_CHAR, + DPCTL_SHORT, + DPCTL_INT, + DPCTL_UNSIGNED_INT, + DPCTL_UNSIGNED_INT8, + DPCTL_LONG, + DPCTL_UNSIGNED_LONG, + DPCTL_LONG_LONG, + DPCTL_UNSIGNED_LONG_LONG, + DPCTL_SIZE_T, + DPCTL_FLOAT, + DPCTL_DOUBLE, + DPCTL_LONG_DOUBLE, + DPCTL_VOID_PTR +} DPCTLKernelArgType; + +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_event_interface.h b/dpctl-capi/include/dpctl_sycl_event_interface.h similarity index 68% rename from backends/include/dppl_sycl_event_interface.h rename to dpctl-capi/include/dpctl_sycl_event_interface.h index 98bc9dae08..754792da50 100644 --- a/backends/include/dppl_sycl_event_interface.h +++ b/dpctl-capi/include/dpctl_sycl_event_interface.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_event_interface.h - dpctl-C_API ---*---C++ -*---===// +//===---------- dpctl_sycl_event_interface.h - dpctl-C_API ---*---C++ -*---===// // // Data Parallel Control Library (dpCtl) // @@ -25,31 +25,31 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief C-API wrapper for sycl::event.wait. * - * @param ERef An opaque DPPLSyclEventRef pointer on which to wait. + * @param ERef An opaque DPCTLSyclEventRef pointer on which to wait. */ -DPPL_API -void DPPLEvent_Wait (__dppl_keep DPPLSyclEventRef ERef); +DPCTL_API +void DPCTLEvent_Wait (__dpctl_keep DPCTLSyclEventRef ERef); /*! - * @brief Deletes the DPPLSyclEventRef after casting it to a sycl::event. + * @brief Deletes the DPCTLSyclEventRef after casting it to a sycl::event. * - * @param ERef An opaque DPPLSyclEventRef pointer that would be + * @param ERef An opaque DPCTLSyclEventRef pointer that would be * freed. */ -DPPL_API +DPCTL_API void -DPPLEvent_Delete (__dppl_take DPPLSyclEventRef ERef); +DPCTLEvent_Delete (__dpctl_take DPCTLSyclEventRef ERef); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_kernel_interface.h b/dpctl-capi/include/dpctl_sycl_kernel_interface.h similarity index 71% rename from backends/include/dppl_sycl_kernel_interface.h rename to dpctl-capi/include/dpctl_sycl_kernel_interface.h index a48064cf83..f48244a049 100644 --- a/backends/include/dppl_sycl_kernel_interface.h +++ b/dpctl-capi/include/dpctl_sycl_kernel_interface.h @@ -1,4 +1,4 @@ -//===------------ dppl_sycl_kernel_interface.h - dpctl-C_API --*--C++ --*--===// +//===----------- dpctl_sycl_kernel_interface.h - dpctl-C_API --*--C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -29,46 +29,46 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Returns a C string for the kernel name. * - * @param KRef DPPLSyclKernelRef pointer to an OpenCL + * @param KRef DPCTLSyclKernelRef pointer to an OpenCL * interoperability kernel. * @return If a kernel name exists then returns it as a C string, else * returns a nullptr. */ -DPPL_API -__dppl_give const char* -DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef KRef); +DPCTL_API +__dpctl_give const char* +DPCTLKernel_GetFunctionName (__dpctl_keep const DPCTLSyclKernelRef KRef); /*! * @brief Returns the number of arguments for the OpenCL kernel. * - * @param KRef DPPLSyclKernelRef pointer to an OpenCL + * @param KRef DPCTLSyclKernelRef pointer to an OpenCL * interoperability kernel. * @return Returns the number of arguments for the OpenCL interoperability * kernel. */ -DPPL_API +DPCTL_API size_t -DPPLKernel_GetNumArgs (__dppl_keep const DPPLSyclKernelRef KRef); +DPCTLKernel_GetNumArgs (__dpctl_keep const DPCTLSyclKernelRef KRef); /*! - * @brief Deletes the DPPLSyclKernelRef after casting it to a sycl::kernel. + * @brief Deletes the DPCTLSyclKernelRef after casting it to a sycl::kernel. * - * @param KRef DPPLSyclKernelRef pointer to an OpenCL + * @param KRef DPCTLSyclKernelRef pointer to an OpenCL * interoperability kernel. */ -DPPL_API +DPCTL_API void -DPPLKernel_Delete (__dppl_take DPPLSyclKernelRef KRef); +DPCTLKernel_Delete (__dpctl_take DPCTLSyclKernelRef KRef); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_platform_interface.h b/dpctl-capi/include/dpctl_sycl_platform_interface.h similarity index 64% rename from backends/include/dppl_sycl_platform_interface.h rename to dpctl-capi/include/dpctl_sycl_platform_interface.h index b3df1b5c56..079c0c0ee7 100644 --- a/backends/include/dppl_sycl_platform_interface.h +++ b/dpctl-capi/include/dpctl_sycl_platform_interface.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_platform_interface.h - dpctl-C_API ---*--C++ -*-===// +//===---------- dpctl_sycl_platform_interface.h - dpctl-C_API ---*--C++ -*-===// // // Data Parallel Control Library (dpCtl) // @@ -25,13 +25,13 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_enum_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_enum_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Returns the number of non-host type sycl::platform available on the @@ -39,39 +39,39 @@ DPPL_C_EXTERN_C_BEGIN * * @return The number of available sycl::platforms. */ -DPPL_API -size_t DPPLPlatform_GetNumNonHostPlatforms (); +DPCTL_API +size_t DPCTLPlatform_GetNumNonHostPlatforms (); /*! * @brief Returns the number of unique non-host sycl backends on the system. * * @return The number of unique sycl backends. */ -DPPL_API -size_t DPPLPlatform_GetNumNonHostBackends (); +DPCTL_API +size_t DPCTLPlatform_GetNumNonHostBackends (); /*! - * @brief Returns an array of the unique non-host DPPLSyclBackendType values on + * @brief Returns an array of the unique non-host DPCTLSyclBackendType values on * the system. * - * @return An array of DPPLSyclBackendType enum values. + * @return An array of DPCTLSyclBackendType enum values. */ -DPPL_API -__dppl_give DPPLSyclBackendType* DPPLPlatform_GetListOfNonHostBackends (); +DPCTL_API +__dpctl_give DPCTLSyclBackendType* DPCTLPlatform_GetListOfNonHostBackends (); /*! - * @brief Frees an array of DPPLSyclBackendType enum values. + * @brief Frees an array of DPCTLSyclBackendType enum values. * - * @param BEArr An array of DPPLSyclBackendType enum values to be freed. + * @param BEArr An array of DPCTLSyclBackendType enum values to be freed. */ -DPPL_API -void DPPLPlatform_DeleteListOfBackends (__dppl_take DPPLSyclBackendType* BEArr); +DPCTL_API +void DPCTLPlatform_DeleteListOfBackends (__dpctl_take DPCTLSyclBackendType* BEArr); /*! * @brief Prints out some selected info about all sycl::platform on the system. * */ -DPPL_API -void DPPLPlatform_DumpInfo (); +DPCTL_API +void DPCTLPlatform_DumpInfo (); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_program_interface.h b/dpctl-capi/include/dpctl_sycl_program_interface.h similarity index 74% rename from backends/include/dppl_sycl_program_interface.h rename to dpctl-capi/include/dpctl_sycl_program_interface.h index 8e76ae4d80..febffdbc1e 100644 --- a/backends/include/dppl_sycl_program_interface.h +++ b/dpctl-capi/include/dpctl_sycl_program_interface.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_program_interface.h - dpctl-C_API --*--C++ --*--===// +//===---------- dpctl_sycl_program_interface.h - dpctl-C_API --*--C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -29,13 +29,13 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Create a Sycl program from an OpenCL SPIR-V binary file. @@ -56,11 +56,11 @@ DPPL_C_EXTERN_C_BEGIN * @return A new SyclProgramRef pointer if the program creation succeeded, * else returns NULL. */ -DPPL_API -__dppl_give DPPLSyclProgramRef -DPPLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef Ctx, - __dppl_keep const void *IL, - size_t Length); +DPCTL_API +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef Ctx, + __dpctl_keep const void *IL, + size_t Length); /*! * @brief Create a Sycl program from an OpenCL kernel source string. @@ -71,11 +71,11 @@ DPPLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef Ctx, * @return A new SyclProgramRef pointer if the program creation succeeded, * else returns NULL. */ -DPPL_API -__dppl_give DPPLSyclProgramRef -DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, - __dppl_keep const char *Source, - __dppl_keep const char *CompileOpts); +DPCTL_API +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx, + __dpctl_keep const char *Source, + __dpctl_keep const char *CompileOpts); /*! * @brief Returns the SyclKernel with given name from the program, if not found @@ -85,10 +85,10 @@ DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, * @param KernelName Name of kernel * @return A SyclKernel reference if the kernel exists, else NULL */ -DPPL_API -__dppl_give DPPLSyclKernelRef -DPPLProgram_GetKernel (__dppl_keep DPPLSyclProgramRef PRef, - __dppl_keep const char *KernelName); +DPCTL_API +__dpctl_give DPCTLSyclKernelRef +DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef, + __dpctl_keep const char *KernelName); /*! * @brief Return True if a SyclKernel with given name exists in the program, if @@ -98,18 +98,18 @@ DPPLProgram_GetKernel (__dppl_keep DPPLSyclProgramRef PRef, * @param KernelName Name of kernel * @return True if the kernel exists, else False */ -DPPL_API +DPCTL_API bool -DPPLProgram_HasKernel (__dppl_keep DPPLSyclProgramRef PRef, - __dppl_keep const char *KernelName); +DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef, + __dpctl_keep const char *KernelName); /*! - * @brief Frees the DPPLSyclProgramRef pointer. + * @brief Frees the DPCTLSyclProgramRef pointer. * * @param PRef Opaque pointer to a sycl::program */ -DPPL_API +DPCTL_API void -DPPLProgram_Delete (__dppl_take DPPLSyclProgramRef PRef); +DPCTLProgram_Delete (__dpctl_take DPCTLSyclProgramRef PRef); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_queue_interface.h b/dpctl-capi/include/dpctl_sycl_queue_interface.h similarity index 68% rename from backends/include/dppl_sycl_queue_interface.h rename to dpctl-capi/include/dpctl_sycl_queue_interface.h index 2272858181..ebca3eed23 100644 --- a/backends/include/dppl_sycl_queue_interface.h +++ b/dpctl-capi/include/dpctl_sycl_queue_interface.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_queue_interface.h - dpctl-C_API ---*---C++ -*---===// +//===---------- dpctl_sycl_queue_interface.h - dpctl-C_API ---*---C++ -*---===// // // Data Parallel Control Library (dpCtl) // @@ -21,69 +21,69 @@ /// \file /// This header declares a C interface to sycl::queue member functions. Note /// that sycl::queue constructors are not exposed in this interface. Instead, -/// users should use the functions in dppl_sycl_queue_manager.h. +/// users should use the functions in dpctl_sycl_queue_manager.h. /// //===----------------------------------------------------------------------===// #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_enum_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_enum_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Delete the pointer after casting it to sycl::queue. * - * @param QRef A DPPLSyclQueueRef pointer that gets deleted. + * @param QRef A DPCTLSyclQueueRef pointer that gets deleted. */ -DPPL_API -void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef); +DPCTL_API +void DPCTLQueue_Delete (__dpctl_take DPCTLSyclQueueRef QRef); /*! - * @brief Checks if two DPPLSyclQueueRef objects point to the same sycl::queue. + * @brief Checks if two DPCTLSyclQueueRef objects point to the same sycl::queue. * * @param QRef1 First opaque pointer to the sycl queue. * @param QRef2 Second opaque pointer to the sycl queue. * @return True if the underlying sycl::queue are same, false otherwise. */ -DPPL_API -bool DPPLQueue_AreEq (__dppl_keep const DPPLSyclQueueRef QRef1, - __dppl_keep const DPPLSyclQueueRef QRef2); +DPCTL_API +bool DPCTLQueue_AreEq (__dpctl_keep const DPCTLSyclQueueRef QRef1, + __dpctl_keep const DPCTLSyclQueueRef QRef2); /*! * @brief Returns the Sycl backend for the provided sycl::queue. * * @param QRef An opaque pointer to the sycl queue. - * @return A enum DPPLSyclBackendType corresponding to the backed for the + * @return A enum DPCTLSyclBackendType corresponding to the backed for the * queue. */ -DPPL_API -DPPLSyclBackendType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef); +DPCTL_API +DPCTLSyclBackendType DPCTLQueue_GetBackend (__dpctl_keep DPCTLSyclQueueRef QRef); /*! * @brief Returns the Sycl context for the queue. * * @param QRef An opaque pointer to the sycl queue. - * @return A DPPLSyclContextRef pointer to the sycl context for the queue. + * @return A DPCTLSyclContextRef pointer to the sycl context for the queue. */ -DPPL_API -__dppl_give DPPLSyclContextRef -DPPLQueue_GetContext (__dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclContextRef +DPCTLQueue_GetContext (__dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief returns the Sycl device for the queue. * * @param QRef An opaque pointer to the sycl queue. - * @return A DPPLSyclDeviceRef pointer to the sycl device for the queue. + * @return A DPCTLSyclDeviceRef pointer to the sycl device for the queue. */ -DPPL_API -__dppl_give DPPLSyclDeviceRef -DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclDeviceRef +DPCTLQueue_GetDevice (__dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Submits the kernel to the specified queue with the provided range @@ -102,31 +102,31 @@ DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef); * will be enqueued. * @param Args An array of void* pointers that represent the * kernel arguments for the kernel. - * @param ArgTypes An array of DPPLKernelArgType enum values that + * @param ArgTypes An array of DPCTLKernelArgType enum values that * represent the type of each kernel argument. * @param NArgs Size of Args and ArgTypes. * @param Range Defines the overall dimension of the dispatch for * the kernel. The array can have up to three * dimensions. * @param NRange Size of the gRange array. - * @param DepEvents List of dependent DPPLSyclEventRef objects (events) + * @param DepEvents List of dependent DPCTLSyclEventRef objects (events) * for the kernel. We call sycl::handler.depends_on for * each of the provided events. * @param NDepEvents Size of the DepEvents list. * @return An opaque pointer to the sycl::event returned by the * sycl::queue.submit() function. */ -DPPL_API -DPPLSyclEventRef -DPPLQueue_SubmitRange (__dppl_keep const DPPLSyclKernelRef KRef, - __dppl_keep const DPPLSyclQueueRef QRef, - __dppl_keep void **Args, - __dppl_keep const DPPLKernelArgType *ArgTypes, - size_t NArgs, - __dppl_keep const size_t Range[3], - size_t NRange, - __dppl_keep const DPPLSyclEventRef *DepEvents, - size_t NDepEvents); +DPCTL_API +DPCTLSyclEventRef +DPCTLQueue_SubmitRange (__dpctl_keep const DPCTLSyclKernelRef KRef, + __dpctl_keep const DPCTLSyclQueueRef QRef, + __dpctl_keep void **Args, + __dpctl_keep const DPCTLKernelArgType *ArgTypes, + size_t NArgs, + __dpctl_keep const size_t Range[3], + size_t NRange, + __dpctl_keep const DPCTLSyclEventRef *DepEvents, + size_t NDepEvents); /*! * @brief Submits the kernel to the specified queue with the provided nd_range @@ -145,7 +145,7 @@ DPPLQueue_SubmitRange (__dppl_keep const DPPLSyclKernelRef KRef, * will be enqueued. * @param Args An array of void* pointers that represent the * kernel arguments for the kernel. - * @param ArgTypes An array of DPPLKernelArgType enum values that + * @param ArgTypes An array of DPCTLKernelArgType enum values that * represent the type of each kernel argument. * @param NArgs Size of Args. * @param gRange Defines the overall dimension of the dispatch for @@ -156,25 +156,25 @@ DPPLQueue_SubmitRange (__dppl_keep const DPPLSyclKernelRef KRef, * three dimensions. * @param NDims The number of dimensions for both local and global * ranges. - * @param DepEvents List of dependent DPPLSyclEventRef objects (events) + * @param DepEvents List of dependent DPCTLSyclEventRef objects (events) * for the kernel. We call sycl::handler.depends_on for * each of the provided events. * @param NDepEvents Size of the DepEvents list. * @return An opaque pointer to the sycl::event returned by the * sycl::queue.submit() function. */ -DPPL_API -DPPLSyclEventRef -DPPLQueue_SubmitNDRange(__dppl_keep const DPPLSyclKernelRef KRef, - __dppl_keep const DPPLSyclQueueRef QRef, - __dppl_keep void **Args, - __dppl_keep const DPPLKernelArgType *ArgTypes, - size_t NArgs, - __dppl_keep const size_t gRange[3], - __dppl_keep const size_t lRange[3], - size_t NDims, - __dppl_keep const DPPLSyclEventRef *DepEvents, - size_t NDepEvents); +DPCTL_API +DPCTLSyclEventRef +DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, + __dpctl_keep const DPCTLSyclQueueRef QRef, + __dpctl_keep void **Args, + __dpctl_keep const DPCTLKernelArgType *ArgTypes, + size_t NArgs, + __dpctl_keep const size_t gRange[3], + __dpctl_keep const size_t lRange[3], + size_t NDims, + __dpctl_keep const DPCTLSyclEventRef *DepEvents, + size_t NDepEvents); /*! * @brief Calls the sycl::queue.submit function to do a blocking wait on all @@ -182,9 +182,9 @@ DPPLQueue_SubmitNDRange(__dppl_keep const DPPLSyclKernelRef KRef, * * @param QRef Opaque pointer to a sycl::queue. */ -DPPL_API +DPCTL_API void -DPPLQueue_Wait (__dppl_keep const DPPLSyclQueueRef QRef); +DPCTLQueue_Wait (__dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief C-API wrapper for sycl::queue::memcpy, the function waits on an event @@ -195,9 +195,9 @@ DPPLQueue_Wait (__dppl_keep const DPPLSyclQueueRef QRef); * @param Src An USM pointer to the source memory. * @param Count A number of bytes to copy. */ -DPPL_API -void DPPLQueue_Memcpy (__dppl_keep const DPPLSyclQueueRef QRef, - void *Dest, const void *Src, size_t Count); +DPCTL_API +void DPCTLQueue_Memcpy (__dpctl_keep const DPCTLSyclQueueRef QRef, + void *Dest, const void *Src, size_t Count); /*! * @brief C-API wrapper for sycl::queue::prefetch, the function waits on an event @@ -207,9 +207,9 @@ void DPPLQueue_Memcpy (__dppl_keep const DPPLSyclQueueRef QRef, * @param Ptr An USM pointer to memory. * @param Count A number of bytes to prefetch. */ -DPPL_API -void DPPLQueue_Prefetch (__dppl_keep DPPLSyclQueueRef QRef, - const void *Ptr, size_t Count); +DPCTL_API +void DPCTLQueue_Prefetch (__dpctl_keep DPCTLSyclQueueRef QRef, + const void *Ptr, size_t Count); /*! * @brief C-API wrapper for sycl::queue::mem_advise, the function waits on an event @@ -221,8 +221,8 @@ void DPPLQueue_Prefetch (__dppl_keep DPPLSyclQueueRef QRef, * @param Advice Device-defined advice for the specified allocation. * A value of 0 reverts the advice for Ptr to the default behavior. */ -DPPL_API -void DPPLQueue_MemAdvise (__dppl_keep DPPLSyclQueueRef QRef, - const void *Ptr, size_t Count, int Advice); +DPCTL_API +void DPCTLQueue_MemAdvise (__dpctl_keep DPCTLSyclQueueRef QRef, + const void *Ptr, size_t Count, int Advice); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_queue_manager.h b/dpctl-capi/include/dpctl_sycl_queue_manager.h similarity index 67% rename from backends/include/dppl_sycl_queue_manager.h rename to dpctl-capi/include/dpctl_sycl_queue_manager.h index 723f58855a..7121521974 100644 --- a/backends/include/dppl_sycl_queue_manager.h +++ b/dpctl-capi/include/dpctl_sycl_queue_manager.h @@ -1,4 +1,4 @@ -//===----------- dppl_sycl_queue_manager.h - dpctl-C_API ---*---C++ ---*---===// +//===---------- dpctl_sycl_queue_manager.h - dpctl-C_API ---*---C++ ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -19,7 +19,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This header declares a C interface to DPPL's sycl::queue manager to +/// This header declares a C interface to DPCTL's sycl::queue manager to /// maintain a thread local stack of sycl::queues objects for use inside /// Python programs. The C interface is designed in a way to not have to /// include the Sycl headers inside a Python extension module, since that would @@ -33,25 +33,25 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_device_interface.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_device_interface.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Get the sycl::queue object that is currently activated for this * thread. * * @return A copy of the current (top of the stack) sycl::queue is returned - * wrapped inside an opaque DPPLSyclQueueRef pointer. + * wrapped inside an opaque DPCTLSyclQueueRef pointer. */ -DPPL_API -__dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue (); +DPCTL_API +__dpctl_give DPCTLSyclQueueRef DPCTLQueueMgr_GetCurrentQueue (); /*! * @brief Get a sycl::queue object of the specified type and device id. @@ -61,14 +61,14 @@ __dppl_give DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue (); * @param DNum Device id for the device (defaults to 0) * * @return A copy of the sycl::queue corresponding to the device is returned - * wrapped inside a DPPLSyclDeviceType pointer. A runtime_error exception is + * wrapped inside a DPCTLSyclDeviceType pointer. A runtime_error exception is * raised if no such device exists. */ -DPPL_API -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, - size_t DNum); +DPCTL_API +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_GetQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, + size_t DNum); /*! * @brief Get the number of activated queues not including the global or @@ -76,8 +76,8 @@ DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy, * * @return The number of activated queues. */ -DPPL_API -size_t DPPLQueueMgr_GetNumActivatedQueues (); +DPCTL_API +size_t DPCTLQueueMgr_GetNumActivatedQueues (); /*! * @brief Get the number of available queues for given backend and device type @@ -87,9 +87,9 @@ size_t DPPLQueueMgr_GetNumActivatedQueues (); * @param DeviceTy Type of Sycl device. * @return The number of available queues. */ -DPPL_API -size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy); +DPCTL_API +size_t DPCTLQueueMgr_GetNumQueues (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy); /*! * @brief Returns True if the passed in queue and the current queue are the @@ -99,12 +99,12 @@ size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBackendType BETy, * @return True or False depending on whether the QRef argument is the same as * the currently activated queue. */ -DPPL_API -bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +bool DPCTLQueueMgr_IsCurrentQueue (__dpctl_keep const DPCTLSyclQueueRef QRef); /*! -* @brief Set the default DPPL queue to the sycl::queue for the given backend -* and device type combination and return a DPPLSyclQueueRef for that queue. +* @brief Set the default DPCTL queue to the sycl::queue for the given backend +* and device type combination and return a DPCTLSyclQueueRef for that queue. * If no queue was created Null is returned to caller. * * @param BETy Type of Sycl backend. @@ -113,51 +113,51 @@ bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef); * @return A copy of the sycl::queue that was set as the new default queue. If no * queue could be created then returns Null. */ -DPPL_API -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, - size_t DNum); +DPCTL_API +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_SetAsDefaultQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, + size_t DNum); /*! - * @brief Pushes a new sycl::queue object to the top of DPPL's thread-local + * @brief Pushes a new sycl::queue object to the top of DPCTL's thread-local * stack of a "activated" queues, and returns a copy of the queue to caller. * - * The DPPL queue manager maintains a thread-local stack of sycl::queue objects + * The DPCTL queue manager maintains a thread-local stack of sycl::queue objects * to facilitate nested parallelism. The sycl::queue at the top of the stack is * termed as the currently activated queue, and is always the one returned by - * DPPLQueueMgr_GetCurrentQueue(). DPPLPushSyclQueueToStack creates a new + * DPCTLQueueMgr_GetCurrentQueue(). DPCTLPushSyclQueueToStack creates a new * sycl::queue corresponding to the specified device and pushes it to the top * of the stack. A copy of the sycl::queue is returned to the caller wrapped - * inside the opaque DPPLSyclQueueRef pointer. A runtime_error exception is + * inside the opaque DPCTLSyclQueueRef pointer. A runtime_error exception is * thrown when a new sycl::queue could not be created for the specified device. * * @param BETy Type of Sycl backend. * @param DeviceTy The type of Sycl device (sycl_device_type) * @param DNum Device id for the device (defaults to 0) * - * @return A copy of the sycl::queue that was pushed to the top of DPPL's + * @return A copy of the sycl::queue that was pushed to the top of DPCTL's * stack of sycl::queue objects. Nullptr is returned if no such device exists. */ -DPPL_API -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_PushQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, - size_t DNum); +DPCTL_API +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_PushQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, + size_t DNum); /*! - * @brief Pops the top of stack element from DPPL's stack of activated + * @brief Pops the top of stack element from DPCTL's stack of activated * sycl::queue objects. * - * DPPLPopSyclQueue only removes the reference from the DPPL stack of + * DPCTLPopSyclQueue only removes the reference from the DPCTL stack of * sycl::queue objects. Any instance of the popped queue that were previously - * acquired by calling DPPLPushSyclQueue() or DPPLQueueMgr_GetCurrentQueue() + * acquired by calling DPCTLPushSyclQueue() or DPCTLQueueMgr_GetCurrentQueue() * needs to be freed separately. In addition, a runtime_error is thrown when * the stack contains only one sycl::queue, i.e., the default queue. * */ -DPPL_API -void DPPLQueueMgr_PopQueue (); +DPCTL_API +void DPCTLQueueMgr_PopQueue (); /*! @@ -166,7 +166,7 @@ void DPPLQueueMgr_PopQueue (); * * The instance is not placed into queue manager. The user assumes * ownership of the queue reference and should deallocate it using - * DPPLQueue_Delete. + * DPCTLQueue_Delete. * * @param CRef Sycl context reference * @param DRef Sycl device reference @@ -174,10 +174,10 @@ void DPPLQueueMgr_PopQueue (); * @return A copy of the sycl::queue created from given context and device * references. */ -DPPL_API -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_GetQueueFromContextAndDevice(__dppl_keep DPPLSyclContextRef CRef, - __dppl_keep DPPLSyclDeviceRef DRef); +DPCTL_API +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_GetQueueFromContextAndDevice(__dpctl_keep DPCTLSyclContextRef CRef, + __dpctl_keep DPCTLSyclDeviceRef DRef); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_types.h b/dpctl-capi/include/dpctl_sycl_types.h similarity index 65% rename from backends/include/dppl_sycl_types.h rename to dpctl-capi/include/dpctl_sycl_types.h index 74f2792f7a..83ffeef831 100644 --- a/backends/include/dppl_sycl_types.h +++ b/dpctl-capi/include/dpctl_sycl_types.h @@ -1,4 +1,4 @@ -//===-------------- dppl_sycl_types.h - dpctl-C_API ----*---- C++ ----*----===// +//===------------- dpctl_sycl_types.h - dpctl-C_API ----*---- C++ ----*----===// // // Data Parallel Control Library (dpCtl) // @@ -19,7 +19,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file defines types used by DPPL's C interface to SYCL. +/// This file defines types used by DPCTL's C interface to SYCL. /// //===----------------------------------------------------------------------===// @@ -27,56 +27,56 @@ #include "Support/ExternC.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Opaque pointer to a sycl::context * */ -typedef struct DPPLOpaqueSyclContext *DPPLSyclContextRef; +typedef struct DPCTLOpaqueSyclContext *DPCTLSyclContextRef; /*! * @brief Opaque pointer to a sycl::device * */ -typedef struct DPPLOpaqueSyclDevice *DPPLSyclDeviceRef; +typedef struct DPCTLOpaqueSyclDevice *DPCTLSyclDeviceRef; /*! * @brief Opaque pointer to a sycl::event * */ -typedef struct DPPLOpaqueSyclEvent *DPPLSyclEventRef; +typedef struct DPCTLOpaqueSyclEvent *DPCTLSyclEventRef; /*! * @brief Opaque pointer to a sycl::kernel * */ -typedef struct DPPLOpaqueSyclKernel *DPPLSyclKernelRef; +typedef struct DPCTLOpaqueSyclKernel *DPCTLSyclKernelRef; /*! * @brief Opaque pointer to a sycl::platform * */ -typedef struct DPPLOpaqueSyclPlatform *DPPLSyclPlatformRef; +typedef struct DPCTLOpaqueSyclPlatform *DPCTLSyclPlatformRef; /*! * @brief Opaque pointer to a sycl::program * */ -typedef struct DPPLOpaqueSyclProgram *DPPLSyclProgramRef; +typedef struct DPCTLOpaqueSyclProgram *DPCTLSyclProgramRef; /*! * @brief Opaque pointer to a sycl::queue * * @see sycl::queue */ -typedef struct DPPLOpaqueSyclQueue *DPPLSyclQueueRef; +typedef struct DPCTLOpaqueSyclQueue *DPCTLSyclQueueRef; /*! - * @brief Used to pass a sycl::usm memory opaquely through DPPL interfaces. + * @brief Used to pass a sycl::usm memory opaquely through DPCTL interfaces. * * @see sycl::usm */ -typedef struct DPPLOpaqueSyclUSM *DPPLSyclUSMRef; +typedef struct DPCTLOpaqueSyclUSM *DPCTLSyclUSMRef; -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_sycl_usm_interface.h b/dpctl-capi/include/dpctl_sycl_usm_interface.h similarity index 66% rename from backends/include/dppl_sycl_usm_interface.h rename to dpctl-capi/include/dpctl_sycl_usm_interface.h index 608a0da020..f7a8a7e404 100644 --- a/backends/include/dppl_sycl_usm_interface.h +++ b/dpctl-capi/include/dpctl_sycl_usm_interface.h @@ -1,4 +1,4 @@ -//===------------- dppl_sycl_usm_interface.h - dpctl-C_API ---*---C++ -*---===// +//===------------ dpctl_sycl_usm_interface.h - dpctl-C_API ---*---C++ -*---===// // // Data Parallel Control Library (dpCtl) // @@ -25,13 +25,13 @@ #pragma once -#include "dppl_data_types.h" -#include "dppl_sycl_types.h" +#include "dpctl_data_types.h" +#include "dpctl_sycl_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Create USM shared memory. @@ -41,9 +41,9 @@ DPPL_C_EXTERN_C_BEGIN * * @return The pointer to USM shared memory. On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLmalloc_shared (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_shared (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Create USM shared memory. @@ -55,10 +55,10 @@ DPPLmalloc_shared (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); * @return The pointer to USM shared memory with the requested alignment. * On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_shared (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_shared (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Create USM host memory. @@ -68,9 +68,9 @@ DPPLaligned_alloc_shared (size_t alignment, size_t size, * * @return The pointer to USM host memory. On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLmalloc_host (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_host (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Create USM host memory. @@ -82,10 +82,10 @@ DPPLmalloc_host (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); * @return The pointer to USM host memory with the requested alignment. * On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_host (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_host (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Create USM device memory. @@ -95,9 +95,9 @@ DPPLaligned_alloc_host (size_t alignment, size_t size, * * @return The pointer to USM device memory. On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLmalloc_device (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_device (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Create USM device memory. @@ -109,10 +109,10 @@ DPPLmalloc_device (size_t size, __dppl_keep const DPPLSyclQueueRef QRef); * @return The pointer to USM device memory with requested alignment. * On failure, returns nullptr. */ -DPPL_API -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_device (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_device (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Free USM memory. @@ -123,17 +123,17 @@ DPPLaligned_alloc_device (size_t alignment, size_t size, * USM pointer must have been allocated using the same context as the one * used to construct the queue. */ -DPPL_API -void DPPLfree_with_queue (__dppl_take DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclQueueRef QRef); +DPCTL_API +void DPCTLfree_with_queue (__dpctl_take DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief Free USM memory. * */ -DPPL_API -void DPPLfree_with_context (__dppl_take DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef); +DPCTL_API +void DPCTLfree_with_context (__dpctl_take DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef); /*! * @brief Get pointer type. @@ -143,10 +143,10 @@ void DPPLfree_with_context (__dppl_take DPPLSyclUSMRef MRef, * * @return "host", "device", "shared" or "unknown" */ -DPPL_API +DPCTL_API const char * -DPPLUSM_GetPointerType (__dppl_keep const DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef); +DPCTLUSM_GetPointerType (__dpctl_keep const DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef); /*! * @brief Get the device associated with USM pointer. @@ -154,10 +154,10 @@ DPPLUSM_GetPointerType (__dppl_keep const DPPLSyclUSMRef MRef, * @param MRef USM pointer * @param CRef Sycl context reference associated with the pointer * - * @return A DPPLSyclDeviceRef pointer to the sycl device. + * @return A DPCTLSyclDeviceRef pointer to the sycl device. */ -DPPL_API -DPPLSyclDeviceRef -DPPLUSM_GetPointerDevice (__dppl_keep const DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef); -DPPL_C_EXTERN_C_END +DPCTL_API +DPCTLSyclDeviceRef +DPCTLUSM_GetPointerDevice (__dpctl_keep const DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef); +DPCTL_C_EXTERN_C_END diff --git a/backends/include/dppl_utils.h b/dpctl-capi/include/dpctl_utils.h similarity index 81% rename from backends/include/dppl_utils.h rename to dpctl-capi/include/dpctl_utils.h index b0578173af..6510242c5a 100644 --- a/backends/include/dppl_utils.h +++ b/dpctl-capi/include/dpctl_utils.h @@ -1,4 +1,4 @@ -//===------------------- dppl_utils.h - dpctl-C_API ---*--- C++ -----*-----===// +//===------------------ dpctl_utils.h - dpctl-C_API ---*--- C++ -----*-----===// // // Data Parallel Control Library (dpCtl) // @@ -19,32 +19,32 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file defines common helper functions used in other places in DPPL. +/// This file defines common helper functions used in other places in DPCTL. //===----------------------------------------------------------------------===// #pragma once -#include "dppl_data_types.h" +#include "dpctl_data_types.h" #include "Support/DllExport.h" #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" -DPPL_C_EXTERN_C_BEGIN +DPCTL_C_EXTERN_C_BEGIN /*! * @brief Deletes the C String argument. * * @param str C string to be deleted */ -DPPL_API -void DPPLCString_Delete (__dppl_take const char* str); +DPCTL_API +void DPCTLCString_Delete (__dpctl_take const char* str); /*! * @brief Deletes an array of size_t elements. * * @param arr Array to be deleted. */ -DPPL_API -void DPPLSize_t_Array_Delete (__dppl_take size_t* arr); +DPCTL_API +void DPCTLSize_t_Array_Delete (__dpctl_take size_t* arr); -DPPL_C_EXTERN_C_END +DPCTL_C_EXTERN_C_END diff --git a/backends/source/dppl_sycl_context_interface.cpp b/dpctl-capi/source/dpctl_sycl_context_interface.cpp similarity index 68% rename from backends/source/dppl_sycl_context_interface.cpp rename to dpctl-capi/source/dpctl_sycl_context_interface.cpp index c160d72065..ef252ceb0f 100644 --- a/backends/source/dppl_sycl_context_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_context_interface.cpp @@ -1,4 +1,4 @@ -//===------- dppl_sycl_context_interface.cpp - dpctl-C_API ---*--- C++ -*-===// +//===------ dpctl_sycl_context_interface.cpp - dpctl-C_API ---*--- C++ -*-===// // // Data Parallel Control Library (dpCtl) // @@ -20,11 +20,11 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_context_interface.h. +/// dpctl_sycl_context_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_context_interface.h" +#include "dpctl_sycl_context_interface.h" #include "Support/CBindingWrapping.h" #include @@ -33,11 +33,11 @@ using namespace cl::sycl; namespace { // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) } /* end of anonymous namespace */ -bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, - __dppl_keep const DPPLSyclContextRef CtxRef2) +bool DPCTLContext_AreEq (__dpctl_keep const DPCTLSyclContextRef CtxRef1, + __dpctl_keep const DPCTLSyclContextRef CtxRef2) { if(!(CtxRef1 && CtxRef2)) // \todo handle error @@ -45,7 +45,7 @@ bool DPPLContext_AreEq (__dppl_keep const DPPLSyclContextRef CtxRef1, return (*unwrap(CtxRef1) == *unwrap(CtxRef2)); } -bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef) +bool DPCTLContext_IsHost (__dpctl_keep const DPCTLSyclContextRef CtxRef) { auto Ctx = unwrap(CtxRef); if (Ctx) { @@ -54,27 +54,27 @@ bool DPPLContext_IsHost (__dppl_keep const DPPLSyclContextRef CtxRef) return false; } -void DPPLContext_Delete (__dppl_take DPPLSyclContextRef CtxRef) +void DPCTLContext_Delete (__dpctl_take DPCTLSyclContextRef CtxRef) { delete unwrap(CtxRef); } -DPPLSyclBackendType -DPPLContext_GetBackend (__dppl_keep const DPPLSyclContextRef CtxRef) +DPCTLSyclBackendType +DPCTLContext_GetBackend (__dpctl_keep const DPCTLSyclContextRef CtxRef) { auto BE = unwrap(CtxRef)->get_platform().get_backend(); switch(BE) { case backend::host: - return DPPL_HOST; + return DPCTL_HOST; case backend::opencl: - return DPPL_OPENCL; + return DPCTL_OPENCL; case backend::level_zero: - return DPPL_LEVEL_ZERO; + return DPCTL_LEVEL_ZERO; case backend::cuda: - return DPPL_CUDA; + return DPCTL_CUDA; default: - return DPPL_UNKNOWN_BACKEND; + return DPCTL_UNKNOWN_BACKEND; } } diff --git a/backends/source/dppl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp similarity index 75% rename from backends/source/dppl_sycl_device_interface.cpp rename to dpctl-capi/source/dpctl_sycl_device_interface.cpp index 5d862e47ec..2d893f9d1f 100644 --- a/backends/source/dppl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -1,4 +1,4 @@ -//===------ dppl_sycl_device_interface.cpp - dpctl-C_API ---*--- C++ --*--===// +//===----- dpctl_sycl_device_interface.cpp - dpctl-C_API ---*--- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -20,24 +20,24 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_device_interface.h. +/// dpctl_sycl_device_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_device_interface.h" +#include "dpctl_sycl_device_interface.h" #include "Support/CBindingWrapping.h" #include #include #include #include /* SYCL headers */ -#include "../helper/include/dppl_utils_helper.h" +#include "../helper/include/dpctl_utils_helper.h" using namespace cl::sycl; namespace { // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPPLSyclDeviceRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) /*! * @brief Helper function to print the metadata for a sycl::device. @@ -59,7 +59,7 @@ void dump_device_info (const device & Device) ss << std::setw(4) << " " << std::left << std::setw(16) << "Device type"; auto devTy = Device.get_info(); - ss << DPPL_DeviceTypeToStr(devTy); + ss << DPCTL_DeviceTypeToStr(devTy); std::cout << ss.str(); } @@ -72,19 +72,19 @@ void dump_device_info (const device & Device) * vendor, and device profile are printed out. More attributed may be added * later. */ -void DPPLDevice_DumpInfo (__dppl_keep const DPPLSyclDeviceRef DRef) +void DPCTLDevice_DumpInfo (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto Device = unwrap(DRef); dump_device_info(*Device); } -void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef) +void DPCTLDevice_Delete (__dpctl_take DPCTLSyclDeviceRef DRef) { delete unwrap(DRef); } -bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef) +bool DPCTLDevice_IsAccelerator (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -93,7 +93,7 @@ bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef) return false; } -bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef) +bool DPCTLDevice_IsCPU (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -102,7 +102,7 @@ bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef) return false; } -bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef) +bool DPCTLDevice_IsGPU (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -112,7 +112,7 @@ bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef) } -bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef) +bool DPCTLDevice_IsHost (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -123,7 +123,7 @@ bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef) uint32_t -DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_GetMaxComputeUnits (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -133,7 +133,7 @@ DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef) } uint32_t -DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_GetMaxWorkItemDims (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -142,8 +142,8 @@ DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef) return 0; } -__dppl_keep size_t* -DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef) +__dpctl_keep size_t* +DPCTLDevice_GetMaxWorkItemSizes (__dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t *sizes = nullptr; auto D = unwrap(DRef); @@ -158,7 +158,7 @@ DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef) } size_t -DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_GetMaxWorkGroupSize (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -168,7 +168,7 @@ DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef) } uint32_t -DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_GetMaxNumSubGroups (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -178,7 +178,7 @@ DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef) } bool -DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_HasInt64BaseAtomics (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -188,7 +188,7 @@ DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef) } bool -DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef) +DPCTLDevice_HasInt64ExtendedAtomics (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -197,8 +197,8 @@ DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef) return false; } -__dppl_give const char* -DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef) +__dpctl_give const char* +DPCTLDevice_GetName (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -215,8 +215,8 @@ DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef) return nullptr; } -__dppl_give const char* -DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef) +__dpctl_give const char* +DPCTLDevice_GetVendorName (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -233,8 +233,8 @@ DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef) return nullptr; } -__dppl_give const char* -DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef) +__dpctl_give const char* +DPCTLDevice_GetDriverInfo (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -251,7 +251,7 @@ DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef) return nullptr; } -bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef) +bool DPCTLDevice_IsHostUnifiedMemory (__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { @@ -260,8 +260,8 @@ bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef) return false; } -bool DPPLDevice_AreEq(__dppl_keep const DPPLSyclDeviceRef DevRef1, - __dppl_keep const DPPLSyclDeviceRef DevRef2) +bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, + __dpctl_keep const DPCTLSyclDeviceRef DevRef2) { if(!(DevRef1 && DevRef2)) // \todo handle error diff --git a/backends/source/dppl_sycl_event_interface.cpp b/dpctl-capi/source/dpctl_sycl_event_interface.cpp similarity index 80% rename from backends/source/dppl_sycl_event_interface.cpp rename to dpctl-capi/source/dpctl_sycl_event_interface.cpp index ae8356adba..e244391730 100644 --- a/backends/source/dppl_sycl_event_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_event_interface.cpp @@ -1,4 +1,4 @@ -//===------ dppl_sycl_event_interface.cpp - dpctl-C_API ---*--- C++ --*---===// +//===----- dpctl_sycl_event_interface.cpp - dpctl-C_API ---*--- C++ --*---===// // // Data Parallel Control Library (dpCtl) // @@ -20,11 +20,11 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_event_interface.h. +/// dpctl_sycl_event_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_event_interface.h" +#include "dpctl_sycl_event_interface.h" #include "Support/CBindingWrapping.h" #include /* SYCL headers */ @@ -34,11 +34,11 @@ using namespace cl::sycl; namespace { // Create wrappers for C Binding types (see CBindingWrapping.h) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPPLSyclEventRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef) } /* end of anonymous namespace */ -void DPPLEvent_Wait (__dppl_keep DPPLSyclEventRef ERef) +void DPCTLEvent_Wait (__dpctl_keep DPCTLSyclEventRef ERef) { // \todo How to handle errors? E.g. when ERef is null or not a valid event. auto SyclEvent = unwrap(ERef); @@ -46,7 +46,7 @@ void DPPLEvent_Wait (__dppl_keep DPPLSyclEventRef ERef) } void -DPPLEvent_Delete (__dppl_take DPPLSyclEventRef ERef) +DPCTLEvent_Delete (__dpctl_take DPCTLSyclEventRef ERef) { delete unwrap(ERef); } diff --git a/backends/source/dppl_sycl_kernel_interface.cpp b/dpctl-capi/source/dpctl_sycl_kernel_interface.cpp similarity index 80% rename from backends/source/dppl_sycl_kernel_interface.cpp rename to dpctl-capi/source/dpctl_sycl_kernel_interface.cpp index 152cf59197..b4996c6b1d 100644 --- a/backends/source/dppl_sycl_kernel_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_kernel_interface.cpp @@ -1,4 +1,4 @@ -//===------ dppl_sycl_kernel_interface.cpp - dpctl-C_API ---*--- C++ --*--===// +//===----- dpctl_sycl_kernel_interface.cpp - dpctl-C_API ---*--- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -20,11 +20,11 @@ /// /// \file /// This file implements the functions declared in -/// dppl_sycl_kernel_interface.h. +/// dpctl_sycl_kernel_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_kernel_interface.h" +#include "dpctl_sycl_kernel_interface.h" #include "Support/CBindingWrapping.h" #include /* Sycl headers */ @@ -34,12 +34,12 @@ using namespace cl::sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPPLSyclKernelRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) } /* end of anonymous namespace */ -__dppl_give const char* -DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef Kernel) +__dpctl_give const char* +DPCTLKernel_GetFunctionName (__dpctl_keep const DPCTLSyclKernelRef Kernel) { if(!Kernel) { // \todo record error @@ -61,7 +61,7 @@ DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef Kernel) } size_t -DPPLKernel_GetNumArgs (__dppl_keep const DPPLSyclKernelRef Kernel) +DPCTLKernel_GetNumArgs (__dpctl_keep const DPCTLSyclKernelRef Kernel) { if(!Kernel) { // \todo record error @@ -74,7 +74,7 @@ DPPLKernel_GetNumArgs (__dppl_keep const DPPLSyclKernelRef Kernel) } void -DPPLKernel_Delete (__dppl_take DPPLSyclKernelRef Kernel) +DPCTLKernel_Delete (__dpctl_take DPCTLSyclKernelRef Kernel) { delete unwrap(Kernel); } diff --git a/backends/source/dppl_sycl_platform_interface.cpp b/dpctl-capi/source/dpctl_sycl_platform_interface.cpp similarity index 84% rename from backends/source/dppl_sycl_platform_interface.cpp rename to dpctl-capi/source/dpctl_sycl_platform_interface.cpp index d9b53205fb..d646670f66 100644 --- a/backends/source/dppl_sycl_platform_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_platform_interface.cpp @@ -1,4 +1,4 @@ -//===------ dppl_sycl_platform_interface.cpp - dpctl-C_API --*-- C++ --*--===// +//===----- dpctl_sycl_platform_interface.cpp - dpctl-C_API --*-- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -20,16 +20,16 @@ /// /// \file /// This file implements the functions declared in -/// dppl_sycl_platform_interface.h. +/// dpctl_sycl_platform_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_platform_interface.h" +#include "dpctl_sycl_platform_interface.h" #include #include #include #include -#include "../helper/include/dppl_utils_helper.h" +#include "../helper/include/dpctl_utils_helper.h" #include @@ -37,10 +37,10 @@ using namespace cl::sycl; namespace { -std::set +std::set get_set_of_non_hostbackends () { - std::set be_set; + std::set be_set; for (auto p : platform::get_platforms()) { if(p.is_host()) continue; @@ -50,13 +50,13 @@ get_set_of_non_hostbackends () case backend::host: break; case backend::cuda: - be_set.insert(DPPLSyclBackendType::DPPL_CUDA); + be_set.insert(DPCTLSyclBackendType::DPCTL_CUDA); break; case backend::level_zero: - be_set.insert(DPPLSyclBackendType::DPPL_LEVEL_ZERO); + be_set.insert(DPCTLSyclBackendType::DPCTL_LEVEL_ZERO); break; case backend::opencl: - be_set.insert(DPPLSyclBackendType::DPPL_OPENCL); + be_set.insert(DPCTLSyclBackendType::DPCTL_OPENCL); break; default: break; @@ -82,7 +82,7 @@ get_set_of_non_hostbackends () * - info::device::driver_version * - type of the device based on the aspects cpu, gpu, accelerator. */ -void DPPLPlatform_DumpInfo () +void DPCTLPlatform_DumpInfo () { size_t i = 0; @@ -125,7 +125,7 @@ void DPPLPlatform_DumpInfo () << "Device type"; auto devTy = devices[dn].get_info(); - ss << DPPL_DeviceTypeToStr(devTy); + ss << DPCTL_DeviceTypeToStr(devTy); } std::cout << ss.str(); ++i; @@ -135,7 +135,7 @@ void DPPLPlatform_DumpInfo () /*! * Returns the number of sycl::platform on the system. */ -size_t DPPLPlatform_GetNumNonHostPlatforms () +size_t DPCTLPlatform_GetNumNonHostPlatforms () { auto nNonHostPlatforms = 0ul; for (auto &p : platform::get_platforms()) { @@ -146,7 +146,7 @@ size_t DPPLPlatform_GetNumNonHostPlatforms () return nNonHostPlatforms; } -size_t DPPLPlatform_GetNumNonHostBackends () +size_t DPCTLPlatform_GetNumNonHostBackends () { auto be_set = get_set_of_non_hostbackends(); @@ -156,14 +156,14 @@ size_t DPPLPlatform_GetNumNonHostBackends () return be_set.size(); } -__dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends () +__dpctl_give DPCTLSyclBackendType *DPCTLPlatform_GetListOfNonHostBackends () { auto be_set = get_set_of_non_hostbackends(); if (be_set.empty()) return nullptr; - DPPLSyclBackendType *BEArr = new DPPLSyclBackendType[be_set.size()]; + DPCTLSyclBackendType *BEArr = new DPCTLSyclBackendType[be_set.size()]; auto i = 0ul; for (auto be : be_set) { @@ -174,7 +174,7 @@ __dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends () return BEArr; } -void DPPLPlatform_DeleteListOfBackends (__dppl_take DPPLSyclBackendType *BEArr) +void DPCTLPlatform_DeleteListOfBackends (__dpctl_take DPCTLSyclBackendType *BEArr) { delete[] BEArr; } diff --git a/backends/source/dppl_sycl_program_interface.cpp b/dpctl-capi/source/dpctl_sycl_program_interface.cpp similarity index 79% rename from backends/source/dppl_sycl_program_interface.cpp rename to dpctl-capi/source/dpctl_sycl_program_interface.cpp index e076d4080e..d7dae83e0f 100644 --- a/backends/source/dppl_sycl_program_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_program_interface.cpp @@ -1,4 +1,4 @@ -//===----- dppl_sycl_program_interface.cpp - dpctl-C_API ---*--- C++ --*--===// +//===---- dpctl_sycl_program_interface.cpp - dpctl-C_API ---*--- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -20,11 +20,11 @@ /// /// \file /// This file implements the functions declared in -/// dppl_sycl_program_interface.h. +/// dpctl_sycl_program_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_program_interface.h" +#include "dpctl_sycl_program_interface.h" #include "Support/CBindingWrapping.h" #include /* Sycl headers */ @@ -34,15 +34,15 @@ using namespace cl::sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(program, DPPLSyclProgramRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPPLSyclKernelRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(program, DPCTLSyclProgramRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) } /* end of anonymous namespace */ -__dppl_give DPPLSyclProgramRef -DPPLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef CtxRef, - __dppl_keep const void *IL, +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef, + __dpctl_keep const void *IL, size_t length) { cl_int err; @@ -91,10 +91,10 @@ DPPLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef CtxRef, } } -__dppl_give DPPLSyclProgramRef -DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, - __dppl_keep const char *Source, - __dppl_keep const char *CompileOpts) +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx, + __dpctl_keep const char *Source, + __dpctl_keep const char *CompileOpts) { std::string compileOpts; context *SyclCtx = nullptr; @@ -132,9 +132,9 @@ DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, } } -__dppl_give DPPLSyclKernelRef -DPPLProgram_GetKernel (__dppl_keep DPPLSyclProgramRef PRef, - __dppl_keep const char *KernelName) +__dpctl_give DPCTLSyclKernelRef +DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef, + __dpctl_keep const char *KernelName) { if(!PRef) { // \todo record error @@ -156,8 +156,8 @@ DPPLProgram_GetKernel (__dppl_keep DPPLSyclProgramRef PRef, } bool -DPPLProgram_HasKernel (__dppl_keep DPPLSyclProgramRef PRef, - __dppl_keep const char *KernelName) +DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef, + __dpctl_keep const char *KernelName) { if(!PRef) { // \todo handle error @@ -173,7 +173,7 @@ DPPLProgram_HasKernel (__dppl_keep DPPLSyclProgramRef PRef, } void -DPPLProgram_Delete (__dppl_take DPPLSyclProgramRef PRef) +DPCTLProgram_Delete (__dpctl_take DPCTLSyclProgramRef PRef) { delete unwrap(PRef); } diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/dpctl-capi/source/dpctl_sycl_queue_interface.cpp similarity index 72% rename from backends/source/dppl_sycl_queue_interface.cpp rename to dpctl-capi/source/dpctl_sycl_queue_interface.cpp index 7e66b9eb8b..bd71ec116c 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_queue_interface.cpp @@ -1,4 +1,4 @@ -//===------ dppl_sycl_queue_interface.cpp - dpctl-C_API ---*--- C++ --*---===// +//===----- dpctl_sycl_queue_interface.cpp - dpctl-C_API ---*--- C++ --*---===// // // Data Parallel Control Library (dpCtl) // @@ -20,12 +20,12 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_queue_interface.h. +/// dpctl_sycl_queue_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_context_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_context_interface.h" #include "Support/CBindingWrapping.h" #include #include @@ -37,11 +37,11 @@ using namespace cl::sycl; namespace { // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPPLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPPLSyclEventRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPPLSyclKernelRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPPLSyclQueueRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) /*! * @brief Set the kernel arg object @@ -49,59 +49,59 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPPLSyclQueueRef) * @param cgh My Param doc * @param Arg My Param doc */ -bool set_kernel_arg (handler &cgh, size_t idx, __dppl_keep void *Arg, - DPPLKernelArgType ArgTy) +bool set_kernel_arg (handler &cgh, size_t idx, __dpctl_keep void *Arg, + DPCTLKernelArgType ArgTy) { bool arg_set = true; switch (ArgTy) { - case DPPL_CHAR: + case DPCTL_CHAR: cgh.set_arg(idx, *(char*)Arg); break; - case DPPL_SIGNED_CHAR: + case DPCTL_SIGNED_CHAR: cgh.set_arg(idx, *(signed char*)Arg); break; - case DPPL_UNSIGNED_CHAR: + case DPCTL_UNSIGNED_CHAR: cgh.set_arg(idx, *(unsigned char*)Arg); break; - case DPPL_SHORT: + case DPCTL_SHORT: cgh.set_arg(idx, *(short*)Arg); break; - case DPPL_INT: + case DPCTL_INT: cgh.set_arg(idx, *(int*)Arg); break; - case DPPL_UNSIGNED_INT: + case DPCTL_UNSIGNED_INT: cgh.set_arg(idx, *(unsigned int*)Arg); break; - case DPPL_UNSIGNED_INT8: + case DPCTL_UNSIGNED_INT8: cgh.set_arg(idx, *(uint8_t*)Arg); break; - case DPPL_LONG: + case DPCTL_LONG: cgh.set_arg(idx, *(long*)Arg); break; - case DPPL_UNSIGNED_LONG: + case DPCTL_UNSIGNED_LONG: cgh.set_arg(idx, *(unsigned long*)Arg); break; - case DPPL_LONG_LONG: + case DPCTL_LONG_LONG: cgh.set_arg(idx, *(long long*)Arg); break; - case DPPL_UNSIGNED_LONG_LONG: + case DPCTL_UNSIGNED_LONG_LONG: cgh.set_arg(idx, *(unsigned long long*)Arg); break; - case DPPL_SIZE_T: + case DPCTL_SIZE_T: cgh.set_arg(idx, *(size_t*)Arg); break; - case DPPL_FLOAT: + case DPCTL_FLOAT: cgh.set_arg(idx, *(float*)Arg); break; - case DPPL_DOUBLE: + case DPCTL_DOUBLE: cgh.set_arg(idx, *(double*)Arg); break; - case DPPL_LONG_DOUBLE: + case DPCTL_LONG_DOUBLE: cgh.set_arg(idx, *(long double*)Arg); break; - case DPPL_VOID_PTR: + case DPCTL_VOID_PTR: cgh.set_arg(idx, Arg); break; default: @@ -118,14 +118,14 @@ bool set_kernel_arg (handler &cgh, size_t idx, __dppl_keep void *Arg, /*! * Delete the passed in pointer after verifying it points to a sycl::queue. */ -void DPPLQueue_Delete (__dppl_take DPPLSyclQueueRef QRef) +void DPCTLQueue_Delete (__dpctl_take DPCTLSyclQueueRef QRef) { delete unwrap(QRef); } -bool DPPLQueue_AreEq (__dppl_keep const DPPLSyclQueueRef QRef1, - __dppl_keep const DPPLSyclQueueRef QRef2) +bool DPCTLQueue_AreEq (__dpctl_keep const DPCTLSyclQueueRef QRef1, + __dpctl_keep const DPCTLSyclQueueRef QRef2) { if(!(QRef1 && QRef2)) // \todo handle error @@ -133,45 +133,45 @@ bool DPPLQueue_AreEq (__dppl_keep const DPPLSyclQueueRef QRef1, return (*unwrap(QRef1) == *unwrap(QRef2)); } -DPPLSyclBackendType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef) +DPCTLSyclBackendType DPCTLQueue_GetBackend (__dpctl_keep DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); try { auto C = Q->get_context(); - return DPPLContext_GetBackend(wrap(&C)); + return DPCTLContext_GetBackend(wrap(&C)); } catch (runtime_error &re) { std::cerr << re.what() << '\n'; // store error message - return DPPL_UNKNOWN_BACKEND; + return DPCTL_UNKNOWN_BACKEND; } } -__dppl_give DPPLSyclDeviceRef -DPPLQueue_GetDevice (__dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclDeviceRef +DPCTLQueue_GetDevice (__dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Device = new device(Q->get_device()); return wrap(Device); } -__dppl_give DPPLSyclContextRef -DPPLQueue_GetContext (__dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclContextRef +DPCTLQueue_GetContext (__dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Context = new context(Q->get_context()); return wrap(Context); } -__dppl_give DPPLSyclEventRef -DPPLQueue_SubmitRange (__dppl_keep const DPPLSyclKernelRef KRef, - __dppl_keep const DPPLSyclQueueRef QRef, - __dppl_keep void **Args, - __dppl_keep const DPPLKernelArgType *ArgTypes, +__dpctl_give DPCTLSyclEventRef +DPCTLQueue_SubmitRange (__dpctl_keep const DPCTLSyclKernelRef KRef, + __dpctl_keep const DPCTLSyclQueueRef QRef, + __dpctl_keep void **Args, + __dpctl_keep const DPCTLKernelArgType *ArgTypes, size_t NArgs, - __dppl_keep const size_t Range[3], + __dpctl_keep const size_t Range[3], size_t NDims, - __dppl_keep const DPPLSyclEventRef *DepEvents, + __dpctl_keep const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) { auto Kernel = unwrap(KRef); @@ -221,16 +221,16 @@ DPPLQueue_SubmitRange (__dppl_keep const DPPLSyclKernelRef KRef, return wrap(new event(e)); } -DPPLSyclEventRef -DPPLQueue_SubmitNDRange(__dppl_keep const DPPLSyclKernelRef KRef, - __dppl_keep const DPPLSyclQueueRef QRef, - __dppl_keep void **Args, - __dppl_keep const DPPLKernelArgType *ArgTypes, +DPCTLSyclEventRef +DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, + __dpctl_keep const DPCTLSyclQueueRef QRef, + __dpctl_keep void **Args, + __dpctl_keep const DPCTLKernelArgType *ArgTypes, size_t NArgs, - __dppl_keep const size_t gRange[3], - __dppl_keep const size_t lRange[3], + __dpctl_keep const size_t gRange[3], + __dpctl_keep const size_t lRange[3], size_t NDims, - __dppl_keep const DPPLSyclEventRef *DepEvents, + __dpctl_keep const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) { auto Kernel = unwrap(KRef); @@ -283,14 +283,14 @@ DPPLQueue_SubmitNDRange(__dppl_keep const DPPLSyclKernelRef KRef, } void -DPPLQueue_Wait (__dppl_keep DPPLSyclQueueRef QRef) +DPCTLQueue_Wait (__dpctl_keep DPCTLSyclQueueRef QRef) { // \todo what happens if the QRef is null or a pointer to a valid sycl queue auto SyclQueue = unwrap(QRef); SyclQueue->wait(); } -void DPPLQueue_Memcpy (__dppl_keep const DPPLSyclQueueRef QRef, +void DPCTLQueue_Memcpy (__dpctl_keep const DPCTLSyclQueueRef QRef, void *Dest, const void *Src, size_t Count) { auto Q = unwrap(QRef); @@ -299,7 +299,7 @@ void DPPLQueue_Memcpy (__dppl_keep const DPPLSyclQueueRef QRef, } void -DPPLQueue_Prefetch (__dppl_keep DPPLSyclQueueRef QRef, +DPCTLQueue_Prefetch (__dpctl_keep DPCTLSyclQueueRef QRef, const void *Ptr, size_t Count) { auto Q = unwrap(QRef); @@ -308,7 +308,7 @@ DPPLQueue_Prefetch (__dppl_keep DPPLSyclQueueRef QRef, } void -DPPLQueue_MemAdvise (__dppl_keep DPPLSyclQueueRef QRef, +DPCTLQueue_MemAdvise (__dpctl_keep DPCTLSyclQueueRef QRef, const void *Ptr, size_t Count, int Advice) { auto Q = unwrap(QRef); diff --git a/backends/source/dppl_sycl_queue_manager.cpp b/dpctl-capi/source/dpctl_sycl_queue_manager.cpp similarity index 78% rename from backends/source/dppl_sycl_queue_manager.cpp rename to dpctl-capi/source/dpctl_sycl_queue_manager.cpp index 7a7689a392..80653f454d 100644 --- a/backends/source/dppl_sycl_queue_manager.cpp +++ b/dpctl-capi/source/dpctl_sycl_queue_manager.cpp @@ -1,4 +1,4 @@ -//===--------- dppl_sycl_queue_manager.cpp - dpctl-C_API --*-- C++ ---*---===// +//===-------- dpctl_sycl_queue_manager.cpp - dpctl-C_API --*-- C++ ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -20,10 +20,10 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_queue_manager.h. +/// dpctl_sycl_queue_manager.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_queue_manager.h" +#include "dpctl_sycl_queue_manager.h" #include "Support/CBindingWrapping.h" #include #include @@ -39,15 +39,15 @@ namespace { // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPPLSyclQueueRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPPLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) /*! - * @brief A helper class to support the DPPLSyclQueuemanager. + * @brief A helper class to support the DPCTLSyclQueuemanager. * * The QMgrHelper is needed so that sycl headers are not exposed at the - * top-level DPPL API. + * top-level DPCTL API. * */ class QMgrHelper @@ -154,24 +154,24 @@ class QMgrHelper return *active_queues; } - static __dppl_give DPPLSyclQueueRef - getQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, + static __dpctl_give DPCTLSyclQueueRef + getQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum); - static __dppl_give DPPLSyclQueueRef + static __dpctl_give DPCTLSyclQueueRef getCurrentQueue (); - static bool isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef); + static bool isCurrentQueue (__dpctl_keep const DPCTLSyclQueueRef QRef); - static __dppl_give DPPLSyclQueueRef - setAsDefaultQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, + static __dpctl_give DPCTLSyclQueueRef + setAsDefaultQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum); - static __dppl_give DPPLSyclQueueRef - pushSyclQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, + static __dpctl_give DPCTLSyclQueueRef + pushSyclQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum); static void @@ -182,10 +182,10 @@ class QMgrHelper /*! * Allocates a new copy of the present top of stack queue, which can be the * default queue and returns to caller. The caller owns the pointer and is - * responsible for deallocating it. The helper function DPPLQueue_Delete should + * responsible for deallocating it. The helper function DPCTLQueue_Delete should * be used for that purpose. */ -DPPLSyclQueueRef QMgrHelper::getCurrentQueue () +DPCTLSyclQueueRef QMgrHelper::getCurrentQueue () { auto &activated_q = get_active_queues(); if(activated_q.empty()) { @@ -200,19 +200,19 @@ DPPLSyclQueueRef QMgrHelper::getCurrentQueue () /*! * Allocates a sycl::queue by copying from the cached {cpu|gpu}_queues vector * and returns it to the caller. The caller owns the pointer and is responsible - * for deallocating it. The helper function DPPLQueue_Delete should + * for deallocating it. The helper function DPCTLQueue_Delete should * be used for that purpose. */ -__dppl_give DPPLSyclQueueRef -QMgrHelper::getQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +__dpctl_give DPCTLSyclQueueRef +QMgrHelper::getQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { queue *QRef = nullptr; switch (BETy|DeviceTy) { - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_CPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_CPU: { auto cpuQs = get_opencl_cpu_queues(); if (DNum >= cpuQs.size()) { @@ -224,7 +224,7 @@ QMgrHelper::getQueue (DPPLSyclBackendType BETy, QRef = new queue(cpuQs[DNum]); break; } - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_GPU: { auto gpuQs = get_opencl_gpu_queues(); if (DNum >= gpuQs.size()) { @@ -236,7 +236,7 @@ QMgrHelper::getQueue (DPPLSyclBackendType BETy, QRef = new queue(gpuQs[DNum]); break; } - case DPPLSyclBackendType::DPPL_LEVEL_ZERO | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO | DPCTLSyclDeviceType::DPCTL_GPU: { auto l0GpuQs = get_level0_gpu_queues(); if (DNum >= l0GpuQs.size()) { @@ -261,7 +261,7 @@ QMgrHelper::getQueue (DPPLSyclBackendType BETy, * device of the queue passed as input. Return true if both queues have the * same context and device. */ -bool QMgrHelper::isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef) +bool QMgrHelper::isCurrentQueue (__dpctl_keep const DPCTLSyclQueueRef QRef) { auto &activated_q = get_active_queues(); if(activated_q.empty()) { @@ -278,9 +278,9 @@ bool QMgrHelper::isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef) * Changes the first entry into the stack, i.e., the default queue to a new * sycl::queue corresponding to the device type and device number. */ -__dppl_give DPPLSyclQueueRef -QMgrHelper::setAsDefaultQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +__dpctl_give DPCTLSyclQueueRef +QMgrHelper::setAsDefaultQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { queue *QRef = nullptr; @@ -292,7 +292,7 @@ QMgrHelper::setAsDefaultQueue (DPPLSyclBackendType BETy, switch (BETy|DeviceTy) { - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_CPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_CPU: { auto oclcpu_q = get_opencl_cpu_queues(); if (DNum >= oclcpu_q.size()) { @@ -304,7 +304,7 @@ QMgrHelper::setAsDefaultQueue (DPPLSyclBackendType BETy, activeQ[0] = oclcpu_q[DNum]; break; } - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_GPU: { auto oclgpu_q = get_opencl_gpu_queues(); if (DNum >= oclgpu_q.size()) { @@ -316,7 +316,7 @@ QMgrHelper::setAsDefaultQueue (DPPLSyclBackendType BETy, activeQ[0] = oclgpu_q[DNum]; break; } - case DPPLSyclBackendType::DPPL_LEVEL_ZERO | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO | DPCTLSyclDeviceType::DPCTL_GPU: { auto l0gpu_q = get_level0_gpu_queues(); if (DNum >= l0gpu_q.size()) { @@ -342,12 +342,12 @@ QMgrHelper::setAsDefaultQueue (DPPLSyclBackendType BETy, /*! * Allocates a new sycl::queue by copying from the cached {cpu|gpu}_queues * vector. The pointer returned is now owned by the caller and must be properly - * cleaned up. The helper function DPPLDeleteSyclQueue() can be used is for that + * cleaned up. The helper function DPCTLDeleteSyclQueue() can be used is for that * purpose. */ -__dppl_give DPPLSyclQueueRef -QMgrHelper::pushSyclQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +__dpctl_give DPCTLSyclQueueRef +QMgrHelper::pushSyclQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { queue *QRef = nullptr; @@ -359,7 +359,7 @@ QMgrHelper::pushSyclQueue (DPPLSyclBackendType BETy, switch (BETy|DeviceTy) { - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_CPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_CPU: { if (DNum >= get_opencl_cpu_queues().size()) { // \todo handle error @@ -371,7 +371,7 @@ QMgrHelper::pushSyclQueue (DPPLSyclBackendType BETy, QRef = new queue(activeQ[activeQ.size()-1]); break; } - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_GPU: { if (DNum >= get_opencl_gpu_queues().size()) { // \todo handle error @@ -383,7 +383,7 @@ QMgrHelper::pushSyclQueue (DPPLSyclBackendType BETy, QRef = new queue(activeQ[get_active_queues().size()-1]); break; } - case DPPLSyclBackendType::DPPL_LEVEL_ZERO | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO | DPCTLSyclDeviceType::DPCTL_GPU: { if (DNum >= get_level0_gpu_queues().size()) { // \todo handle error @@ -432,7 +432,7 @@ QMgrHelper::popSyclQueue () * Returns inside the number of activated queues not including the global queue * (QMgrHelper::active_queues[0]). */ -size_t DPPLQueueMgr_GetNumActivatedQueues () +size_t DPCTLQueueMgr_GetNumActivatedQueues () { if (QMgrHelper::get_active_queues().empty()) { // \todo handle error @@ -446,20 +446,20 @@ size_t DPPLQueueMgr_GetNumActivatedQueues () * Returns the number of available queues for a specific backend and device * type combination. */ -size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy) +size_t DPCTLQueueMgr_GetNumQueues (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy) { switch (BETy|DeviceTy) { - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_CPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_CPU: { return QMgrHelper::get_opencl_cpu_queues().size(); } - case DPPLSyclBackendType::DPPL_OPENCL | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_OPENCL | DPCTLSyclDeviceType::DPCTL_GPU: { return QMgrHelper::get_opencl_gpu_queues().size(); } - case DPPLSyclBackendType::DPPL_LEVEL_ZERO | DPPLSyclDeviceType::DPPL_GPU: + case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO | DPCTLSyclDeviceType::DPCTL_GPU: { return QMgrHelper::get_level0_gpu_queues().size(); } @@ -475,7 +475,7 @@ size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBackendType BETy, /*! * \see QMgrHelper::getCurrentQueue() */ -DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue () +DPCTLSyclQueueRef DPCTLQueueMgr_GetCurrentQueue () { return QMgrHelper::getCurrentQueue(); } @@ -484,8 +484,8 @@ DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue () * Returns a copy of a sycl::queue corresponding to the specified device type * and device number. A runtime_error gets thrown if no such device exists. */ -DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +DPCTLSyclQueueRef DPCTLQueueMgr_GetQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { return QMgrHelper::getQueue(BETy, DeviceTy, DNum); @@ -494,7 +494,7 @@ DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy, /*! * */ -bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef) +bool DPCTLQueueMgr_IsCurrentQueue (__dpctl_keep const DPCTLSyclQueueRef QRef) { return QMgrHelper::isCurrentQueue(QRef); } @@ -504,9 +504,9 @@ bool DPPLQueueMgr_IsCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef) * specified device type and id. If not queue was found for the backend and * device, Null is returned. */ -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_SetAsDefaultQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { return QMgrHelper::setAsDefaultQueue(BETy, DeviceTy, DNum); @@ -515,9 +515,9 @@ DPPLQueueMgr_SetAsDefaultQueue (DPPLSyclBackendType BETy, /*! * \see QMgrHelper::pushSyclQueue() */ -__dppl_give DPPLSyclQueueRef -DPPLQueueMgr_PushQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +__dpctl_give DPCTLSyclQueueRef +DPCTLQueueMgr_PushQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) { return QMgrHelper::pushSyclQueue(BETy, DeviceTy, DNum); @@ -526,7 +526,7 @@ DPPLQueueMgr_PushQueue (DPPLSyclBackendType BETy, /*! * \see QMgrHelper::popSyclQueue() */ -void DPPLQueueMgr_PopQueue () +void DPCTLQueueMgr_PopQueue () { QMgrHelper::popSyclQueue(); } @@ -535,9 +535,9 @@ void DPPLQueueMgr_PopQueue () * The function constructs a new SYCL queue instance from SYCL conext and * SYCL device. */ -DPPLSyclQueueRef -DPPLQueueMgr_GetQueueFromContextAndDevice (__dppl_keep DPPLSyclContextRef CRef, - __dppl_keep DPPLSyclDeviceRef DRef) +DPCTLSyclQueueRef +DPCTLQueueMgr_GetQueueFromContextAndDevice (__dpctl_keep DPCTLSyclContextRef CRef, + __dpctl_keep DPCTLSyclDeviceRef DRef) { auto dev = unwrap(DRef); auto ctx = unwrap(CRef); diff --git a/backends/source/dppl_sycl_usm_interface.cpp b/dpctl-capi/source/dpctl_sycl_usm_interface.cpp similarity index 58% rename from backends/source/dppl_sycl_usm_interface.cpp rename to dpctl-capi/source/dpctl_sycl_usm_interface.cpp index dd79a45bb1..bf0afc233f 100644 --- a/backends/source/dppl_sycl_usm_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_usm_interface.cpp @@ -1,4 +1,4 @@ -//===------- dppl_sycl_usm_interface.cpp - dpctl-C_API ---*--- C++ ---*---===// +//===------ dpctl_sycl_usm_interface.cpp - dpctl-C_API ---*--- C++ ---*---===// // // Data Parallel Control Library (dpCtl) // @@ -20,12 +20,12 @@ /// /// \file /// This file implements the data types and functions declared in -/// dppl_sycl_usm_interface.h. +/// dpctl_sycl_usm_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_usm_interface.h" -#include "dppl_sycl_device_interface.h" +#include "dpctl_sycl_usm_interface.h" +#include "dpctl_sycl_device_interface.h" #include "Support/CBindingWrapping.h" #include /* SYCL headers */ @@ -35,74 +35,74 @@ using namespace cl::sycl; namespace { // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPPLSyclQueueRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPPLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPPLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPPLSyclUSMRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef) } /* end of anonymous namespace */ -__dppl_give DPPLSyclUSMRef -DPPLmalloc_shared (size_t size, __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_shared (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = malloc_shared(size, *Q); return wrap(Ptr); } -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_shared (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_shared (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = aligned_alloc_shared(alignment, size, *Q); return wrap(Ptr); } -__dppl_give DPPLSyclUSMRef -DPPLmalloc_host (size_t size, __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_host (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = malloc_host(size, *Q); return wrap(Ptr); } -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_host (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_host (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = aligned_alloc_host(alignment, size, *Q); return wrap(Ptr); } -__dppl_give DPPLSyclUSMRef -DPPLmalloc_device (size_t size, __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLmalloc_device (size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = malloc_device(size, *Q); return wrap(Ptr); } -__dppl_give DPPLSyclUSMRef -DPPLaligned_alloc_device (size_t alignment, size_t size, - __dppl_keep const DPPLSyclQueueRef QRef) +__dpctl_give DPCTLSyclUSMRef +DPCTLaligned_alloc_device (size_t alignment, size_t size, + __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Q = unwrap(QRef); auto Ptr = aligned_alloc_device(alignment, size, *Q); return wrap(Ptr); } -void DPPLfree_with_queue (__dppl_take DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclQueueRef QRef) +void DPCTLfree_with_queue (__dpctl_take DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclQueueRef QRef) { auto Ptr = unwrap(MRef); auto Q = unwrap(QRef); free(Ptr, *Q); } -void DPPLfree_with_context (__dppl_take DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef) +void DPCTLfree_with_context (__dpctl_take DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef) { auto Ptr = unwrap(MRef); auto C = unwrap(CRef); @@ -110,8 +110,8 @@ void DPPLfree_with_context (__dppl_take DPPLSyclUSMRef MRef, } const char * -DPPLUSM_GetPointerType (__dppl_keep const DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef) +DPCTLUSM_GetPointerType (__dpctl_keep const DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef) { auto Ptr = unwrap(MRef); auto C = unwrap(CRef); @@ -129,9 +129,9 @@ DPPLUSM_GetPointerType (__dppl_keep const DPPLSyclUSMRef MRef, } } -DPPLSyclDeviceRef -DPPLUSM_GetPointerDevice (__dppl_keep const DPPLSyclUSMRef MRef, - __dppl_keep const DPPLSyclContextRef CRef) +DPCTLSyclDeviceRef +DPCTLUSM_GetPointerDevice (__dpctl_keep const DPCTLSyclUSMRef MRef, + __dpctl_keep const DPCTLSyclContextRef CRef) { auto Ptr = unwrap(MRef); auto C = unwrap(CRef); diff --git a/backends/source/dppl_utils.cpp b/dpctl-capi/source/dpctl_utils.cpp similarity index 76% rename from backends/source/dppl_utils.cpp rename to dpctl-capi/source/dpctl_utils.cpp index 6468809070..9ba61bb00b 100644 --- a/backends/source/dppl_utils.cpp +++ b/dpctl-capi/source/dpctl_utils.cpp @@ -1,4 +1,4 @@ -//===-------------- dppl_utils.cpp - dpctl-C_API ----*---- C++ -----*-----===// +//===------------- dpctl_utils.cpp - dpctl-C_API ----*---- C++ -----*-----===// // // Data Parallel Control Library (dpCtl) // @@ -19,18 +19,18 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file implements the helper functions defined in dppl_utils.h. +/// This file implements the helper functions defined in dpctl_utils.h. /// //===----------------------------------------------------------------------===// -#include "dppl_utils.h" +#include "dpctl_utils.h" -void DPPLCString_Delete (__dppl_take const char* str) +void DPCTLCString_Delete (__dpctl_take const char* str) { delete[] str; } -void DPPLSize_t_Array_Delete (__dppl_take size_t* arr) +void DPCTLSize_t_Array_Delete (__dpctl_take size_t* arr) { delete[] arr; } diff --git a/backends/tests/CMakeLists.txt b/dpctl-capi/tests/CMakeLists.txt similarity index 91% rename from backends/tests/CMakeLists.txt rename to dpctl-capi/tests/CMakeLists.txt index bdccdde3fd..8c599ce333 100644 --- a/backends/tests/CMakeLists.txt +++ b/dpctl-capi/tests/CMakeLists.txt @@ -21,7 +21,7 @@ endforeach() file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) add_executable(dpctl_c_api_tests EXCLUDE_FROM_ALL ${sources}) target_link_libraries( - dpctl_c_api_tests ${CMAKE_THREAD_LIBS_INIT} GTest::GTest DPPLSyclInterface + dpctl_c_api_tests ${CMAKE_THREAD_LIBS_INIT} GTest::GTest DPCTLSyclInterface ) gtest_discover_tests(dpctl_c_api_tests) add_dependencies(check dpctl_c_api_tests) diff --git a/backends/tests/multi_kernel.spv b/dpctl-capi/tests/multi_kernel.spv similarity index 100% rename from backends/tests/multi_kernel.spv rename to dpctl-capi/tests/multi_kernel.spv diff --git a/backends/tests/test_main.cpp b/dpctl-capi/tests/test_main.cpp similarity index 100% rename from backends/tests/test_main.cpp rename to dpctl-capi/tests/test_main.cpp diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp new file mode 100644 index 0000000000..22493b0156 --- /dev/null +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -0,0 +1,397 @@ +//===--- test_sycl_device_interface.cpp - dpctl-C_API interface -*- C++ -*-===// +// +// Python Data Parallel Processing Library (PyDPCTL) +// +// Copyright 2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file has unit test cases for functions defined in +/// dpctl_sycl_device_interface.h. +/// +//===----------------------------------------------------------------------===// + +#include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" +#include "dpctl_utils.h" + +#include +#include + +using namespace cl::sycl; + + +struct TestDPCTLSyclDeviceInterface : public ::testing::Test +{ + DPCTLSyclDeviceRef OpenCL_cpu = nullptr; + DPCTLSyclDeviceRef OpenCL_gpu = nullptr; + DPCTLSyclDeviceRef OpenCL_Level0_gpu = nullptr; + + TestDPCTLSyclDeviceInterface () + { + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + OpenCL_cpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + OpenCL_gpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + + if(DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); + OpenCL_Level0_gpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + } + + ~TestDPCTLSyclDeviceInterface () + { + DPCTLDevice_Delete(OpenCL_cpu); + DPCTLDevice_Delete(OpenCL_gpu); + DPCTLDevice_Delete(OpenCL_Level0_gpu); + } + +}; + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetDriverInfo) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto DriverInfo = DPCTLDevice_GetDriverInfo(OpenCL_cpu); + EXPECT_TRUE(DriverInfo != nullptr); + DPCTLCString_Delete(DriverInfo); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetDriverInfo) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto DriverInfo = DPCTLDevice_GetDriverInfo(OpenCL_gpu); + EXPECT_TRUE(DriverInfo != nullptr); + DPCTLCString_Delete(DriverInfo); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetDriverInfo) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto DriverInfo = DPCTLDevice_GetDriverInfo(OpenCL_Level0_gpu); + EXPECT_TRUE(DriverInfo != nullptr); + DPCTLCString_Delete(DriverInfo); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetMaxComputeUnits) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto n = DPCTLDevice_GetMaxComputeUnits(OpenCL_cpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetMaxComputeUnits) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto n = DPCTLDevice_GetMaxComputeUnits(OpenCL_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetMaxComputeUnits) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto n = DPCTLDevice_GetMaxComputeUnits(OpenCL_Level0_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkItemDims) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto n = DPCTLDevice_GetMaxWorkItemDims(OpenCL_cpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkItemDims) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto n = DPCTLDevice_GetMaxWorkItemDims(OpenCL_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkItemDims) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto n = DPCTLDevice_GetMaxWorkItemDims(OpenCL_Level0_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkItemSizes) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto item_sizes = DPCTLDevice_GetMaxWorkItemSizes(OpenCL_cpu); + EXPECT_TRUE(item_sizes != nullptr); + DPCTLSize_t_Array_Delete(item_sizes); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkItemSizes) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto item_sizes = DPCTLDevice_GetMaxWorkItemSizes(OpenCL_gpu); + EXPECT_TRUE(item_sizes != nullptr); + DPCTLSize_t_Array_Delete(item_sizes); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkItemSizes) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto item_sizes = DPCTLDevice_GetMaxWorkItemSizes(OpenCL_Level0_gpu); + EXPECT_TRUE(item_sizes != nullptr); + DPCTLSize_t_Array_Delete(item_sizes); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetMaxWorkGroupSize) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto n = DPCTLDevice_GetMaxWorkGroupSize(OpenCL_cpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetMaxWorkGroupSize) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto n = DPCTLDevice_GetMaxWorkGroupSize(OpenCL_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetMaxWorkGroupSize) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto n = DPCTLDevice_GetMaxWorkGroupSize(OpenCL_Level0_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetMaxNumSubGroups) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto n = DPCTLDevice_GetMaxNumSubGroups(OpenCL_cpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetMaxNumSubGroups) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto n = DPCTLDevice_GetMaxNumSubGroups(OpenCL_gpu); + EXPECT_TRUE(n > 0); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetMaxNumSubGroups) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto n = DPCTLDevice_GetMaxNumSubGroups(OpenCL_Level0_gpu); + EXPECT_TRUE(n > 0); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_HasInt64BaseAtomics) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto atomics = DPCTLDevice_HasInt64BaseAtomics(OpenCL_cpu); + auto D = reinterpret_cast(OpenCL_cpu); + auto has_atomics= D->has(aspect::int64_base_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_HasInt64BaseAtomics) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto atomics = DPCTLDevice_HasInt64BaseAtomics(OpenCL_gpu); + auto D = reinterpret_cast(OpenCL_gpu); + auto has_atomics= D->has(aspect::int64_base_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_HasInt64BaseAtomics) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto atomics = DPCTLDevice_HasInt64BaseAtomics(OpenCL_Level0_gpu); + auto D = reinterpret_cast(OpenCL_Level0_gpu); + auto has_atomics= D->has(aspect::int64_base_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_HasInt64ExtendedAtomics) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto atomics = DPCTLDevice_HasInt64ExtendedAtomics(OpenCL_cpu); + auto D = reinterpret_cast(OpenCL_cpu); + auto has_atomics= D->has(aspect::int64_extended_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_HasInt64ExtendedAtomics) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL GPU device found."); + + auto atomics = DPCTLDevice_HasInt64ExtendedAtomics(OpenCL_gpu); + auto D = reinterpret_cast(OpenCL_gpu); + auto has_atomics= D->has(aspect::int64_extended_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +//TODO: Update when DPC++ properly supports aspects +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_HasInt64ExtendedAtomics) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto atomics = DPCTLDevice_HasInt64ExtendedAtomics(OpenCL_Level0_gpu); + auto D = reinterpret_cast(OpenCL_Level0_gpu); + auto has_atomics= D->has(aspect::int64_extended_atomics); + EXPECT_TRUE(has_atomics == atomics); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetName) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto DevName = DPCTLDevice_GetName(OpenCL_cpu); + EXPECT_TRUE(DevName != nullptr); + DPCTLCString_Delete(DevName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetName) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto DevName = DPCTLDevice_GetName(OpenCL_gpu); + EXPECT_TRUE(DevName != nullptr); + DPCTLCString_Delete(DevName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetName) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto DevName = DPCTLDevice_GetName(OpenCL_Level0_gpu); + EXPECT_TRUE(DevName != nullptr); + DPCTLCString_Delete(DevName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetVendorName) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto VendorName = DPCTLDevice_GetVendorName(OpenCL_cpu); + EXPECT_TRUE(VendorName != nullptr); + DPCTLCString_Delete(VendorName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_GetVendorName) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + auto VendorName = DPCTLDevice_GetVendorName(OpenCL_gpu); + EXPECT_TRUE(VendorName != nullptr); + DPCTLCString_Delete(VendorName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_GetVendorName) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + auto VendorName = DPCTLDevice_GetVendorName(OpenCL_Level0_gpu); + EXPECT_TRUE(VendorName != nullptr); + DPCTLCString_Delete(VendorName); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLCPU_IsCPU) +{ + if(!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + EXPECT_TRUE(DPCTLDevice_IsCPU(OpenCL_cpu)); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckOCLGPU_IsGPU) +{ + if(!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + EXPECT_TRUE(DPCTLDevice_IsGPU(OpenCL_gpu)); +} + +TEST_F (TestDPCTLSyclDeviceInterface, CheckLevel0GPU_IsGPU) +{ + if(!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no Level0 GPU device found."); + + EXPECT_TRUE(DPCTLDevice_IsGPU(OpenCL_Level0_gpu)); +} + diff --git a/backends/tests/test_sycl_kernel_interface.cpp b/dpctl-capi/tests/test_sycl_kernel_interface.cpp similarity index 51% rename from backends/tests/test_sycl_kernel_interface.cpp rename to dpctl-capi/tests/test_sycl_kernel_interface.cpp index e087b36d17..374be4de20 100644 --- a/backends/tests/test_sycl_kernel_interface.cpp +++ b/dpctl-capi/tests/test_sycl_kernel_interface.cpp @@ -20,16 +20,16 @@ /// /// \file /// This file has unit test cases for functions defined in -/// dppl_sycl_kernel_interface.h. +/// dpctl_sycl_kernel_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_kernel_interface.h" -#include "dppl_sycl_program_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" -#include "dppl_utils.h" +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_kernel_interface.h" +#include "dpctl_sycl_program_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" +#include "dpctl_utils.h" #include #include @@ -38,7 +38,7 @@ using namespace cl::sycl; -struct TestDPPLSyclKernelInterface : public ::testing::Test +struct TestDPCTLSyclKernelInterface : public ::testing::Test { const char *CLProgramStr = R"CLC( kernel void add(global int* a, global int* b, global int* c) { @@ -54,58 +54,58 @@ struct TestDPPLSyclKernelInterface : public ::testing::Test const char *CompileOpts ="-cl-fast-relaxed-math"; size_t nOpenCLGpuQ = 0; - TestDPPLSyclKernelInterface () - : nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) + TestDPCTLSyclKernelInterface () + : nOpenCLGpuQ(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { } }; -TEST_F (TestDPPLSyclKernelInterface, CheckGetFunctionName) +TEST_F (TestDPCTLSyclKernelInterface, CheckGetFunctionName) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, CompileOpts); - auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); - auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); + auto AddKernel = DPCTLProgram_GetKernel(PRef, "add"); + auto AxpyKernel = DPCTLProgram_GetKernel(PRef, "axpy"); - auto fnName1 = DPPLKernel_GetFunctionName(AddKernel); - auto fnName2 = DPPLKernel_GetFunctionName(AxpyKernel); + auto fnName1 = DPCTLKernel_GetFunctionName(AddKernel); + auto fnName2 = DPCTLKernel_GetFunctionName(AxpyKernel); ASSERT_STREQ("add", fnName1); ASSERT_STREQ("axpy", fnName2); - DPPLCString_Delete(fnName1); - DPPLCString_Delete(fnName2); + DPCTLCString_Delete(fnName1); + DPCTLCString_Delete(fnName2); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); - DPPLKernel_Delete(AddKernel); - DPPLKernel_Delete(AxpyKernel); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); + DPCTLKernel_Delete(AddKernel); + DPCTLKernel_Delete(AxpyKernel); } -TEST_F (TestDPPLSyclKernelInterface, CheckGetNumArgs) +TEST_F (TestDPCTLSyclKernelInterface, CheckGetNumArgs) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, CompileOpts); - auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); - auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); + auto AddKernel = DPCTLProgram_GetKernel(PRef, "add"); + auto AxpyKernel = DPCTLProgram_GetKernel(PRef, "axpy"); - ASSERT_EQ(DPPLKernel_GetNumArgs(AddKernel), 3ul); - ASSERT_EQ(DPPLKernel_GetNumArgs(AxpyKernel), 4ul); + ASSERT_EQ(DPCTLKernel_GetNumArgs(AddKernel), 3ul); + ASSERT_EQ(DPCTLKernel_GetNumArgs(AxpyKernel), 4ul); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); - DPPLKernel_Delete(AddKernel); - DPPLKernel_Delete(AxpyKernel); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); + DPCTLKernel_Delete(AddKernel); + DPCTLKernel_Delete(AxpyKernel); } diff --git a/backends/tests/test_sycl_platform_interface.cpp b/dpctl-capi/tests/test_sycl_platform_interface.cpp similarity index 58% rename from backends/tests/test_sycl_platform_interface.cpp rename to dpctl-capi/tests/test_sycl_platform_interface.cpp index 0af59173e2..525e0e1892 100644 --- a/backends/tests/test_sycl_platform_interface.cpp +++ b/dpctl-capi/tests/test_sycl_platform_interface.cpp @@ -20,47 +20,47 @@ /// /// \file /// This file has unit test cases for functions defined in -/// dppl_sycl_platform_interface.h. +/// dpctl_sycl_platform_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_platform_interface.h" +#include "dpctl_sycl_platform_interface.h" #include -struct TestDPPLSyclPlatformInterface : public ::testing::Test +struct TestDPCTLSyclPlatformInterface : public ::testing::Test { }; -TEST_F (TestDPPLSyclPlatformInterface, CheckGetNumPlatforms) +TEST_F (TestDPCTLSyclPlatformInterface, CheckGetNumPlatforms) { - auto nplatforms = DPPLPlatform_GetNumNonHostPlatforms(); + auto nplatforms = DPCTLPlatform_GetNumNonHostPlatforms(); EXPECT_GE(nplatforms, 0ul); } -TEST_F (TestDPPLSyclPlatformInterface, GetNumBackends) +TEST_F (TestDPCTLSyclPlatformInterface, GetNumBackends) { - auto nbackends = DPPLPlatform_GetNumNonHostBackends(); + auto nbackends = DPCTLPlatform_GetNumNonHostBackends(); EXPECT_GE(nbackends, 0ul); } -TEST_F (TestDPPLSyclPlatformInterface, GetListOfBackends) +TEST_F (TestDPCTLSyclPlatformInterface, GetListOfBackends) { - auto nbackends = DPPLPlatform_GetNumNonHostBackends(); + auto nbackends = DPCTLPlatform_GetNumNonHostBackends(); if(!nbackends) GTEST_SKIP_("No non host backends available"); - auto backends = DPPLPlatform_GetListOfNonHostBackends(); + auto backends = DPCTLPlatform_GetListOfNonHostBackends(); EXPECT_TRUE(backends != nullptr); for(auto i = 0ul; i < nbackends; ++i) { EXPECT_TRUE( - backends[i] == DPPLSyclBackendType::DPPL_CUDA || - backends[i] == DPPLSyclBackendType::DPPL_OPENCL || - backends[i] == DPPLSyclBackendType::DPPL_LEVEL_ZERO + backends[i] == DPCTLSyclBackendType::DPCTL_CUDA || + backends[i] == DPCTLSyclBackendType::DPCTL_OPENCL || + backends[i] == DPCTLSyclBackendType::DPCTL_LEVEL_ZERO ); } - DPPLPlatform_DeleteListOfBackends(backends); + DPCTLPlatform_DeleteListOfBackends(backends); } -TEST_F (TestDPPLSyclPlatformInterface, CheckDPPLPlatformDumpInfo) +TEST_F (TestDPCTLSyclPlatformInterface, CheckDPCTLPlatformDumpInfo) { - EXPECT_NO_FATAL_FAILURE(DPPLPlatform_DumpInfo()); + EXPECT_NO_FATAL_FAILURE(DPCTLPlatform_DumpInfo()); } diff --git a/backends/tests/test_sycl_program_interface.cpp b/dpctl-capi/tests/test_sycl_program_interface.cpp similarity index 65% rename from backends/tests/test_sycl_program_interface.cpp rename to dpctl-capi/tests/test_sycl_program_interface.cpp index ee4c5c4932..0e0061b674 100644 --- a/backends/tests/test_sycl_program_interface.cpp +++ b/dpctl-capi/tests/test_sycl_program_interface.cpp @@ -20,15 +20,15 @@ /// /// \file /// This file has unit test cases for functions defined in -/// dppl_sycl_program_interface.h. +/// dpctl_sycl_program_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_kernel_interface.h" -#include "dppl_sycl_program_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_kernel_interface.h" +#include "dpctl_sycl_program_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" #include #include @@ -42,7 +42,7 @@ namespace { const int SIZE = 1024; -void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel) +void add_kernel_checker (queue *syclQueue, DPCTLSyclKernelRef AddKernel) { range<1> a_size{SIZE}; std::array a, b, c; @@ -74,7 +74,7 @@ void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel) } } -void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel) +void axpy_kernel_checker (queue *syclQueue, DPCTLSyclKernelRef AxpyKernel) { range<1> a_size{SIZE}; std::array a, b, c; @@ -109,7 +109,7 @@ void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel) } /* end of anonymous namespace */ -struct TestDPPLSyclProgramInterface : public ::testing::Test +struct TestDPCTLSyclProgramInterface : public ::testing::Test { const char *CLProgramStr = R"CLC( kernel void add(global int* a, global int* b, global int* c) { @@ -128,69 +128,69 @@ struct TestDPPLSyclProgramInterface : public ::testing::Test std::vector spirvBuffer; size_t nOpenCLGpuQ = 0; - TestDPPLSyclProgramInterface () : + TestDPCTLSyclProgramInterface () : spirvFile{"./multi_kernel.spv", std::ios::binary | std::ios::ate}, spirvFileSize(std::filesystem::file_size("./multi_kernel.spv")), spirvBuffer(spirvFileSize), - nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) + nOpenCLGpuQ(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { spirvFile.seekg(0, std::ios::beg); spirvFile.read(spirvBuffer.data(), spirvFileSize); } - ~TestDPPLSyclProgramInterface () + ~TestDPCTLSyclProgramInterface () { spirvFile.close(); } }; -TEST_F (TestDPPLSyclProgramInterface, CheckCreateFromOCLSource) +TEST_F (TestDPCTLSyclProgramInterface, CheckCreateFromOCLSource) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, CompileOpts); ASSERT_TRUE(PRef != nullptr); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "add")); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "axpy")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "add")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "axpy")); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); } -TEST_F (TestDPPLSyclProgramInterface, CheckCreateFromOCLSpirv) +TEST_F (TestDPCTLSyclProgramInterface, CheckCreateFromOCLSpirv) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSpirv(CtxRef, spirvBuffer.data(), + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSpirv(CtxRef, spirvBuffer.data(), spirvFileSize); ASSERT_TRUE(PRef != nullptr); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "add")); - ASSERT_TRUE(DPPLProgram_HasKernel(PRef, "axpy")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "add")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "axpy")); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); } -TEST_F (TestDPPLSyclProgramInterface, CheckGetKernelOCLSource) +TEST_F (TestDPCTLSyclProgramInterface, CheckGetKernelOCLSource) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, CompileOpts); - auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); - auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); + auto AddKernel = DPCTLProgram_GetKernel(PRef, "add"); + auto AxpyKernel = DPCTLProgram_GetKernel(PRef, "axpy"); ASSERT_TRUE(AddKernel != nullptr); ASSERT_TRUE(AxpyKernel != nullptr); @@ -200,24 +200,24 @@ TEST_F (TestDPPLSyclProgramInterface, CheckGetKernelOCLSource) add_kernel_checker(syclQueue, AddKernel); axpy_kernel_checker(syclQueue, AxpyKernel); - DPPLKernel_Delete(AddKernel); - DPPLKernel_Delete(AxpyKernel); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); + DPCTLKernel_Delete(AddKernel); + DPCTLKernel_Delete(AxpyKernel); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); } -TEST_F (TestDPPLSyclProgramInterface, CheckGetKernelOCLSpirv) +TEST_F (TestDPCTLSyclProgramInterface, CheckGetKernelOCLSpirv) { if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto QueueRef = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); - auto CtxRef = DPPLQueue_GetContext(QueueRef); - auto PRef = DPPLProgram_CreateFromOCLSpirv(CtxRef, spirvBuffer.data(), + auto QueueRef = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(QueueRef); + auto PRef = DPCTLProgram_CreateFromOCLSpirv(CtxRef, spirvBuffer.data(), spirvFileSize); - auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); - auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); + auto AddKernel = DPCTLProgram_GetKernel(PRef, "add"); + auto AxpyKernel = DPCTLProgram_GetKernel(PRef, "axpy"); ASSERT_TRUE(AddKernel != nullptr); ASSERT_TRUE(AxpyKernel != nullptr); @@ -227,10 +227,10 @@ TEST_F (TestDPPLSyclProgramInterface, CheckGetKernelOCLSpirv) add_kernel_checker(syclQueue, AddKernel); axpy_kernel_checker(syclQueue, AxpyKernel); - DPPLKernel_Delete(AddKernel); - DPPLKernel_Delete(AxpyKernel); - DPPLQueue_Delete(QueueRef); - DPPLContext_Delete(CtxRef); - DPPLProgram_Delete(PRef); + DPCTLKernel_Delete(AddKernel); + DPCTLKernel_Delete(AxpyKernel); + DPCTLQueue_Delete(QueueRef); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); } diff --git a/dpctl-capi/tests/test_sycl_queue_interface.cpp b/dpctl-capi/tests/test_sycl_queue_interface.cpp new file mode 100644 index 0000000000..3a1b7cb5db --- /dev/null +++ b/dpctl-capi/tests/test_sycl_queue_interface.cpp @@ -0,0 +1,379 @@ +//===-------- test_sycl_queue_interface.cpp - dpctl-C_API ---*--- C++ --*--===// +// +// Data Parallel Control Library (dpCtl) +// +// Copyright 2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file has unit test cases for functions defined in +/// dpctl_sycl_queue_interface.h. +/// +//===----------------------------------------------------------------------===// + +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_event_interface.h" +#include "dpctl_sycl_kernel_interface.h" +#include "dpctl_sycl_program_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" +#include "dpctl_sycl_usm_interface.h" +#include "Support/CBindingWrapping.h" +#include +#include + +using namespace cl::sycl; + +namespace +{ +constexpr size_t SIZE = 1024; + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef); + +void add_kernel_checker (const float *a, const float *b, const float *c) +{ + // Validate the data + for(auto i = 0ul; i < SIZE; ++i) { + EXPECT_EQ(c[i], a[i] + b[i]); + } +} + +void axpy_kernel_checker (const float *a, const float *b, const float *c, + float d) +{ + for(auto i = 0ul; i < SIZE; ++i) { + EXPECT_EQ(c[i], a[i] + d*b[i]); + } +} + +bool has_devices () +{ + bool ret = false; + for (auto &p : platform::get_platforms()) { + if (p.is_host()) + continue; + if(!p.get_devices().empty()) { + ret = true; + break; + } + } + return ret; +} + +} + +struct TestDPCTLSyclQueueInterface : public ::testing::Test +{ + const char *CLProgramStr = R"CLC( + kernel void init_arr (global float *a) { + size_t index = get_global_id(0); + a[index] = (float)index; + } + + kernel void add (global float* a, global float* b, global float* c) { + size_t index = get_global_id(0); + c[index] = a[index] + b[index]; + } + + kernel void axpy (global float* a, global float* b, + global float* c, float d) { + size_t index = get_global_id(0); + c[index] = a[index] + d*b[index]; + } + )CLC"; + const char *CompileOpts ="-cl-fast-relaxed-math"; + + TestDPCTLSyclQueueInterface () + { } + + ~TestDPCTLSyclQueueInterface () + { } +}; + +TEST_F (TestDPCTLSyclQueueInterface, CheckAreEq) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto nOclGPU = DPCTLQueueMgr_GetNumQueues(DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU); + if(!nOclGPU) + GTEST_SKIP_("Skipping: No OpenCL GPUs available.\n"); + + auto Q1 = DPCTLQueueMgr_GetCurrentQueue(); + auto Q2 = DPCTLQueueMgr_GetCurrentQueue(); + EXPECT_TRUE(DPCTLQueue_AreEq(Q1, Q2)); + + auto Def_Q = DPCTLQueueMgr_SetAsDefaultQueue( + DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU, + 0 + ); + auto OclGPU_Q0 = DPCTLQueueMgr_PushQueue( + DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU, + 0 + ); + auto OclGPU_Q1 = DPCTLQueueMgr_PushQueue( + DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU, + 0 + ); + EXPECT_TRUE(DPCTLQueue_AreEq(Def_Q, OclGPU_Q0)); + EXPECT_TRUE(DPCTLQueue_AreEq(Def_Q, OclGPU_Q1)); + EXPECT_TRUE(DPCTLQueue_AreEq(OclGPU_Q0, OclGPU_Q1)); + DPCTLQueue_Delete(Def_Q); + DPCTLQueue_Delete(OclGPU_Q0); + DPCTLQueue_Delete(OclGPU_Q1); + DPCTLQueueMgr_PopQueue(); + DPCTLQueueMgr_PopQueue(); +} + +TEST_F (TestDPCTLSyclQueueInterface, CheckAreEq2) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto nOclGPU = DPCTLQueueMgr_GetNumQueues(DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU); + auto nOclCPU = DPCTLQueueMgr_GetNumQueues(DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_CPU); + if(!nOclGPU || !nOclCPU) + GTEST_SKIP_("OpenCL GPUs and CPU not available.\n"); + auto GPU_Q = DPCTLQueueMgr_PushQueue( + DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_GPU, + 0 + ); + auto CPU_Q = DPCTLQueueMgr_PushQueue( + DPCTLSyclBackendType::DPCTL_OPENCL, + DPCTLSyclDeviceType::DPCTL_CPU, + 0 + ); + EXPECT_FALSE(DPCTLQueue_AreEq(GPU_Q, CPU_Q)); + DPCTLQueueMgr_PopQueue(); + DPCTLQueueMgr_PopQueue(); +} + +TEST_F (TestDPCTLSyclQueueInterface, CheckGetBackend) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto Q1 = DPCTLQueueMgr_GetCurrentQueue(); + auto BE = DPCTLQueue_GetBackend(Q1); + EXPECT_TRUE((BE == DPCTL_OPENCL) || + (BE == DPCTL_LEVEL_ZERO) || + (BE == DPCTL_CUDA) || + (BE == DPCTL_HOST) + ); + DPCTLQueue_Delete(Q1); + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + EXPECT_TRUE(DPCTLQueue_GetBackend(Q) == DPCTL_OPENCL); + DPCTLQueue_Delete(Q); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + EXPECT_TRUE(DPCTLQueue_GetBackend(Q) == DPCTL_OPENCL); + DPCTLQueue_Delete(Q); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); + EXPECT_TRUE(DPCTLQueue_GetBackend(Q) == DPCTL_LEVEL_ZERO); + DPCTLQueue_Delete(Q); + DPCTLQueueMgr_PopQueue(); + } +} + +TEST_F (TestDPCTLSyclQueueInterface, CheckGetContext) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto Q1 = DPCTLQueueMgr_GetCurrentQueue(); + auto Ctx = DPCTLQueue_GetContext(Q1); + ASSERT_TRUE(Ctx != nullptr); + DPCTLQueue_Delete(Q1); + DPCTLContext_Delete(Ctx); + + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto OclGpuCtx = DPCTLQueue_GetContext(Q); + ASSERT_TRUE(OclGpuCtx != nullptr); + DPCTLQueue_Delete(Q); + DPCTLContext_Delete(OclGpuCtx); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + auto OclCpuCtx = DPCTLQueue_GetContext(Q); + ASSERT_TRUE(OclCpuCtx != nullptr); + DPCTLQueue_Delete(Q); + DPCTLContext_Delete(OclCpuCtx); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); + auto L0Ctx = DPCTLQueue_GetContext(Q); + ASSERT_TRUE(Ctx != nullptr); + DPCTLQueue_Delete(Q); + DPCTLContext_Delete(L0Ctx); + DPCTLQueueMgr_PopQueue(); + } +} + +TEST_F (TestDPCTLSyclQueueInterface, CheckGetDevice) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto Q1 = DPCTLQueueMgr_GetCurrentQueue(); + auto D = DPCTLQueue_GetDevice(Q1); + ASSERT_TRUE(D != nullptr); + DPCTLQueue_Delete(Q1); + DPCTLDevice_Delete(D); + + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto OCLGPU_D = DPCTLQueue_GetDevice(Q); + ASSERT_TRUE(OCLGPU_D != nullptr); + EXPECT_TRUE(DPCTLDevice_IsGPU(OCLGPU_D)); + DPCTLQueue_Delete(Q); + DPCTLDevice_Delete(OCLGPU_D); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + auto OCLCPU_D = DPCTLQueue_GetDevice(Q); + ASSERT_TRUE(OCLCPU_D != nullptr); + EXPECT_TRUE(DPCTLDevice_IsCPU(OCLCPU_D)); + DPCTLQueue_Delete(Q); + DPCTLDevice_Delete(OCLCPU_D); + DPCTLQueueMgr_PopQueue(); + } + if(DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_PushQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); + auto L0GPU_D = DPCTLQueue_GetDevice(Q); + ASSERT_TRUE(L0GPU_D != nullptr); + EXPECT_TRUE(DPCTLDevice_IsGPU(L0GPU_D)); + DPCTLQueue_Delete(Q); + DPCTLDevice_Delete(L0GPU_D); + DPCTLQueueMgr_PopQueue(); + } +} + +TEST_F (TestDPCTLSyclQueueInterface, CheckSubmit) +{ + if(!has_devices()) + GTEST_SKIP_("Skipping: No Sycl devices.\n"); + + auto nOpenCLGpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU); + + if(!nOpenCLGpuQ) + GTEST_SKIP_("Skipping: No OpenCL GPU device.\n"); + + auto Queue = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + auto CtxRef = DPCTLQueue_GetContext(Queue); + auto PRef = DPCTLProgram_CreateFromOCLSource(CtxRef, CLProgramStr, + CompileOpts); + ASSERT_TRUE(PRef != nullptr); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "init_arr")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "add")); + ASSERT_TRUE(DPCTLProgram_HasKernel(PRef, "axpy")); + + auto InitKernel = DPCTLProgram_GetKernel(PRef, "init_arr"); + auto AddKernel = DPCTLProgram_GetKernel(PRef, "add"); + auto AxpyKernel = DPCTLProgram_GetKernel(PRef, "axpy"); + + // Create the input args + auto a = DPCTLmalloc_shared(SIZE, Queue); + ASSERT_TRUE(a != nullptr); + auto b = DPCTLmalloc_shared(SIZE, Queue); + ASSERT_TRUE(b != nullptr); + auto c = DPCTLmalloc_shared(SIZE, Queue); + ASSERT_TRUE(c != nullptr); + + // Initialize a,b + DPCTLKernelArgType argTypes[] = {DPCTL_VOID_PTR}; + size_t Range[] = {SIZE}; + void *arg1[1] = { unwrap(a) }; + void *arg2[1] = { unwrap(b) }; + + auto E1 = DPCTLQueue_SubmitRange(InitKernel, Queue, arg1, argTypes, 1, + Range, 1, nullptr, 0); + auto E2 = DPCTLQueue_SubmitRange(InitKernel, Queue, arg2, argTypes, 1, + Range, 1, nullptr, 0); + ASSERT_TRUE(E1 != nullptr); + ASSERT_TRUE(E2 != nullptr); + + DPCTLQueue_Wait(Queue); + + // Submit the add kernel + void *args[3] = { unwrap(a), unwrap(b), unwrap(c) }; + DPCTLKernelArgType addKernelArgTypes[] = { + DPCTL_VOID_PTR, + DPCTL_VOID_PTR, + DPCTL_VOID_PTR + }; + + auto E3 = DPCTLQueue_SubmitRange(AddKernel, Queue, args, + addKernelArgTypes, 3, Range, 1, nullptr, 0); + ASSERT_TRUE(E3 != nullptr); + DPCTLQueue_Wait(Queue); + + // Verify the result of "add" + add_kernel_checker((float*)a, (float*)b, (float*)c); + + // Create kernel args for axpy + float d = 10.0; + void *args2[4] = { unwrap(a), unwrap(b), unwrap(c) , (void*)&d }; + DPCTLKernelArgType addKernelArgTypes2[] = { + DPCTL_VOID_PTR, + DPCTL_VOID_PTR, + DPCTL_VOID_PTR, + DPCTL_FLOAT + }; + auto E4 = DPCTLQueue_SubmitRange(AxpyKernel, Queue, args2, + addKernelArgTypes2, 4, Range, 1, + nullptr, 0); + ASSERT_TRUE(E4 != nullptr); + DPCTLQueue_Wait(Queue); + + // Verify the result of "axpy" + axpy_kernel_checker((float*)a, (float*)b, (float*)c, d); + + // clean ups + DPCTLEvent_Delete(E1); + DPCTLEvent_Delete(E2); + DPCTLEvent_Delete(E3); + DPCTLEvent_Delete(E4); + + DPCTLKernel_Delete(AddKernel); + DPCTLKernel_Delete(AxpyKernel); + DPCTLKernel_Delete(InitKernel); + + DPCTLfree_with_queue((DPCTLSyclUSMRef)a, Queue); + DPCTLfree_with_queue((DPCTLSyclUSMRef)b, Queue); + DPCTLfree_with_queue((DPCTLSyclUSMRef)c, Queue); + + DPCTLQueue_Delete(Queue); + DPCTLContext_Delete(CtxRef); + DPCTLProgram_Delete(PRef); +} + diff --git a/backends/tests/test_sycl_queue_manager.cpp b/dpctl-capi/tests/test_sycl_queue_manager.cpp similarity index 54% rename from backends/tests/test_sycl_queue_manager.cpp rename to dpctl-capi/tests/test_sycl_queue_manager.cpp index 4f3404ed30..7c69e26990 100644 --- a/backends/tests/test_sycl_queue_manager.cpp +++ b/dpctl-capi/tests/test_sycl_queue_manager.cpp @@ -20,13 +20,13 @@ /// /// \file /// This file has unit test cases for functions defined in -/// dppl_sycl_queue_interface.h and dppl_sycl_queue_manager.h. +/// dpctl_sycl_queue_interface.h and dpctl_sycl_queue_manager.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_device_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" #include #include @@ -39,23 +39,23 @@ namespace { void foo (size_t & num) { - auto q1 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); - auto q2 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); + auto q1 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + auto q2 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); // Capture the number of active queues in first - num = DPPLQueueMgr_GetNumActivatedQueues(); - DPPLQueueMgr_PopQueue(); - DPPLQueueMgr_PopQueue(); - DPPLQueue_Delete(q1); - DPPLQueue_Delete(q2); + num = DPCTLQueueMgr_GetNumActivatedQueues(); + DPCTLQueueMgr_PopQueue(); + DPCTLQueueMgr_PopQueue(); + DPCTLQueue_Delete(q1); + DPCTLQueue_Delete(q2); } void bar (size_t & num) { - auto q1 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); + auto q1 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); // Capture the number of active queues in second - num = DPPLQueueMgr_GetNumActivatedQueues(); - DPPLQueueMgr_PopQueue(); - DPPLQueue_Delete(q1); + num = DPCTLQueueMgr_GetNumActivatedQueues(); + DPCTLQueueMgr_PopQueue(); + DPCTLQueue_Delete(q1); } bool has_devices () @@ -74,31 +74,31 @@ bool has_devices () } -struct TestDPPLSyclQueueManager : public ::testing::Test +struct TestDPCTLSyclQueueManager : public ::testing::Test { }; -TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetCurrentQueue) +TEST_F (TestDPCTLSyclQueueManager, CheckDPCTLGetCurrentQueue) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - DPPLSyclQueueRef q = nullptr; - ASSERT_NO_THROW(q = DPPLQueueMgr_GetCurrentQueue()); + DPCTLSyclQueueRef q = nullptr; + ASSERT_NO_THROW(q = DPCTLQueueMgr_GetCurrentQueue()); ASSERT_TRUE(q != nullptr); } -TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetOpenCLCpuQ) +TEST_F (TestDPCTLSyclQueueManager, CheckDPCTLGetOpenCLCpuQ) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - auto nOpenCLCpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU); + auto nOpenCLCpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU); if(!nOpenCLCpuQ) GTEST_SKIP_("Skipping: No OpenCL CPU device found."); - auto q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_CPU, 0); + auto q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_CPU, 0); EXPECT_TRUE(q != nullptr); auto sycl_q = reinterpret_cast(q); auto be = sycl_q->get_context().get_platform().get_backend(); @@ -108,21 +108,21 @@ TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetOpenCLCpuQ) auto non_existent_device_num = nOpenCLCpuQ + 1; // Non-existent device number should return nullptr - auto null_q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_CPU, + auto null_q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_CPU, non_existent_device_num); ASSERT_TRUE(null_q == nullptr); } -TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetOpenCLGpuQ) +TEST_F (TestDPCTLSyclQueueManager, CheckDPCTLGetOpenCLGpuQ) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - auto nOpenCLGpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU); + auto nOpenCLGpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU); if(!nOpenCLGpuQ) GTEST_SKIP_("Skipping: No OpenCL GPU device found.\n"); - auto q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, 0); + auto q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); EXPECT_TRUE(q != nullptr); auto sycl_q = reinterpret_cast(q); auto be = sycl_q->get_context().get_platform().get_backend(); @@ -132,21 +132,21 @@ TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetOpenCLGpuQ) auto non_existent_device_num = nOpenCLGpuQ + 1; // Non-existent device number should return nullptr - auto null_q = DPPLQueueMgr_GetQueue(DPPL_OPENCL, DPPL_GPU, + auto null_q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, non_existent_device_num); ASSERT_TRUE(null_q == nullptr); } -TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetLevel0GpuQ) +TEST_F (TestDPCTLSyclQueueManager, CheckDPCTLGetLevel0GpuQ) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - auto nL0GpuQ = DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU); + auto nL0GpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU); if(!nL0GpuQ) GTEST_SKIP_("Skipping: No OpenCL GPU device found.\n"); - auto q = DPPLQueueMgr_GetQueue(DPPL_LEVEL_ZERO, DPPL_GPU, 0); + auto q = DPCTLQueueMgr_GetQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); EXPECT_TRUE(q != nullptr); auto sycl_q = reinterpret_cast(q); auto be = sycl_q->get_context().get_platform().get_backend(); @@ -156,26 +156,26 @@ TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetLevel0GpuQ) auto non_existent_device_num = nL0GpuQ + 1; // Non-existent device number should return nullptr - auto null_q = DPPLQueueMgr_GetQueue(DPPL_LEVEL_ZERO, DPPL_GPU, + auto null_q = DPCTLQueueMgr_GetQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, non_existent_device_num); ASSERT_TRUE(null_q == nullptr); } -TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues) +TEST_F (TestDPCTLSyclQueueManager, CheckGetNumActivatedQueues) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); size_t num0, num1, num2, num4; - auto nOpenCLCpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU); - auto nOpenCLGpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU); + auto nOpenCLCpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU); + auto nOpenCLGpuQ = DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU); // Add a queue to main thread if(!nOpenCLCpuQ || !nOpenCLGpuQ) GTEST_SKIP_("Skipping as no OpenCL GPU device found.\n"); - auto q = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); + auto q = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); std::thread first (foo, std::ref(num1)); std::thread second (bar, std::ref(num2)); @@ -185,9 +185,9 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues) second.join(); // Capture the number of active queues in first - num0 = DPPLQueueMgr_GetNumActivatedQueues(); - DPPLQueueMgr_PopQueue(); - num4 = DPPLQueueMgr_GetNumActivatedQueues(); + num0 = DPCTLQueueMgr_GetNumActivatedQueues(); + DPCTLQueueMgr_PopQueue(); + num4 = DPCTLQueueMgr_GetNumActivatedQueues(); // Verify what the expected number of activated queues each time a thread // called getNumActivatedQueues. @@ -196,67 +196,67 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues) EXPECT_EQ(num2, 1ul); EXPECT_EQ(num4, 0ul); - DPPLQueue_Delete(q); + DPCTLQueue_Delete(q); } -TEST_F (TestDPPLSyclQueueManager, CheckDPPLDumpDeviceInfo) +TEST_F (TestDPCTLSyclQueueManager, CheckDPCTLDumpDeviceInfo) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - auto q = DPPLQueueMgr_GetCurrentQueue(); - EXPECT_NO_FATAL_FAILURE(DPPLDevice_DumpInfo(DPPLQueue_GetDevice(q))); - EXPECT_NO_FATAL_FAILURE(DPPLQueue_Delete(q)); + auto q = DPCTLQueueMgr_GetCurrentQueue(); + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_DumpInfo(DPCTLQueue_GetDevice(q))); + EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(q)); } -TEST_F (TestDPPLSyclQueueManager, CheckIsCurrentQueue) +TEST_F (TestDPCTLSyclQueueManager, CheckIsCurrentQueue) { if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - if(!DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) + if(!DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) GTEST_SKIP_("Skipping: No OpenCL GPU.\n"); - auto Q0 = DPPLQueueMgr_GetCurrentQueue(); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q0)); - auto Q1 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q1)); - DPPLQueue_Delete(Q1); - DPPLQueueMgr_PopQueue(); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q0)); - DPPLQueue_Delete(Q0); + auto Q0 = DPCTLQueueMgr_GetCurrentQueue(); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q0)); + auto Q1 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q1)); + DPCTLQueue_Delete(Q1); + DPCTLQueueMgr_PopQueue(); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q0)); + DPCTLQueue_Delete(Q0); } -TEST_F (TestDPPLSyclQueueManager, CheckIsCurrentQueue2) +TEST_F (TestDPCTLSyclQueueManager, CheckIsCurrentQueue2) { - if(!DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU) || - !DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) + if(!DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU) || + !DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) GTEST_SKIP_("Skipping: No OpenCL GPU and OpenCL CPU.\n"); - auto Q1 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_GPU, 0); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q1)); - auto Q2 = DPPLQueueMgr_PushQueue(DPPL_OPENCL, DPPL_CPU, 0); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q2)); - EXPECT_FALSE(DPPLQueueMgr_IsCurrentQueue(Q1)); - DPPLQueue_Delete(Q2); - DPPLQueueMgr_PopQueue(); - EXPECT_TRUE(DPPLQueueMgr_IsCurrentQueue(Q1)); - DPPLQueue_Delete(Q1); - DPPLQueueMgr_PopQueue(); + auto Q1 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q1)); + auto Q2 = DPCTLQueueMgr_PushQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q2)); + EXPECT_FALSE(DPCTLQueueMgr_IsCurrentQueue(Q1)); + DPCTLQueue_Delete(Q2); + DPCTLQueueMgr_PopQueue(); + EXPECT_TRUE(DPCTLQueueMgr_IsCurrentQueue(Q1)); + DPCTLQueue_Delete(Q1); + DPCTLQueueMgr_PopQueue(); } -TEST_F (TestDPPLSyclQueueManager, CreateQueueFromDeviceAndContext) +TEST_F (TestDPCTLSyclQueueManager, CreateQueueFromDeviceAndContext) { - auto Q = DPPLQueueMgr_GetCurrentQueue(); - auto D = DPPLQueue_GetDevice(Q); - auto C = DPPLQueue_GetContext(Q); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); + auto D = DPCTLQueue_GetDevice(Q); + auto C = DPCTLQueue_GetContext(Q); - auto Q2 = DPPLQueueMgr_GetQueueFromContextAndDevice(C, D); - auto D2 = DPPLQueue_GetDevice(Q2); - auto C2 = DPPLQueue_GetContext(Q2); + auto Q2 = DPCTLQueueMgr_GetQueueFromContextAndDevice(C, D); + auto D2 = DPCTLQueue_GetDevice(Q2); + auto C2 = DPCTLQueue_GetContext(Q2); - EXPECT_TRUE(DPPLDevice_AreEq(D, D2)); - EXPECT_TRUE(DPPLContext_AreEq(C, C2)); + EXPECT_TRUE(DPCTLDevice_AreEq(D, D2)); + EXPECT_TRUE(DPCTLContext_AreEq(C, C2)); - DPPLQueue_Delete(Q2); - DPPLQueue_Delete(Q); + DPCTLQueue_Delete(Q2); + DPCTLQueue_Delete(Q); } diff --git a/backends/tests/test_sycl_usm_interface.cpp b/dpctl-capi/tests/test_sycl_usm_interface.cpp similarity index 52% rename from backends/tests/test_sycl_usm_interface.cpp rename to dpctl-capi/tests/test_sycl_usm_interface.cpp index 5e6135ac24..9d6cabedbe 100644 --- a/backends/tests/test_sycl_usm_interface.cpp +++ b/dpctl-capi/tests/test_sycl_usm_interface.cpp @@ -1,4 +1,4 @@ -//===-------- test_sycl_usm_interface.cpp - dpctl-C_API ---*--- C++ --*--===// +//===---------- test_sycl_usm_interface.cpp - dpctl-C_API ---*--- C++ --*--===// // // Data Parallel Control Library (dpCtl) // @@ -20,16 +20,16 @@ /// /// \file /// This file has unit test cases for functions defined in -/// dppl_sycl_usm_interface.h. +/// dpctl_sycl_usm_interface.h. /// //===----------------------------------------------------------------------===// -#include "dppl_sycl_context_interface.h" -#include "dppl_sycl_device_interface.h" -#include "dppl_sycl_event_interface.h" -#include "dppl_sycl_queue_interface.h" -#include "dppl_sycl_queue_manager.h" -#include "dppl_sycl_usm_interface.h" +#include "dpctl_sycl_context_interface.h" +#include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_event_interface.h" +#include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_queue_manager.h" +#include "dpctl_sycl_usm_interface.h" #include "Support/CBindingWrapping.h" #include #include @@ -40,7 +40,7 @@ namespace { constexpr size_t SIZE = 1024; -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPPLSyclUSMRef); +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef); bool has_devices () { @@ -57,129 +57,129 @@ bool has_devices () } void -common_test_body (size_t nbytes, const DPPLSyclUSMRef Ptr, - const DPPLSyclQueueRef Q, const char *expected) +common_test_body (size_t nbytes, const DPCTLSyclUSMRef Ptr, + const DPCTLSyclQueueRef Q, const char *expected) { - auto Ctx = DPPLQueue_GetContext(Q); + auto Ctx = DPCTLQueue_GetContext(Q); - auto kind = DPPLUSM_GetPointerType(Ptr, Ctx); + auto kind = DPCTLUSM_GetPointerType(Ptr, Ctx); EXPECT_TRUE(0 == std::strncmp(kind, expected, 4)); - auto Dev = DPPLUSM_GetPointerDevice(Ptr, Ctx); - auto QueueDev = DPPLQueue_GetDevice(Q); - EXPECT_TRUE(DPPLDevice_AreEq(Dev, QueueDev)); + auto Dev = DPCTLUSM_GetPointerDevice(Ptr, Ctx); + auto QueueDev = DPCTLQueue_GetDevice(Q); + EXPECT_TRUE(DPCTLDevice_AreEq(Dev, QueueDev)); - EXPECT_NO_FATAL_FAILURE(DPPLQueue_Prefetch(Q, Ptr, nbytes)); + EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Prefetch(Q, Ptr, nbytes)); - DPPLDevice_Delete(QueueDev); - DPPLDevice_Delete(Dev); - DPPLContext_Delete(Ctx); + DPCTLDevice_Delete(QueueDev); + DPCTLDevice_Delete(Dev); + DPCTLContext_Delete(Ctx); } } // end of namespace -struct TestDPPLSyclUSMInterface : public ::testing::Test +struct TestDPCTLSyclUSMInterface : public ::testing::Test { - TestDPPLSyclUSMInterface () + TestDPCTLSyclUSMInterface () { } - ~TestDPPLSyclUSMInterface () + ~TestDPCTLSyclUSMInterface () { } }; -TEST_F (TestDPPLSyclUSMInterface, MallocShared) +TEST_F (TestDPCTLSyclUSMInterface, MallocShared) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLmalloc_shared(nbytes, Q); + auto Ptr = DPCTLmalloc_shared(nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "shared"); - DPPLfree_with_queue(Ptr, Q); - DPPLQueue_Delete(Q); + DPCTLfree_with_queue(Ptr, Q); + DPCTLQueue_Delete(Q); } -TEST_F (TestDPPLSyclUSMInterface, MallocDevice) +TEST_F (TestDPCTLSyclUSMInterface, MallocDevice) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLmalloc_device(nbytes, Q); + auto Ptr = DPCTLmalloc_device(nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "device"); - DPPLfree_with_queue(Ptr, Q); - DPPLQueue_Delete(Q); + DPCTLfree_with_queue(Ptr, Q); + DPCTLQueue_Delete(Q); } -TEST_F (TestDPPLSyclUSMInterface, MallocHost) +TEST_F (TestDPCTLSyclUSMInterface, MallocHost) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLmalloc_host(nbytes, Q); + auto Ptr = DPCTLmalloc_host(nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "host"); - DPPLfree_with_queue(Ptr, Q); - DPPLQueue_Delete(Q); + DPCTLfree_with_queue(Ptr, Q); + DPCTLQueue_Delete(Q); } -TEST_F (TestDPPLSyclUSMInterface, AlignedAllocShared) +TEST_F (TestDPCTLSyclUSMInterface, AlignedAllocShared) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLaligned_alloc_shared(64, nbytes, Q); + auto Ptr = DPCTLaligned_alloc_shared(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "shared"); - DPPLfree_with_queue(Ptr, Q); - DPPLQueue_Delete(Q); + DPCTLfree_with_queue(Ptr, Q); + DPCTLQueue_Delete(Q); } -TEST_F (TestDPPLSyclUSMInterface, AlignedAllocDevice) +TEST_F (TestDPCTLSyclUSMInterface, AlignedAllocDevice) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLaligned_alloc_device(64, nbytes, Q); + auto Ptr = DPCTLaligned_alloc_device(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "device"); - DPPLfree_with_queue(Ptr, Q); - DPPLQueue_Delete(Q); + DPCTLfree_with_queue(Ptr, Q); + DPCTLQueue_Delete(Q); } -TEST_F (TestDPPLSyclUSMInterface, AlignedAllocHost) +TEST_F (TestDPCTLSyclUSMInterface, AlignedAllocHost) { if (!has_devices()) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); - auto Q = DPPLQueueMgr_GetCurrentQueue(); + auto Q = DPCTLQueueMgr_GetCurrentQueue(); const size_t nbytes = SIZE; - auto Ptr = DPPLaligned_alloc_host(64, nbytes, Q); + auto Ptr = DPCTLaligned_alloc_host(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); common_test_body(nbytes, Ptr, Q, "host"); - DPPLfree_with_queue(Ptr, Q); + DPCTLfree_with_queue(Ptr, Q); } diff --git a/dpctl/__init__.pxd b/dpctl/__init__.pxd index 89f3dbe551..87a5878b3f 100644 --- a/dpctl/__init__.pxd +++ b/dpctl/__init__.pxd @@ -1,4 +1,4 @@ -##===------------- __init__.pxd - dpctl module --------*- Cython -*-------===## +##===-------------- __init__.pxd - dpctl module --------*- Cython -*-------===## ## ## Data Parallel Control (dpCtl) ## diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index e354ae4187..4922086eca 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -31,205 +31,205 @@ from libcpp cimport bool from libc.stdint cimport uint32_t -cdef extern from "dppl_utils.h": - cdef void DPPLCString_Delete (const char *str) - cdef void DPPLSize_t_Array_Delete (size_t *arr) - -cdef extern from "dppl_sycl_enum_types.h": - cdef enum _backend_type 'DPPLSyclBackendType': - _OPENCL 'DPPL_OPENCL' - _HOST 'DPPL_HOST' - _LEVEL_ZERO 'DPPL_LEVEL_ZERO' - _CUDA 'DPPL_CUDA' - _UNKNOWN_BACKEND 'DPPL_UNKNOWN_BACKEND' - - ctypedef _backend_type DPPLSyclBackendType - - cdef enum _device_type 'DPPLSyclDeviceType': - _GPU 'DPPL_GPU' - _CPU 'DPPL_CPU' - _ACCELERATOR 'DPPL_ACCELERATOR' - _HOST_DEVICE 'DPPL_HOST_DEVICE' - - ctypedef _device_type DPPLSyclDeviceType - - cdef enum _arg_data_type 'DPPLKernelArgType': - _CHAR 'DPPL_CHAR', - _SIGNED_CHAR 'DPPL_SIGNED_CHAR', - _UNSIGNED_CHAR 'DPPL_UNSIGNED_CHAR', - _SHORT 'DPPL_SHORT', - _INT 'DPPL_INT', - _UNSIGNED_INT 'DPPL_UNSIGNED_INT', - _UNSIGNED_INT8 'DPPL_UNSIGNED_INT8', - _LONG 'DPPL_LONG', - _UNSIGNED_LONG 'DPPL_UNSIGNED_LONG', - _LONG_LONG 'DPPL_LONG_LONG', - _UNSIGNED_LONG_LONG 'DPPL_UNSIGNED_LONG_LONG', - _SIZE_T 'DPPL_SIZE_T', - _FLOAT 'DPPL_FLOAT', - _DOUBLE 'DPPL_DOUBLE', - _LONG_DOUBLE 'DPPL_DOUBLE', - _VOID_PTR 'DPPL_VOID_PTR' - - ctypedef _arg_data_type DPPLKernelArgType - -cdef extern from "dppl_sycl_types.h": - cdef struct DPPLOpaqueSyclContext - cdef struct DPPLOpaqueSyclDevice - cdef struct DPPLOpaqueSyclEvent - cdef struct DPPLOpaqueSyclKernel - cdef struct DPPLOpaqueSyclProgram - cdef struct DPPLOpaqueSyclQueue - cdef struct DPPLOpaqueSyclUSM - - ctypedef DPPLOpaqueSyclContext* DPPLSyclContextRef - ctypedef DPPLOpaqueSyclDevice* DPPLSyclDeviceRef - ctypedef DPPLOpaqueSyclEvent* DPPLSyclEventRef - ctypedef DPPLOpaqueSyclKernel* DPPLSyclKernelRef - ctypedef DPPLOpaqueSyclProgram* DPPLSyclProgramRef - ctypedef DPPLOpaqueSyclQueue* DPPLSyclQueueRef - ctypedef DPPLOpaqueSyclUSM* DPPLSyclUSMRef - - -cdef extern from "dppl_sycl_device_interface.h": - cdef void DPPLDevice_DumpInfo (const DPPLSyclDeviceRef DRef) - cdef void DPPLDevice_Delete (DPPLSyclDeviceRef DRef) - cdef void DPPLDevice_DumpInfo (const DPPLSyclDeviceRef DRef) - cdef bool DPPLDevice_IsAccelerator (const DPPLSyclDeviceRef DRef) - cdef bool DPPLDevice_IsCPU (const DPPLSyclDeviceRef DRef) - cdef bool DPPLDevice_IsGPU (const DPPLSyclDeviceRef DRef) - cdef bool DPPLDevice_IsHost (const DPPLSyclDeviceRef DRef) - cpdef const char *DPPLDevice_GetDriverInfo (const DPPLSyclDeviceRef DRef) - cpdef const char *DPPLDevice_GetName (const DPPLSyclDeviceRef DRef) - cpdef const char *DPPLDevice_GetVendorName (const DPPLSyclDeviceRef DRef) - cdef bool DPPLDevice_IsHostUnifiedMemory (const DPPLSyclDeviceRef DRef) - cpdef uint32_t DPPLDevice_GetMaxComputeUnits (const DPPLSyclDeviceRef DRef) - cpdef uint32_t DPPLDevice_GetMaxWorkItemDims (const DPPLSyclDeviceRef DRef) - cpdef size_t *DPPLDevice_GetMaxWorkItemSizes (const DPPLSyclDeviceRef DRef) - cpdef size_t DPPLDevice_GetMaxWorkGroupSize (const DPPLSyclDeviceRef DRef) - cpdef uint32_t DPPLDevice_GetMaxNumSubGroups (const DPPLSyclDeviceRef DRef) - cpdef bool DPPLDevice_HasInt64BaseAtomics (const DPPLSyclDeviceRef DRef) - cpdef bool DPPLDevice_HasInt64ExtendedAtomics (const DPPLSyclDeviceRef DRef) - - -cdef extern from "dppl_sycl_event_interface.h": - cdef void DPPLEvent_Wait (DPPLSyclEventRef ERef) - cdef void DPPLEvent_Delete (DPPLSyclEventRef ERef) - - -cdef extern from "dppl_sycl_kernel_interface.h": - cdef const char* DPPLKernel_GetFunctionName (const DPPLSyclKernelRef KRef) - cdef size_t DPPLKernel_GetNumArgs (const DPPLSyclKernelRef KRef) - cdef void DPPLKernel_Delete (DPPLSyclKernelRef KRef) - - -cdef extern from "dppl_sycl_platform_interface.h": - cdef size_t DPPLPlatform_GetNumNonHostPlatforms () - cdef void DPPLPlatform_DumpInfo () - cdef size_t DPPLPlatform_GetNumNonHostBackends () - cdef DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends () - cdef void DPPLPlatform_DeleteListOfBackends (DPPLSyclBackendType * BEs) - - -cdef extern from "dppl_sycl_context_interface.h": - cdef bool DPPLContext_AreEq (const DPPLSyclContextRef CtxRef1, - const DPPLSyclContextRef CtxRef2) - cdef DPPLSyclBackendType DPPLContext_GetBackend ( - const DPPLSyclContextRef CtxRef) - cdef void DPPLContext_Delete (DPPLSyclContextRef CtxRef) - - -cdef extern from "dppl_sycl_program_interface.h": - cdef DPPLSyclProgramRef DPPLProgram_CreateFromOCLSpirv ( - const DPPLSyclContextRef Ctx, +cdef extern from "dpctl_utils.h": + cdef void DPCTLCString_Delete (const char *str) + cdef void DPCTLSize_t_Array_Delete (size_t *arr) + +cdef extern from "dpctl_sycl_enum_types.h": + cdef enum _backend_type 'DPCTLSyclBackendType': + _OPENCL 'DPCTL_OPENCL' + _HOST 'DPCTL_HOST' + _LEVEL_ZERO 'DPCTL_LEVEL_ZERO' + _CUDA 'DPCTL_CUDA' + _UNKNOWN_BACKEND 'DPCTL_UNKNOWN_BACKEND' + + ctypedef _backend_type DPCTLSyclBackendType + + cdef enum _device_type 'DPCTLSyclDeviceType': + _GPU 'DPCTL_GPU' + _CPU 'DPCTL_CPU' + _ACCELERATOR 'DPCTL_ACCELERATOR' + _HOST_DEVICE 'DPCTL_HOST_DEVICE' + + ctypedef _device_type DPCTLSyclDeviceType + + cdef enum _arg_data_type 'DPCTLKernelArgType': + _CHAR 'DPCTL_CHAR', + _SIGNED_CHAR 'DPCTL_SIGNED_CHAR', + _UNSIGNED_CHAR 'DPCTL_UNSIGNED_CHAR', + _SHORT 'DPCTL_SHORT', + _INT 'DPCTL_INT', + _UNSIGNED_INT 'DPCTL_UNSIGNED_INT', + _UNSIGNED_INT8 'DPCTL_UNSIGNED_INT8', + _LONG 'DPCTL_LONG', + _UNSIGNED_LONG 'DPCTL_UNSIGNED_LONG', + _LONG_LONG 'DPCTL_LONG_LONG', + _UNSIGNED_LONG_LONG 'DPCTL_UNSIGNED_LONG_LONG', + _SIZE_T 'DPCTL_SIZE_T', + _FLOAT 'DPCTL_FLOAT', + _DOUBLE 'DPCTL_DOUBLE', + _LONG_DOUBLE 'DPCTL_DOUBLE', + _VOID_PTR 'DPCTL_VOID_PTR' + + ctypedef _arg_data_type DPCTLKernelArgType + +cdef extern from "dpctl_sycl_types.h": + cdef struct DPCTLOpaqueSyclContext + cdef struct DPCTLOpaqueSyclDevice + cdef struct DPCTLOpaqueSyclEvent + cdef struct DPCTLOpaqueSyclKernel + cdef struct DPCTLOpaqueSyclProgram + cdef struct DPCTLOpaqueSyclQueue + cdef struct DPCTLOpaqueSyclUSM + + ctypedef DPCTLOpaqueSyclContext* DPCTLSyclContextRef + ctypedef DPCTLOpaqueSyclDevice* DPCTLSyclDeviceRef + ctypedef DPCTLOpaqueSyclEvent* DPCTLSyclEventRef + ctypedef DPCTLOpaqueSyclKernel* DPCTLSyclKernelRef + ctypedef DPCTLOpaqueSyclProgram* DPCTLSyclProgramRef + ctypedef DPCTLOpaqueSyclQueue* DPCTLSyclQueueRef + ctypedef DPCTLOpaqueSyclUSM* DPCTLSyclUSMRef + + +cdef extern from "dpctl_sycl_device_interface.h": + cdef void DPCTLDevice_DumpInfo (const DPCTLSyclDeviceRef DRef) + cdef void DPCTLDevice_Delete (DPCTLSyclDeviceRef DRef) + cdef void DPCTLDevice_DumpInfo (const DPCTLSyclDeviceRef DRef) + cdef bool DPCTLDevice_IsAccelerator (const DPCTLSyclDeviceRef DRef) + cdef bool DPCTLDevice_IsCPU (const DPCTLSyclDeviceRef DRef) + cdef bool DPCTLDevice_IsGPU (const DPCTLSyclDeviceRef DRef) + cdef bool DPCTLDevice_IsHost (const DPCTLSyclDeviceRef DRef) + cpdef const char *DPCTLDevice_GetDriverInfo (const DPCTLSyclDeviceRef DRef) + cpdef const char *DPCTLDevice_GetName (const DPCTLSyclDeviceRef DRef) + cpdef const char *DPCTLDevice_GetVendorName (const DPCTLSyclDeviceRef DRef) + cdef bool DPCTLDevice_IsHostUnifiedMemory (const DPCTLSyclDeviceRef DRef) + cpdef uint32_t DPCTLDevice_GetMaxComputeUnits (const DPCTLSyclDeviceRef DRef) + cpdef uint32_t DPCTLDevice_GetMaxWorkItemDims (const DPCTLSyclDeviceRef DRef) + cpdef size_t *DPCTLDevice_GetMaxWorkItemSizes (const DPCTLSyclDeviceRef DRef) + cpdef size_t DPCTLDevice_GetMaxWorkGroupSize (const DPCTLSyclDeviceRef DRef) + cpdef uint32_t DPCTLDevice_GetMaxNumSubGroups (const DPCTLSyclDeviceRef DRef) + cpdef bool DPCTLDevice_HasInt64BaseAtomics (const DPCTLSyclDeviceRef DRef) + cpdef bool DPCTLDevice_HasInt64ExtendedAtomics (const DPCTLSyclDeviceRef DRef) + + +cdef extern from "dpctl_sycl_event_interface.h": + cdef void DPCTLEvent_Wait (DPCTLSyclEventRef ERef) + cdef void DPCTLEvent_Delete (DPCTLSyclEventRef ERef) + + +cdef extern from "dpctl_sycl_kernel_interface.h": + cdef const char* DPCTLKernel_GetFunctionName (const DPCTLSyclKernelRef KRef) + cdef size_t DPCTLKernel_GetNumArgs (const DPCTLSyclKernelRef KRef) + cdef void DPCTLKernel_Delete (DPCTLSyclKernelRef KRef) + + +cdef extern from "dpctl_sycl_platform_interface.h": + cdef size_t DPCTLPlatform_GetNumNonHostPlatforms () + cdef void DPCTLPlatform_DumpInfo () + cdef size_t DPCTLPlatform_GetNumNonHostBackends () + cdef DPCTLSyclBackendType *DPCTLPlatform_GetListOfNonHostBackends () + cdef void DPCTLPlatform_DeleteListOfBackends (DPCTLSyclBackendType * BEs) + + +cdef extern from "dpctl_sycl_context_interface.h": + cdef bool DPCTLContext_AreEq (const DPCTLSyclContextRef CtxRef1, + const DPCTLSyclContextRef CtxRef2) + cdef DPCTLSyclBackendType DPCTLContext_GetBackend ( + const DPCTLSyclContextRef CtxRef) + cdef void DPCTLContext_Delete (DPCTLSyclContextRef CtxRef) + + +cdef extern from "dpctl_sycl_program_interface.h": + cdef DPCTLSyclProgramRef DPCTLProgram_CreateFromOCLSpirv ( + const DPCTLSyclContextRef Ctx, const void *IL, size_t Length) - cdef DPPLSyclProgramRef DPPLProgram_CreateFromOCLSource ( - const DPPLSyclContextRef Ctx, + cdef DPCTLSyclProgramRef DPCTLProgram_CreateFromOCLSource ( + const DPCTLSyclContextRef Ctx, const char* Source, const char* CompileOpts) - cdef DPPLSyclKernelRef DPPLProgram_GetKernel (DPPLSyclProgramRef PRef, + cdef DPCTLSyclKernelRef DPCTLProgram_GetKernel (DPCTLSyclProgramRef PRef, const char *KernelName) - cdef bool DPPLProgram_HasKernel (DPPLSyclProgramRef PRef, + cdef bool DPCTLProgram_HasKernel (DPCTLSyclProgramRef PRef, const char *KernelName) - cdef void DPPLProgram_Delete (DPPLSyclProgramRef PRef) - - -cdef extern from "dppl_sycl_queue_interface.h": - cdef bool DPPLQueue_AreEq (const DPPLSyclQueueRef QRef1, - const DPPLSyclQueueRef QRef2) - cdef void DPPLQueue_Delete (DPPLSyclQueueRef QRef) - cdef DPPLSyclBackendType DPPLQueue_GetBackend (const DPPLSyclQueueRef Q) - cdef DPPLSyclContextRef DPPLQueue_GetContext (const DPPLSyclQueueRef Q) - cdef DPPLSyclDeviceRef DPPLQueue_GetDevice (const DPPLSyclQueueRef Q) - cdef DPPLSyclEventRef DPPLQueue_SubmitRange ( - const DPPLSyclKernelRef Ref, - const DPPLSyclQueueRef QRef, + cdef void DPCTLProgram_Delete (DPCTLSyclProgramRef PRef) + + +cdef extern from "dpctl_sycl_queue_interface.h": + cdef bool DPCTLQueue_AreEq (const DPCTLSyclQueueRef QRef1, + const DPCTLSyclQueueRef QRef2) + cdef void DPCTLQueue_Delete (DPCTLSyclQueueRef QRef) + cdef DPCTLSyclBackendType DPCTLQueue_GetBackend (const DPCTLSyclQueueRef Q) + cdef DPCTLSyclContextRef DPCTLQueue_GetContext (const DPCTLSyclQueueRef Q) + cdef DPCTLSyclDeviceRef DPCTLQueue_GetDevice (const DPCTLSyclQueueRef Q) + cdef DPCTLSyclEventRef DPCTLQueue_SubmitRange ( + const DPCTLSyclKernelRef Ref, + const DPCTLSyclQueueRef QRef, void **Args, - const DPPLKernelArgType *ArgTypes, + const DPCTLKernelArgType *ArgTypes, size_t NArgs, const size_t Range[3], size_t NDims, - const DPPLSyclEventRef *DepEvents, + const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) - cdef DPPLSyclEventRef DPPLQueue_SubmitNDRange( - const DPPLSyclKernelRef Ref, - const DPPLSyclQueueRef QRef, + cdef DPCTLSyclEventRef DPCTLQueue_SubmitNDRange( + const DPCTLSyclKernelRef Ref, + const DPCTLSyclQueueRef QRef, void **Args, - const DPPLKernelArgType *ArgTypes, + const DPCTLKernelArgType *ArgTypes, size_t NArgs, const size_t gRange[3], const size_t lRange[3], size_t NDims, - const DPPLSyclEventRef *DepEvents, + const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) - cdef void DPPLQueue_Wait (const DPPLSyclQueueRef QRef) - cdef void DPPLQueue_Memcpy (const DPPLSyclQueueRef Q, + cdef void DPCTLQueue_Wait (const DPCTLSyclQueueRef QRef) + cdef void DPCTLQueue_Memcpy (const DPCTLSyclQueueRef Q, void *Dest, const void *Src, size_t Count) - cdef void DPPLQueue_Prefetch (const DPPLSyclQueueRef Q, + cdef void DPCTLQueue_Prefetch (const DPCTLSyclQueueRef Q, const void *Src, size_t Count) - cdef void DPPLQueue_MemAdvise (const DPPLSyclQueueRef Q, + cdef void DPCTLQueue_MemAdvise (const DPCTLSyclQueueRef Q, const void *Src, size_t Count, int Advice) -cdef extern from "dppl_sycl_queue_manager.h": - cdef DPPLSyclQueueRef DPPLQueueMgr_GetCurrentQueue () - cdef size_t DPPLQueueMgr_GetNumQueues (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy) - cdef size_t DPPLQueueMgr_GetNumActivatedQueues () - cdef DPPLSyclQueueRef DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, +cdef extern from "dpctl_sycl_queue_manager.h": + cdef DPCTLSyclQueueRef DPCTLQueueMgr_GetCurrentQueue () + cdef size_t DPCTLQueueMgr_GetNumQueues (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy) + cdef size_t DPCTLQueueMgr_GetNumActivatedQueues () + cdef DPCTLSyclQueueRef DPCTLQueueMgr_GetQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) - cdef bool DPPLQueueMgr_IsCurrentQueue (const DPPLSyclQueueRef QRef) - cdef void DPPLQueueMgr_PopQueue () - cdef DPPLSyclQueueRef DPPLQueueMgr_PushQueue (DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, + cdef bool DPCTLQueueMgr_IsCurrentQueue (const DPCTLSyclQueueRef QRef) + cdef void DPCTLQueueMgr_PopQueue () + cdef DPCTLSyclQueueRef DPCTLQueueMgr_PushQueue (DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum) - cdef DPPLSyclQueueRef DPPLQueueMgr_SetAsDefaultQueue ( - DPPLSyclBackendType BETy, - DPPLSyclDeviceType DeviceTy, + cdef DPCTLSyclQueueRef DPCTLQueueMgr_SetAsDefaultQueue ( + DPCTLSyclBackendType BETy, + DPCTLSyclDeviceType DeviceTy, size_t DNum ) - cdef DPPLSyclQueueRef DPPLQueueMgr_GetQueueFromContextAndDevice( - DPPLSyclContextRef CRef, - DPPLSyclDeviceRef DRef) - - -cdef extern from "dppl_sycl_usm_interface.h": - cdef DPPLSyclUSMRef DPPLmalloc_shared (size_t size, DPPLSyclQueueRef QRef) - cdef DPPLSyclUSMRef DPPLmalloc_host (size_t size, DPPLSyclQueueRef QRef) - cdef DPPLSyclUSMRef DPPLmalloc_device (size_t size, DPPLSyclQueueRef QRef) - cdef DPPLSyclUSMRef DPPLaligned_alloc_shared (size_t alignment, - size_t size, DPPLSyclQueueRef QRef) - cdef DPPLSyclUSMRef DPPLaligned_alloc_host (size_t alignment, - size_t size, DPPLSyclQueueRef QRef) - cdef DPPLSyclUSMRef DPPLaligned_alloc_device (size_t alignment, - size_t size, DPPLSyclQueueRef QRef) - cdef void DPPLfree_with_queue (DPPLSyclUSMRef MRef, - DPPLSyclQueueRef QRef) - cdef void DPPLfree_with_context (DPPLSyclUSMRef MRef, - DPPLSyclContextRef CRef) - cdef const char* DPPLUSM_GetPointerType (DPPLSyclUSMRef MRef, - DPPLSyclContextRef CRef) - cdef DPPLSyclDeviceRef DPPLUSM_GetPointerDevice (DPPLSyclUSMRef MRef, - DPPLSyclContextRef CRef) + cdef DPCTLSyclQueueRef DPCTLQueueMgr_GetQueueFromContextAndDevice( + DPCTLSyclContextRef CRef, + DPCTLSyclDeviceRef DRef) + + +cdef extern from "dpctl_sycl_usm_interface.h": + cdef DPCTLSyclUSMRef DPCTLmalloc_shared (size_t size, DPCTLSyclQueueRef QRef) + cdef DPCTLSyclUSMRef DPCTLmalloc_host (size_t size, DPCTLSyclQueueRef QRef) + cdef DPCTLSyclUSMRef DPCTLmalloc_device (size_t size, DPCTLSyclQueueRef QRef) + cdef DPCTLSyclUSMRef DPCTLaligned_alloc_shared (size_t alignment, + size_t size, DPCTLSyclQueueRef QRef) + cdef DPCTLSyclUSMRef DPCTLaligned_alloc_host (size_t alignment, + size_t size, DPCTLSyclQueueRef QRef) + cdef DPCTLSyclUSMRef DPCTLaligned_alloc_device (size_t alignment, + size_t size, DPCTLSyclQueueRef QRef) + cdef void DPCTLfree_with_queue (DPCTLSyclUSMRef MRef, + DPCTLSyclQueueRef QRef) + cdef void DPCTLfree_with_context (DPCTLSyclUSMRef MRef, + DPCTLSyclContextRef CRef) + cdef const char* DPCTLUSM_GetPointerType (DPCTLSyclUSMRef MRef, + DPCTLSyclContextRef CRef) + cdef DPCTLSyclDeviceRef DPCTLUSM_GetPointerDevice (DPCTLSyclUSMRef MRef, + DPCTLSyclContextRef CRef) diff --git a/dpctl/_sycl_core.pxd b/dpctl/_sycl_core.pxd index 0fe7d677cd..66767d9620 100644 --- a/dpctl/_sycl_core.pxd +++ b/dpctl/_sycl_core.pxd @@ -34,18 +34,18 @@ from libc.stdint cimport uint32_t cdef class SyclContext: ''' Wrapper class for a Sycl Context ''' - cdef DPPLSyclContextRef _ctxt_ref + cdef DPCTLSyclContextRef _ctxt_ref @staticmethod - cdef SyclContext _create (DPPLSyclContextRef ctxt) + cdef SyclContext _create (DPCTLSyclContextRef ctxt) cpdef bool equals (self, SyclContext ctxt) - cdef DPPLSyclContextRef get_context_ref (self) + cdef DPCTLSyclContextRef get_context_ref (self) cdef class SyclDevice: ''' Wrapper class for a Sycl Device ''' - cdef DPPLSyclDeviceRef _device_ref + cdef DPCTLSyclDeviceRef _device_ref cdef const char *_vendor_name cdef const char *_device_name cdef const char *_driver_version @@ -58,8 +58,8 @@ cdef class SyclDevice: cdef bool _int64_extended_atomics @staticmethod - cdef SyclDevice _create (DPPLSyclDeviceRef dref) - cdef DPPLSyclDeviceRef get_device_ref (self) + cdef SyclDevice _create (DPCTLSyclDeviceRef dref) + cdef DPCTLSyclDeviceRef get_device_ref (self) cpdef get_device_name (self) cpdef get_device_type (self) cpdef get_vendor_name (self) @@ -76,12 +76,12 @@ cdef class SyclDevice: cdef class SyclEvent: ''' Wrapper class for a Sycl Event ''' - cdef DPPLSyclEventRef _event_ref + cdef DPCTLSyclEventRef _event_ref cdef list _args @staticmethod - cdef SyclEvent _create (DPPLSyclEventRef e, list args) - cdef DPPLSyclEventRef get_event_ref (self) + cdef SyclEvent _create (DPCTLSyclEventRef e, list args) + cdef DPCTLSyclEventRef get_event_ref (self) cpdef void wait (self) @@ -89,55 +89,55 @@ cdef class SyclKernel: ''' Wraps a sycl::kernel object created from an OpenCL interoperability kernel. ''' - cdef DPPLSyclKernelRef _kernel_ref + cdef DPCTLSyclKernelRef _kernel_ref cdef const char *_function_name - cdef DPPLSyclKernelRef get_kernel_ref (self) + cdef DPCTLSyclKernelRef get_kernel_ref (self) @staticmethod - cdef SyclKernel _create (DPPLSyclKernelRef kref) + cdef SyclKernel _create (DPCTLSyclKernelRef kref) cdef class SyclProgram: ''' Wraps a sycl::program object created from an OpenCL interoperability program. - SyclProgram exposes the C API from dppl_sycl_program_interface.h. A + SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A SyclProgram can be created from either a source string or a SPIR-V binary file. ''' - cdef DPPLSyclProgramRef _program_ref + cdef DPCTLSyclProgramRef _program_ref @staticmethod - cdef SyclProgram _create (DPPLSyclProgramRef pref) - cdef DPPLSyclProgramRef get_program_ref (self) + cdef SyclProgram _create (DPCTLSyclProgramRef pref) + cdef DPCTLSyclProgramRef get_program_ref (self) cpdef SyclKernel get_sycl_kernel(self, str kernel_name) cdef class SyclQueue: ''' Wrapper class for a Sycl queue. ''' - cdef DPPLSyclQueueRef _queue_ref + cdef DPCTLSyclQueueRef _queue_ref cdef SyclContext _context cdef SyclDevice _device cdef _raise_queue_submit_error (self, fname, errcode) cdef _raise_invalid_range_error (self, fname, ndims, errcode) cdef int _populate_args (self, list args, void **kargs, - DPPLKernelArgType *kargty) + DPCTLKernelArgType *kargty) cdef int _populate_range (self, size_t Range[3], list gS, size_t nGS) @staticmethod - cdef SyclQueue _create (DPPLSyclQueueRef qref) + cdef SyclQueue _create (DPCTLSyclQueueRef qref) @staticmethod cdef SyclQueue _create_from_context_and_device (SyclContext ctx, SyclDevice dev) cpdef bool equals (self, SyclQueue q) cpdef SyclContext get_sycl_context (self) cpdef SyclDevice get_sycl_device (self) - cdef DPPLSyclQueueRef get_queue_ref (self) + cdef DPCTLSyclQueueRef get_queue_ref (self) cpdef SyclEvent submit (self, SyclKernel kernel, list args, list gS, list lS=*, list dEvents=*) cpdef void wait (self) - cdef DPPLSyclQueueRef get_queue_ref (self) + cdef DPCTLSyclQueueRef get_queue_ref (self) cpdef memcpy (self, dest, src, size_t count) cpdef prefetch (self, ptr, size_t count=*) cpdef mem_advise (self, ptr, size_t count, int mem) diff --git a/dpctl/_sycl_core.pyx b/dpctl/_sycl_core.pyx index f9049f8322..de19924ed1 100644 --- a/dpctl/_sycl_core.pyx +++ b/dpctl/_sycl_core.pyx @@ -119,29 +119,29 @@ cdef class SyclQueueCreationError (Exception): cdef class SyclContext: @staticmethod - cdef SyclContext _create (DPPLSyclContextRef ctxt): + cdef SyclContext _create (DPCTLSyclContextRef ctxt): cdef SyclContext ret = SyclContext.__new__(SyclContext) ret._ctxt_ref = ctxt return ret def __dealloc__ (self): - DPPLContext_Delete(self._ctxt_ref) + DPCTLContext_Delete(self._ctxt_ref) cpdef bool equals (self, SyclContext ctxt): """ Returns true if the SyclContext argument has the same _context_ref as this SyclContext. """ - return DPPLContext_AreEq(self._ctxt_ref, ctxt.get_context_ref()) + return DPCTLContext_AreEq(self._ctxt_ref, ctxt.get_context_ref()) - cdef DPPLSyclContextRef get_context_ref (self): + cdef DPCTLSyclContextRef get_context_ref (self): return self._ctxt_ref def addressof_ref (self): - """Returns the address of the DPPLSyclContextRef pointer as a + """Returns the address of the DPCTLSyclContextRef pointer as a long. Returns: - The address of the DPPLSyclContextRef object used to create this + The address of the DPCTLSyclContextRef object used to create this SyclContext cast to a long. """ return int(self._ctx_ref) @@ -151,32 +151,32 @@ cdef class SyclDevice: """ @staticmethod - cdef SyclDevice _create (DPPLSyclDeviceRef dref): + cdef SyclDevice _create (DPCTLSyclDeviceRef dref): cdef SyclDevice ret = SyclDevice.__new__(SyclDevice) ret._device_ref = dref - ret._vendor_name = DPPLDevice_GetVendorName(dref) - ret._device_name = DPPLDevice_GetName(dref) - ret._driver_version = DPPLDevice_GetDriverInfo(dref) - ret._max_compute_units = DPPLDevice_GetMaxComputeUnits(dref) - ret._max_work_item_dims = DPPLDevice_GetMaxWorkItemDims(dref) - ret._max_work_item_sizes = DPPLDevice_GetMaxWorkItemSizes(dref) - ret._max_work_group_size = DPPLDevice_GetMaxWorkGroupSize(dref) - ret._max_num_sub_groups = DPPLDevice_GetMaxNumSubGroups(dref) - ret._int64_base_atomics = DPPLDevice_HasInt64BaseAtomics(dref) - ret._int64_extended_atomics = DPPLDevice_HasInt64ExtendedAtomics(dref) + ret._vendor_name = DPCTLDevice_GetVendorName(dref) + ret._device_name = DPCTLDevice_GetName(dref) + ret._driver_version = DPCTLDevice_GetDriverInfo(dref) + ret._max_compute_units = DPCTLDevice_GetMaxComputeUnits(dref) + ret._max_work_item_dims = DPCTLDevice_GetMaxWorkItemDims(dref) + ret._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(dref) + ret._max_work_group_size = DPCTLDevice_GetMaxWorkGroupSize(dref) + ret._max_num_sub_groups = DPCTLDevice_GetMaxNumSubGroups(dref) + ret._int64_base_atomics = DPCTLDevice_HasInt64BaseAtomics(dref) + ret._int64_extended_atomics = DPCTLDevice_HasInt64ExtendedAtomics(dref) return ret def __dealloc__ (self): - DPPLDevice_Delete(self._device_ref) - DPPLCString_Delete(self._device_name) - DPPLCString_Delete(self._vendor_name) - DPPLCString_Delete(self._driver_version) - DPPLSize_t_Array_Delete(self._max_work_item_sizes) + DPCTLDevice_Delete(self._device_ref) + DPCTLCString_Delete(self._device_name) + DPCTLCString_Delete(self._vendor_name) + DPCTLCString_Delete(self._driver_version) + DPCTLSize_t_Array_Delete(self._max_work_item_sizes) def dump_device_info (self): """ Print information about the SYCL device. """ - DPPLDevice_DumpInfo(self._device_ref) + DPCTLDevice_DumpInfo(self._device_ref) cpdef get_device_name (self): """ Returns the name of the device as a string @@ -186,9 +186,9 @@ cdef class SyclDevice: cpdef get_device_type (self): """ Returns the type of the device as a `device_type` enum """ - if DPPLDevice_IsGPU(self._device_ref): + if DPCTLDevice_IsGPU(self._device_ref): return device_type.gpu - elif DPPLDevice_IsCPU(self._device_ref): + elif DPCTLDevice_IsCPU(self._device_ref): return device_type.cpu else: raise ValueError("Unknown device type.") @@ -258,17 +258,17 @@ cdef class SyclDevice: """ return self._max_num_sub_groups - cdef DPPLSyclDeviceRef get_device_ref (self): - """ Returns the DPPLSyclDeviceRef pointer for this class. + cdef DPCTLSyclDeviceRef get_device_ref (self): + """ Returns the DPCTLSyclDeviceRef pointer for this class. """ return self._device_ref def addressof_ref (self): - """Returns the address of the DPPLSyclDeviceRef pointer as a + """Returns the address of the DPCTLSyclDeviceRef pointer as a long. Returns: - The address of the DPPLSyclDeviceRef object used to create this + The address of the DPCTLSyclDeviceRef object used to create this SyclDevice cast to a long. """ return int(self._device_ref) @@ -278,7 +278,7 @@ cdef class SyclEvent: """ @staticmethod - cdef SyclEvent _create (DPPLSyclEventRef eref, list args): + cdef SyclEvent _create (DPCTLSyclEventRef eref, list args): cdef SyclEvent ret = SyclEvent.__new__(SyclEvent) ret._event_ref = eref ret._args = args @@ -286,22 +286,22 @@ cdef class SyclEvent: def __dealloc__ (self): self.wait() - DPPLEvent_Delete(self._event_ref) + DPCTLEvent_Delete(self._event_ref) - cdef DPPLSyclEventRef get_event_ref (self): - """ Returns the DPPLSyclEventRef pointer for this class. + cdef DPCTLSyclEventRef get_event_ref (self): + """ Returns the DPCTLSyclEventRef pointer for this class. """ return self._event_ref cpdef void wait (self): - DPPLEvent_Wait(self._event_ref) + DPCTLEvent_Wait(self._event_ref) def addressof_ref (self): - """ Returns the address of the C API DPPLSyclEventRef pointer as + """ Returns the address of the C API DPCTLSyclEventRef pointer as a long. Returns: - The address of the DPPLSyclEventRef object used to create this + The address of the DPCTLSyclEventRef object used to create this SyclEvent cast to a long. """ return int(self._event_ref) @@ -313,15 +313,15 @@ cdef class SyclKernel: """ @staticmethod - cdef SyclKernel _create (DPPLSyclKernelRef kref): + cdef SyclKernel _create (DPCTLSyclKernelRef kref): cdef SyclKernel ret = SyclKernel.__new__(SyclKernel) ret._kernel_ref = kref - ret._function_name = DPPLKernel_GetFunctionName(kref) + ret._function_name = DPCTLKernel_GetFunctionName(kref) return ret def __dealloc__ (self): - DPPLKernel_Delete(self._kernel_ref) - DPPLCString_Delete(self._function_name) + DPCTLKernel_Delete(self._kernel_ref) + DPCTLCString_Delete(self._function_name) def get_function_name (self): """ Returns the name of the Kernel function. @@ -331,19 +331,19 @@ cdef class SyclKernel: def get_num_args (self): """ Returns the number of arguments for this kernel function. """ - return DPPLKernel_GetNumArgs(self._kernel_ref) + return DPCTLKernel_GetNumArgs(self._kernel_ref) - cdef DPPLSyclKernelRef get_kernel_ref (self): - """ Returns the DPPLSyclKernelRef pointer for this SyclKernel. + cdef DPCTLSyclKernelRef get_kernel_ref (self): + """ Returns the DPCTLSyclKernelRef pointer for this SyclKernel. """ return self._kernel_ref def addressof_ref (self): - """ Returns the address of the C API DPPLSyclKernelRef pointer + """ Returns the address of the C API DPCTLSyclKernelRef pointer as a long. Returns: - The address of the DPPLSyclKernelRef object used to create this + The address of the DPCTLSyclKernelRef object used to create this SyclKernel cast to a long. """ return int(self._kernel_ref) @@ -352,38 +352,38 @@ cdef class SyclProgram: """ Wraps a sycl::program object created from an OpenCL interoperability program. - SyclProgram exposes the C API from dppl_sycl_program_interface.h. A + SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A SyclProgram can be created from either a source string or a SPIR-V binary file. """ @staticmethod - cdef SyclProgram _create (DPPLSyclProgramRef pref): + cdef SyclProgram _create (DPCTLSyclProgramRef pref): cdef SyclProgram ret = SyclProgram.__new__(SyclProgram) ret._program_ref = pref return ret def __dealloc__ (self): - DPPLProgram_Delete(self._program_ref) + DPCTLProgram_Delete(self._program_ref) - cdef DPPLSyclProgramRef get_program_ref (self): + cdef DPCTLSyclProgramRef get_program_ref (self): return self._program_ref cpdef SyclKernel get_sycl_kernel(self, str kernel_name): name = kernel_name.encode('utf8') - return SyclKernel._create(DPPLProgram_GetKernel(self._program_ref, + return SyclKernel._create(DPCTLProgram_GetKernel(self._program_ref, name)) def has_sycl_kernel(self, str kernel_name): name = kernel_name.encode('utf8') - return DPPLProgram_HasKernel(self._program_ref, name) + return DPCTLProgram_HasKernel(self._program_ref, name) def addressof_ref (self): - """Returns the address of the C API DPPLSyclProgramRef pointer + """Returns the address of the C API DPCTLSyclProgramRef pointer as a long. Returns: - The address of the DPPLSyclProgramRef object used to create this + The address of the DPCTLSyclProgramRef object used to create this SyclProgram cast to a long. """ return int(self._program_ref) @@ -395,21 +395,21 @@ cdef class SyclQueue: """ @staticmethod - cdef SyclQueue _create (DPPLSyclQueueRef qref): + cdef SyclQueue _create (DPCTLSyclQueueRef qref): if qref is NULL: raise SyclQueueCreationError("Queue creation failed.") cdef SyclQueue ret = SyclQueue.__new__(SyclQueue) - ret._context = SyclContext._create(DPPLQueue_GetContext(qref)) - ret._device = SyclDevice._create(DPPLQueue_GetDevice(qref)) + ret._context = SyclContext._create(DPCTLQueue_GetContext(qref)) + ret._device = SyclDevice._create(DPCTLQueue_GetDevice(qref)) ret._queue_ref = qref return ret @staticmethod cdef SyclQueue _create_from_context_and_device(SyclContext ctx, SyclDevice dev): cdef SyclQueue ret = SyclQueue.__new__(SyclQueue) - cdef DPPLSyclContextRef cref = ctx.get_context_ref() - cdef DPPLSyclDeviceRef dref = dev.get_device_ref() - cdef DPPLSyclQueueRef qref = DPPLQueueMgr_GetQueueFromContextAndDevice( + cdef DPCTLSyclContextRef cref = ctx.get_context_ref() + cdef DPCTLSyclDeviceRef dref = dev.get_device_ref() + cdef DPCTLSyclQueueRef qref = DPCTLQueueMgr_GetQueueFromContextAndDevice( cref, dref) if qref is NULL: @@ -420,7 +420,7 @@ cdef class SyclQueue: return ret def __dealloc__ (self): - DPPLQueue_Delete(self._queue_ref) + DPCTLQueue_Delete(self._queue_ref) cdef _raise_queue_submit_error (self, fname, errcode): e = SyclKernelSubmitError("Kernel submission to Sycl queue failed.") @@ -437,7 +437,7 @@ cdef class SyclQueue: raise e cdef int _populate_args (self, list args, void **kargs, \ - DPPLKernelArgType *kargty): + DPCTLKernelArgType *kargty): cdef int ret = 0 for idx, arg in enumerate(args): if isinstance(arg, ctypes.c_char): @@ -509,12 +509,12 @@ cdef class SyclQueue: """ Returns true if the SyclQueue argument has the same _queue_ref as this SycleQueue. """ - return DPPLQueue_AreEq(self._queue_ref, q.get_queue_ref()) + return DPCTLQueue_AreEq(self._queue_ref, q.get_queue_ref()) def get_sycl_backend (self): """ Returns the Sycl bakend associated with the queue. """ - cdef DPPLSyclBackendType BE = DPPLQueue_GetBackend(self._queue_ref) + cdef DPCTLSyclBackendType BE = DPCTLQueue_GetBackend(self._queue_ref) if BE == _backend_type._OPENCL: return backend_type.opencl elif BE == _backend_type._LEVEL_ZERO: @@ -532,14 +532,14 @@ cdef class SyclQueue: cpdef SyclDevice get_sycl_device (self): return self._device - cdef DPPLSyclQueueRef get_queue_ref (self): + cdef DPCTLSyclQueueRef get_queue_ref (self): return self._queue_ref def addressof_ref (self): - """ Returns the address of the C API DPPLSyclQueueRef pointer as a long. + """ Returns the address of the C API DPCTLSyclQueueRef pointer as a long. Returns: - The address of the DPPLSyclQueueRef object used to create this + The address of the DPCTLSyclQueueRef object used to create this SyclQueue cast to a long. """ return int(self._queue_ref) @@ -548,9 +548,9 @@ cdef class SyclQueue: list lS = None, list dEvents = None): cdef void **kargs = NULL - cdef DPPLKernelArgType *kargty = NULL - cdef DPPLSyclEventRef *depEvents = NULL - cdef DPPLSyclEventRef Eref = NULL + cdef DPCTLKernelArgType *kargty = NULL + cdef DPCTLSyclEventRef *depEvents = NULL + cdef DPCTLSyclEventRef Eref = NULL cdef int ret cdef size_t gRange[3] cdef size_t lRange[3] @@ -558,17 +558,17 @@ cdef class SyclQueue: cdef size_t nLS = len(lS) if lS is not None else 0 cdef size_t nDE = len(dEvents) if dEvents is not None else 0 - # Allocate the arrays to be sent to DPPLQueue_Submit + # Allocate the arrays to be sent to DPCTLQueue_Submit kargs = malloc(len(args) * sizeof(void*)) if not kargs: raise MemoryError() - kargty = malloc(len(args)*sizeof(DPPLKernelArgType)) + kargty = malloc(len(args)*sizeof(DPCTLKernelArgType)) if not kargty: free(kargs) raise MemoryError() # Create the array of dependent events if any if dEvents is not None and nDE > 0: - depEvents = malloc(nDE*sizeof(DPPLSyclEventRef)) + depEvents = malloc(nDE*sizeof(DPCTLSyclEventRef)) if not depEvents: free(kargs) free(kargty) @@ -593,7 +593,7 @@ cdef class SyclQueue: free(depEvents) self._raise_invalid_range_error("SyclQueue.submit", nGS, -1) - Eref = DPPLQueue_SubmitRange(kernel.get_kernel_ref(), + Eref = DPCTLQueue_SubmitRange(kernel.get_kernel_ref(), self.get_queue_ref(), kargs, kargty, @@ -623,7 +623,7 @@ cdef class SyclQueue: raise ValueError("Local and global ranges need to have same " "number of dimensions.") - Eref = DPPLQueue_SubmitNDRange(kernel.get_kernel_ref(), + Eref = DPCTLQueue_SubmitNDRange(kernel.get_kernel_ref(), self.get_queue_ref(), kargs, kargty, @@ -639,12 +639,12 @@ cdef class SyclQueue: if Eref is NULL: # \todo get the error number from dpctl-capi - self._raise_queue_submit_error("DPPLQueue_Submit", -1) + self._raise_queue_submit_error("DPCTLQueue_Submit", -1) return SyclEvent._create(Eref, args) cpdef void wait (self): - DPPLQueue_Wait(self._queue_ref) + DPCTLQueue_Wait(self._queue_ref) cpdef memcpy (self, dest, src, size_t count): cdef void *c_dest @@ -660,7 +660,7 @@ cdef class SyclQueue: else: raise TypeError("Parameter `src` should have type _Memory.") - DPPLQueue_Memcpy(self._queue_ref, c_dest, c_src, count) + DPCTLQueue_Memcpy(self._queue_ref, c_dest, c_src, count) cpdef prefetch (self, mem, size_t count=0): cdef void *ptr @@ -673,7 +673,7 @@ cdef class SyclQueue: if (count <=0 or count > self.nbytes): count = self.nbytes - DPPLQueue_Prefetch(self._queue_ref, ptr, count) + DPCTLQueue_Prefetch(self._queue_ref, ptr, count) cpdef mem_advise (self, mem, size_t count, int advice): cdef void *ptr @@ -686,7 +686,7 @@ cdef class SyclQueue: if (count <=0 or count > self.nbytes): count = self.nbytes - DPPLQueue_MemAdvise(self._queue_ref, ptr, count, advice) + DPCTLQueue_MemAdvise(self._queue_ref, ptr, count, advice) cdef class _SyclRTManager: @@ -720,13 +720,13 @@ cdef class _SyclRTManager: } def _set_as_current_queue (self, backend_ty, device_ty, device_id): - cdef DPPLSyclQueueRef queue_ref + cdef DPCTLSyclQueueRef queue_ref try : beTy = self._backend_str_ty_dict[backend_ty] try : devTy = self._device_str_ty_dict[device_ty] - queue_ref = DPPLQueueMgr_PushQueue(beTy, devTy, device_id) + queue_ref = DPCTLQueueMgr_PushQueue(beTy, devTy, device_id) return SyclQueue._create(queue_ref) except KeyError: raise UnsupportedDeviceError("Device can only be gpu or cpu") @@ -735,12 +735,12 @@ cdef class _SyclRTManager: "level-0") def _remove_current_queue (self): - DPPLQueueMgr_PopQueue() + DPCTLQueueMgr_PopQueue() def dump (self): """ Prints information about the Runtime object. """ - DPPLPlatform_DumpInfo() + DPCTLPlatform_DumpInfo() def print_available_backends (self): """ Prints the available backends. @@ -760,17 +760,17 @@ cdef class _SyclRTManager: cpdef SyclQueue get_current_queue (self): """ Returns the activated SYCL queue as a PyCapsule. """ - return SyclQueue._create(DPPLQueueMgr_GetCurrentQueue()) + return SyclQueue._create(DPCTLQueueMgr_GetCurrentQueue()) def get_num_activated_queues (self): """ Return the number of currently activated queues for this thread. """ - return DPPLQueueMgr_GetNumActivatedQueues() + return DPCTLQueueMgr_GetNumActivatedQueues() def get_num_platforms (self): """ Returns the number of available non-host SYCL platforms. """ - return DPPLPlatform_GetNumNonHostPlatforms() + return DPCTLPlatform_GetNumNonHostPlatforms() def get_num_queues (self, backend_ty, device_ty): cdef size_t num = 0 @@ -778,7 +778,7 @@ cdef class _SyclRTManager: beTy = self._backend_enum_ty_dict[backend_ty] try : devTy = self._device_enum_ty_dict[device_ty] - num = DPPLQueueMgr_GetNumQueues(beTy, devTy) + num = DPCTLQueueMgr_GetNumQueues(beTy, devTy) except KeyError: raise UnsupportedDeviceError( "Device can only be device_type.gpu or device_type.cpu" @@ -795,7 +795,7 @@ cdef class _SyclRTManager: cdef size_t num = 0 try : beTy = self._backend_enum_ty_dict[backend_ty] - num = DPPLQueueMgr_GetNumQueues(beTy, _device_type._GPU) + num = DPCTLQueueMgr_GetNumQueues(beTy, _device_type._GPU) except KeyError: raise UnsupportedBackendError( "Backend can only be backend_type.opencl or " @@ -810,7 +810,7 @@ cdef class _SyclRTManager: cdef size_t num = 0 try : beTy = self._backend_enum_ty_dict[backend_ty] - num = DPPLQueueMgr_GetNumQueues(beTy, _device_type._CPU) + num = DPCTLQueueMgr_GetNumQueues(beTy, _device_type._CPU) except KeyError: raise UnsupportedBackendError( "Backend can only be backend_type.opencl or " @@ -822,21 +822,21 @@ cdef class _SyclRTManager: return False def has_sycl_platforms (self): - cdef size_t num_platforms = DPPLPlatform_GetNumNonHostPlatforms() + cdef size_t num_platforms = DPCTLPlatform_GetNumNonHostPlatforms() if num_platforms: return True else: return False def is_in_device_context (self): - cdef size_t num = DPPLQueueMgr_GetNumActivatedQueues() + cdef size_t num = DPCTLQueueMgr_GetNumActivatedQueues() if num: return True else: return False def set_default_queue (self, backend_ty, device_ty, device_id): - cdef DPPLSyclQueueRef ret + cdef DPCTLSyclQueueRef ret try : if isinstance(backend_ty, str): beTy = self._backend_str_ty_dict[backend_ty] @@ -847,11 +847,11 @@ cdef class _SyclRTManager: devTy = self._device_str_ty_dict[device_ty] else: devTyp = self._device_enum_ty_dist[device_ty] - ret = DPPLQueueMgr_SetAsDefaultQueue(beTy, devTy, device_id) + ret = DPCTLQueueMgr_SetAsDefaultQueue(beTy, devTy, device_id) if ret is NULL: self._raise_queue_creation_error( backend_ty, device_ty, device_id, - "DPPLQueueMgr_PushQueue" + "DPCTLQueueMgr_PushQueue" ) except KeyError: @@ -898,7 +898,7 @@ def create_program_from_source (SyclQueue q, unicode source, unicode copts=""): """ Creates a Sycl interoperability program from an OpenCL source string. - We use the DPPLProgram_CreateFromOCLSource() C API function to create + We use the DPCTLProgram_CreateFromOCLSource() C API function to create a Sycl progrma from an OpenCL source program that can contain multiple kernels. @@ -920,13 +920,13 @@ def create_program_from_source (SyclQueue q, unicode source, unicode copts=""): "OpenCL devices are supported for program creations." ) - cdef DPPLSyclProgramRef Pref + cdef DPCTLSyclProgramRef Pref cdef bytes bSrc = source.encode('utf8') cdef bytes bCOpts = copts.encode('utf8') cdef const char *Src = bSrc cdef const char *COpts = bCOpts - cdef DPPLSyclContextRef CRef = q.get_sycl_context().get_context_ref() - Pref = DPPLProgram_CreateFromOCLSource(CRef, Src, COpts) + cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() + Pref = DPCTLProgram_CreateFromOCLSource(CRef, Src, COpts) if Pref is NULL: raise SyclProgramCompilationError() @@ -939,7 +939,7 @@ def create_program_from_spirv (SyclQueue q, const unsigned char[:] IL): """ Creates a Sycl interoperability program from an SPIR-V binary. - We use the DPPLProgram_CreateFromOCLSpirv() C API function to create + We use the DPCTLProgram_CreateFromOCLSpirv() C API function to create a Sycl progrma from an compiled SPIR-V binary file. Parameters: @@ -957,11 +957,11 @@ def create_program_from_spirv (SyclQueue q, const unsigned char[:] IL): "OpenCL devices are supported for program creations." ) - cdef DPPLSyclProgramRef Pref + cdef DPCTLSyclProgramRef Pref cdef const unsigned char *dIL = &IL[0] - cdef DPPLSyclContextRef CRef = q.get_sycl_context().get_context_ref() + cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() cdef size_t length = IL.shape[0] - Pref = DPPLProgram_CreateFromOCLSpirv(CRef, dIL, length) + Pref = DPCTLProgram_CreateFromOCLSpirv(CRef, dIL, length) if Pref is NULL: raise SyclProgramCompilationError() diff --git a/dpctl/memory/_memory.pxd b/dpctl/memory/_memory.pxd index 231b2a9c18..7b5a8e1051 100644 --- a/dpctl/memory/_memory.pxd +++ b/dpctl/memory/_memory.pxd @@ -21,12 +21,12 @@ # distutils: language = c++ # cython: language_level=3 -from .._backend cimport DPPLSyclUSMRef +from .._backend cimport DPCTLSyclUSMRef from .._sycl_core cimport SyclQueue, SyclDevice, SyclContext cdef class _Memory: - cdef DPPLSyclUSMRef memory_ptr + cdef DPCTLSyclUSMRef memory_ptr cdef Py_ssize_t nbytes cdef SyclQueue queue cdef object refobj @@ -44,9 +44,9 @@ cdef class _Memory: cpdef bytes tobytes(self) @staticmethod - cdef SyclDevice get_pointer_device(DPPLSyclUSMRef p, SyclContext ctx) + cdef SyclDevice get_pointer_device(DPCTLSyclUSMRef p, SyclContext ctx) @staticmethod - cdef bytes get_pointer_type(DPPLSyclUSMRef p, SyclContext ctx) + cdef bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx) cdef class MemoryUSMShared(_Memory): diff --git a/dpctl/memory/_memory.pyx b/dpctl/memory/_memory.pyx index a5d82171f7..23c061f9e8 100644 --- a/dpctl/memory/_memory.pyx +++ b/dpctl/memory/_memory.pyx @@ -60,14 +60,14 @@ cdef void copy_via_host(void *dest_ptr, SyclQueue dest_queue, # could also have used bytearray(nbytes) cdef unsigned char[::1] host_buf = np.empty((nbytes,), dtype="|u1") - DPPLQueue_Memcpy( + DPCTLQueue_Memcpy( src_queue.get_queue_ref(), &host_buf[0], src_ptr, nbytes ) - DPPLQueue_Memcpy( + DPCTLQueue_Memcpy( dest_queue.get_queue_ref(), dest_ptr, &host_buf[0], @@ -80,7 +80,7 @@ cdef class _BufferData: Internal data struct populated from parsing `__sycl_usm_array_interface__` dictionary """ - cdef DPPLSyclUSMRef p + cdef DPCTLSyclUSMRef p cdef int writeable cdef object dt cdef Py_ssize_t itemsize @@ -123,7 +123,7 @@ cdef class _BufferData: buf = _BufferData.__new__(_BufferData) arr_data_ptr = ary_data_tuple[0] - buf.p = (arr_data_ptr) + buf.p = (arr_data_ptr) buf.writeable = 1 if ary_data_tuple[1] else 0 buf.itemsize = (dt.itemsize) buf.nbytes = (ary_shape[0]) * buf.itemsize @@ -171,7 +171,7 @@ cdef class _Memory: cdef _cinit_alloc(self, Py_ssize_t alignment, Py_ssize_t nbytes, bytes ptr_type, SyclQueue queue): - cdef DPPLSyclUSMRef p + cdef DPCTLSyclUSMRef p self._cinit_empty() @@ -181,22 +181,22 @@ cdef class _Memory: if (ptr_type == b"shared"): if alignment > 0: - p = DPPLaligned_alloc_shared(alignment, nbytes, + p = DPCTLaligned_alloc_shared(alignment, nbytes, queue.get_queue_ref()) else: - p = DPPLmalloc_shared(nbytes, queue.get_queue_ref()) + p = DPCTLmalloc_shared(nbytes, queue.get_queue_ref()) elif (ptr_type == b"host"): if alignment > 0: - p = DPPLaligned_alloc_host(alignment, nbytes, + p = DPCTLaligned_alloc_host(alignment, nbytes, queue.get_queue_ref()) else: - p = DPPLmalloc_host(nbytes, queue.get_queue_ref()) + p = DPCTLmalloc_host(nbytes, queue.get_queue_ref()) elif (ptr_type == b"device"): if (alignment > 0): - p = DPPLaligned_alloc_device(alignment, nbytes, + p = DPCTLaligned_alloc_device(alignment, nbytes, queue.get_queue_ref()) else: - p = DPPLmalloc_device(nbytes, queue.get_queue_ref()) + p = DPCTLmalloc_device(nbytes, queue.get_queue_ref()) else: raise RuntimeError("Pointer type is unknown: {}" \ .format(ptr_type.decode("UTF-8"))) @@ -243,14 +243,14 @@ cdef class _Memory: def __dealloc__(self): if (self.refobj is None and self.memory_ptr): - DPPLfree_with_queue(self.memory_ptr, + DPCTLfree_with_queue(self.memory_ptr, self.queue.get_queue_ref()) self._cinit_empty() cdef _getbuffer(self, Py_buffer *buffer, int flags): # memory_ptr is Ref which is pointer to SYCL type. For USM it is void*. cdef SyclContext ctx = self._context - cdef const char * kind = DPPLUSM_GetPointerType( + cdef const char * kind = DPCTLUSM_GetPointerType( self.memory_ptr, ctx.get_context_ref()) if kind == b'device': @@ -326,16 +326,16 @@ cdef class _Memory: cdef SyclQueue q if syclobj is None: ctx = self._context - kind = DPPLUSM_GetPointerType(self.memory_ptr, + kind = DPCTLUSM_GetPointerType(self.memory_ptr, ctx.get_context_ref()) elif isinstance(syclobj, SyclContext): ctx = (syclobj) - kind = DPPLUSM_GetPointerType(self.memory_ptr, + kind = DPCTLUSM_GetPointerType(self.memory_ptr, ctx.get_context_ref()) elif isinstance(syclobj, SyclQueue): q = (syclobj) ctx = q.get_sycl_context() - kind = DPPLUSM_GetPointerType(self.memory_ptr, + kind = DPCTLUSM_GetPointerType(self.memory_ptr, ctx.get_context_ref()) else: raise ValueError("syclobj keyword can be either None, " @@ -357,7 +357,7 @@ cdef class _Memory: raise ValueError("Destination object is too small to " "accommodate {} bytes".format(self.nbytes)) # call kernel to copy from - DPPLQueue_Memcpy( + DPCTLQueue_Memcpy( self.queue.get_queue_ref(), &host_buf[0], # destination self.memory_ptr, # source @@ -375,7 +375,7 @@ cdef class _Memory: raise ValueError("Source object is too large to be " "accommodated in {} bytes buffer".format(self.nbytes)) # call kernel to copy from - DPPLQueue_Memcpy( + DPCTLQueue_Memcpy( self.queue.get_queue_ref(), self.memory_ptr, # destination &host_buf[0], # source @@ -398,7 +398,7 @@ cdef class _Memory: if (src_buf.nbytes > self.nbytes): raise ValueError("Source object is too large to " "be accommondated in {} bytes buffer".format(self.nbytes)) - kind = DPPLUSM_GetPointerType( + kind = DPCTLUSM_GetPointerType( src_buf.p, self.queue.get_sycl_context().get_context_ref()) if (kind == b'unknown'): copy_via_host( @@ -407,7 +407,7 @@ cdef class _Memory: src_buf.nbytes ) else: - DPPLQueue_Memcpy( + DPCTLQueue_Memcpy( self.queue.get_queue_ref(), self.memory_ptr, src_buf.p, @@ -428,16 +428,16 @@ cdef class _Memory: return b @staticmethod - cdef SyclDevice get_pointer_device(DPPLSyclUSMRef p, SyclContext ctx): + cdef SyclDevice get_pointer_device(DPCTLSyclUSMRef p, SyclContext ctx): """Returns sycl device used to allocate given pointer `p` in given sycl context `ctx`""" - cdef DPPLSyclDeviceRef dref = DPPLUSM_GetPointerDevice(p, ctx.get_context_ref()) + cdef DPCTLSyclDeviceRef dref = DPCTLUSM_GetPointerDevice(p, ctx.get_context_ref()) return SyclDevice._create(dref) @staticmethod - cdef bytes get_pointer_type(DPPLSyclUSMRef p, SyclContext ctx): + cdef bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx): """Returns USM-type of given pointer `p` in given sycl context `ctx`""" - cdef const char * usm_type = DPPLUSM_GetPointerType(p, ctx.get_context_ref()) + cdef const char * usm_type = DPCTLUSM_GetPointerType(p, ctx.get_context_ref()) return usm_type diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index e222a55542..1b1229c39a 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -1,4 +1,4 @@ -##===------------- test_sycl_device.py - dpctl -------*- Python -*---------===## +##===------------ test_sycl_device.py - dpctl -------*- Python -*---------===## ## ## Data Parallel Control (dpctl) ## diff --git a/examples/cython/sycl_buffer/_buffer_example.pyx b/examples/cython/sycl_buffer/_buffer_example.pyx index d1ade59c92..f2f01d0d24 100644 --- a/examples/cython/sycl_buffer/_buffer_example.pyx +++ b/examples/cython/sycl_buffer/_buffer_example.pyx @@ -5,15 +5,15 @@ cimport dpctl as c_dpctl import dpctl cdef extern from "use_sycl_buffer.h": - int c_columnwise_total(c_dpctl.DPPLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil - int c_columnwise_total_no_mkl(c_dpctl.DPPLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil + int c_columnwise_total(c_dpctl.DPCTLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil + int c_columnwise_total_no_mkl(c_dpctl.DPCTLSyclQueueRef q, size_t n, size_t m, double *m, double *ct) nogil def columnwise_total(double[:, ::1] v, method='mkl'): cdef cnp.ndarray res_array = np.empty((v.shape[1],), dtype='d') cdef double[::1] res_memslice = res_array cdef int ret_status cdef c_dpctl.SyclQueue q - cdef c_dpctl.DPPLSyclQueueRef q_ref + cdef c_dpctl.DPCTLSyclQueueRef q_ref q = c_dpctl.get_current_queue() q_ref = q.get_queue_ref() diff --git a/examples/cython/sycl_buffer/use_sycl_buffer.cpp b/examples/cython/sycl_buffer/use_sycl_buffer.cpp index 0c42332ea7..c49e8b3204 100644 --- a/examples/cython/sycl_buffer/use_sycl_buffer.cpp +++ b/examples/cython/sycl_buffer/use_sycl_buffer.cpp @@ -1,10 +1,10 @@ #include #include "use_sycl_buffer.h" #include -#include "dppl_sycl_types.h" +#include "dpctl_sycl_types.h" int -c_columnwise_total(DPPLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { +c_columnwise_total(DPCTLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { sycl::queue q = *(reinterpret_cast(q_ref)); @@ -56,7 +56,7 @@ c_columnwise_total(DPPLSyclQueueRef q_ref, size_t n, size_t m, double *mat, doub inline size_t upper_multiple(size_t n, size_t wg) { return wg * ((n + wg - 1)/wg); } int -c_columnwise_total_no_mkl(DPPLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { +c_columnwise_total_no_mkl(DPCTLSyclQueueRef q_ref, size_t n, size_t m, double *mat, double *ct) { sycl::queue q = *(reinterpret_cast(q_ref)); diff --git a/examples/cython/sycl_buffer/use_sycl_buffer.h b/examples/cython/sycl_buffer/use_sycl_buffer.h index f3ee924861..51ef63eab9 100644 --- a/examples/cython/sycl_buffer/use_sycl_buffer.h +++ b/examples/cython/sycl_buffer/use_sycl_buffer.h @@ -1,7 +1,7 @@ #include -#include "dppl_sycl_types.h" +#include "dpctl_sycl_types.h" extern int c_columnwise_total( - DPPLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); + DPCTLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); extern int c_columnwise_total_no_mkl( - DPPLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); + DPCTLSyclQueueRef q, size_t n, size_t m, double *mat, double *ct); diff --git a/examples/cython/usm_memory/blackscholes.pyx b/examples/cython/usm_memory/blackscholes.pyx index 6495265461..ab9b8da9f3 100644 --- a/examples/cython/usm_memory/blackscholes.pyx +++ b/examples/cython/usm_memory/blackscholes.pyx @@ -10,14 +10,14 @@ import dpctl import numpy as np cdef extern from "sycl_blackscholes.hpp": - cdef void cpp_blackscholes[T](c_dpctl.DPPLSyclQueueRef, size_t n_opts, T* option_params, T* callput) - cdef void cpp_populate_params[T](c_dpctl.DPPLSyclQueueRef, size_t n_opts, T* option_params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) + cdef void cpp_blackscholes[T](c_dpctl.DPCTLSyclQueueRef, size_t n_opts, T* option_params, T* callput) + cdef void cpp_populate_params[T](c_dpctl.DPCTLSyclQueueRef, size_t n_opts, T* option_params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) def black_scholes_price(floating[:, ::1] option_params): cdef size_t n_opts = option_params.shape[0] cdef size_t n_params = option_params.shape[1] cdef c_dpctl.SyclQueue q - cdef c_dpctl.DPPLSyclQueueRef q_ptr + cdef c_dpctl.DPCTLSyclQueueRef q_ptr cdef c_dpctl_mem.MemoryUSMShared mobj cdef floating[:, :] call_put_prices cdef cnp.ndarray callput_arr @@ -56,7 +56,7 @@ def populate_params(floating[:, ::1] option_params, pl, ph, sl, sh, tl, th, rl, cdef size_t n_params = option_params.shape[1] cdef c_dpctl.SyclQueue q - cdef c_dpctl.DPPLSyclQueueRef q_ptr + cdef c_dpctl.DPCTLSyclQueueRef q_ptr cdef double* dp cdef float* fp diff --git a/examples/cython/usm_memory/sycl_blackscholes.cpp b/examples/cython/usm_memory/sycl_blackscholes.cpp index 550a01c622..734aabdd1d 100644 --- a/examples/cython/usm_memory/sycl_blackscholes.cpp +++ b/examples/cython/usm_memory/sycl_blackscholes.cpp @@ -1,5 +1,5 @@ #include -#include "dppl_sycl_types.h" +#include "dpctl_sycl_types.h" #include "sycl_blackscholes.hpp" #include "mkl_rng_sycl_device.hpp" @@ -19,7 +19,7 @@ constexpr int CALL = 0; constexpr int PUT = 1; template -extern void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T* callput) { +extern void cpp_blackscholes(DPCTLSyclQueueRef q_ptr, size_t n_opts, T* params, T* callput) { using data_t = T; sycl::queue q = *(reinterpret_cast(q_ptr)); @@ -100,7 +100,7 @@ extern void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T } template -void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) { +void cpp_populate_params(DPCTLSyclQueueRef q_ptr, size_t n_opts, T* params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed) { sycl::queue q = *(reinterpret_cast(q_ptr)); auto ctx = q.get_context(); @@ -158,13 +158,13 @@ void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, T* params, T pl, // instantation for object files to not be empty -template void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, double* params, double* callput); -template void cpp_blackscholes(DPPLSyclQueueRef q_ptr, size_t n_opts, float* params, float* callput); +template void cpp_blackscholes(DPCTLSyclQueueRef q_ptr, size_t n_opts, double* params, double* callput); +template void cpp_blackscholes(DPCTLSyclQueueRef q_ptr, size_t n_opts, float* params, float* callput); -template void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, double* params, +template void cpp_populate_params(DPCTLSyclQueueRef q_ptr, size_t n_opts, double* params, double pl, double ph, double sl, double sh, double tl, double th, double rl, double rh, double vl, double vh, int seed); -template void cpp_populate_params(DPPLSyclQueueRef q_ptr, size_t n_opts, float* params, +template void cpp_populate_params(DPCTLSyclQueueRef q_ptr, size_t n_opts, float* params, float pl, float ph, float sl, float sh, float tl, float th, float rl, float rh, float vl, float vh, int seed); diff --git a/examples/cython/usm_memory/sycl_blackscholes.hpp b/examples/cython/usm_memory/sycl_blackscholes.hpp index 36594810dc..bf3fbf849c 100644 --- a/examples/cython/usm_memory/sycl_blackscholes.hpp +++ b/examples/cython/usm_memory/sycl_blackscholes.hpp @@ -1,10 +1,10 @@ #include -#include "dppl_sycl_types.h" +#include "dpctl_sycl_types.h" template -extern void cpp_blackscholes(DPPLSyclQueueRef q, size_t n_opts, T* params, T* callput); +extern void cpp_blackscholes(DPCTLSyclQueueRef q, size_t n_opts, T* params, T* callput); template -extern void cpp_populate_params(DPPLSyclQueueRef q, size_t n_opts, T* params, +extern void cpp_populate_params(DPCTLSyclQueueRef q, size_t n_opts, T* params, T pl, T ph, T sl, T sh, T tl, T th, T rl, T rh, T vl, T vh, int seed); diff --git a/scripts/build_backend.py b/scripts/build_backend.py index 57d9cd3ef0..ac61a52b98 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -32,7 +32,7 @@ if os.path.exists(INSTALL_PREFIX): shutil.rmtree(INSTALL_PREFIX) -backends_dir = os.path.join(dpctl_dir, "backends") +backends = os.path.join(dpctl_dir, "dpctl-capi") if IS_LIN: cmake_args = [ @@ -43,7 +43,7 @@ "-DDPCPP_ROOT=" + DPCPP_ROOT, "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"), "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang++"), - backends_dir, + backends, ] subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) subprocess.check_call(["make", "-j", "4"]) @@ -62,7 +62,7 @@ "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, "-DDPCPP_ROOT=" + DPCPP_ROOT, - backends_dir, + backends, ] subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=True) subprocess.check_call(["ninja", "-n"]) @@ -79,4 +79,4 @@ if os.path.exists(include_dir): shutil.rmtree(include_dir) -shutil.copytree(os.path.join(dpctl_dir, "backends", "include"), include_dir) +shutil.copytree(os.path.join(dpctl_dir, "dpctl-capi", "include"), include_dir) diff --git a/scripts/build_for_develop.bat b/scripts/build_for_develop.bat index 3cd73f3546..17c4fe1e70 100644 --- a/scripts/build_for_develop.bat +++ b/scripts/build_for_develop.bat @@ -34,7 +34,7 @@ cmake -G Ninja ^ "-DCMAKE_C_COMPILER:PATH=%DPCPP_ROOT%\bin\clang-cl.exe" ^ "-DCMAKE_CXX_COMPILER:PATH=%DPCPP_ROOT%\bin\dpcpp.exe" ^ "-DBUILD_CAPI_TESTS=%_BUILD_CAPI_TEST%" ^ - "%cd%\..\backends" + "%cd%\..\dpctl-capi" IF %ERRORLEVEL% NEQ 0 exit /b 1 ninja -n @@ -51,12 +51,12 @@ xcopy install\lib\*.lib dpctl /E /Y xcopy install\bin\*.dll dpctl /E /Y mkdir dpctl\include -xcopy backends\include dpctl\include /E /Y +xcopy dpctl-capi\include dpctl\include /E /Y REM required by _sycl_core(dpctl) -set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl" -set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include" +set "DPCTL_SYCL_INTERFACE_LIBDIR=dpctl" +set "DPCTL_SYCL_INTERFACE_INCLDIR=dpctl\include" set "CC=clang-cl.exe" set "CXX=dpcpp.exe" diff --git a/scripts/build_for_develop.sh b/scripts/build_for_develop.sh index 8fd1a04c62..0154782c9c 100755 --- a/scripts/build_for_develop.sh +++ b/scripts/build_for_develop.sh @@ -18,7 +18,7 @@ cmake \ -DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \ -DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \ -DBUILD_CAPI_TESTS=ON \ - ../backends + ../dpctl-capi make V=1 -n -j 4 && make check && make install @@ -31,10 +31,10 @@ popd cp install/lib/*.so dpctl/ mkdir -p dpctl/include -cp -r backends/include/* dpctl/include +cp -r dpctl-capi/include/* dpctl/include -export DPPL_SYCL_INTERFACE_LIBDIR=dpctl -export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include +export DPCTL_SYCL_INTERFACE_LIBDIR=dpctl +export DPCTL_SYCL_INTERFACE_INCLDIR=dpctl/include export CC=${DPCPP_ROOT}/bin/clang export CXX=${DPCPP_ROOT}/bin/dpcpp diff --git a/setup.cfg b/setup.cfg index 59be40a5ed..f360aaf2d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,7 +23,7 @@ VCS = git versionfile_source = dpctl/_version.py versionfile_build = dpctl/_version.py tag_prefix = -parentdir_prefix = DPPL- +parentdir_prefix = DPCTL- [bdist_wheel] universal=1 diff --git a/setup.py b/setup.py index f358b4ed43..087d78f4dd 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -##===---------- setup.py - dpctl.ocldrv interface -----*- Python -*-----===## +##===------------- setup.py - dpctl.ocldrv interface -----*- Python -*-----===## ## ## Data Parallel Control Library (dpCtl) ## @@ -55,18 +55,18 @@ DPCPP_ROOT = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux" os.environ["CC"] = DPCPP_ROOT + "/bin/clang" os.environ["CXX"] = DPCPP_ROOT + "/bin/clang++" - os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" + os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" os.environ["CFLAGS"] = "-fPIC" elif IS_WIN: os.environ["CC"] = "clang-cl.exe" os.environ["CXX"] = "dpcpp.exe" - os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" + os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" -dppl_sycl_interface_lib = os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] -dppl_sycl_interface_include = os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] +dpctl_sycl_interface_lib = os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"] +dpctl_sycl_interface_include = os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"] sycl_lib = os.environ["ONEAPI_ROOT"] + "\compiler\latest\windows\lib" @@ -129,18 +129,18 @@ def extensions(): librarys = [] if IS_LIN: - libs += ["rt", "DPPLSyclInterface"] + libs += ["rt", "DPCTLSyclInterface"] elif IS_MAC: pass elif IS_WIN: - libs += ["DPPLSyclInterface", "sycl"] + libs += ["DPCTLSyclInterface", "sycl"] if IS_LIN: - librarys = [dppl_sycl_interface_lib] + librarys = [dpctl_sycl_interface_lib] elif IS_WIN: - librarys = [dppl_sycl_interface_lib, sycl_lib] + librarys = [dpctl_sycl_interface_lib, sycl_lib] elif IS_MAC: - librarys = [dppl_sycl_interface_lib] + librarys = [dpctl_sycl_interface_lib] if IS_LIN or IS_MAC: runtime_library_dirs = ["$ORIGIN"] @@ -149,9 +149,9 @@ def extensions(): extension_args = { "depends": [ - dppl_sycl_interface_include, + dpctl_sycl_interface_include, ], - "include_dirs": [np.get_include(), dppl_sycl_interface_include], + "include_dirs": [np.get_include(), dpctl_sycl_interface_include], "extra_compile_args": eca + get_other_cxxflags() + get_suppressed_warning_flags(), From 7f43d4ac08c9e05ffd91deba227245040b2ebad8 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Thu, 3 Dec 2020 14:22:24 -0600 Subject: [PATCH 5/8] Refactoring the backend functions to prep for changes to add L0 support. --- .../include/dpctl_sycl_program_interface.h | 9 +- .../source/dpctl_sycl_program_interface.cpp | 113 ++++++++++++------ 2 files changed, 83 insertions(+), 39 deletions(-) diff --git a/dpctl-capi/include/dpctl_sycl_program_interface.h b/dpctl-capi/include/dpctl_sycl_program_interface.h index febffdbc1e..c931b4b166 100644 --- a/dpctl-capi/include/dpctl_sycl_program_interface.h +++ b/dpctl-capi/include/dpctl_sycl_program_interface.h @@ -41,11 +41,10 @@ DPCTL_C_EXTERN_C_BEGIN * @brief Create a Sycl program from an OpenCL SPIR-V binary file. * * Sycl 1.2 does not expose any method to create a sycl::program from a SPIR-V - * IL file. To get around this limitation, we need to use the Sycl feature to - * create an interoperability kernel from an OpenCL kernel. This function first - * creates an OpenCL program and kernel from the SPIR-V binary and then using - * the Sycl-OpenCL interoperability feature creates a Sycl kernel from the - * OpenCL kernel. + * IL file. To get around this limitation, we first creare a SYCL + * interoperability program and then create a SYCL program from the + * interoperability program. Currently, interoperability programs can be created + * for OpenCL and Level-0 backends. * * The feature to create a Sycl kernel from a SPIR-V IL binary will be available * in Sycl 2.0 at which point this function may become deprecated. diff --git a/dpctl-capi/source/dpctl_sycl_program_interface.cpp b/dpctl-capi/source/dpctl_sycl_program_interface.cpp index d7dae83e0f..700628d8e3 100644 --- a/dpctl-capi/source/dpctl_sycl_program_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_program_interface.cpp @@ -38,22 +38,13 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(program, DPCTLSyclProgramRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) -} /* end of anonymous namespace */ - -__dpctl_give DPCTLSyclProgramRef -DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef, - __dpctl_keep const void *IL, - size_t length) +__dppl_give DPCTLSyclProgramRef +createOpenCLInterOpProgram (const context &SyclCtx, + __dppl_keep const void *IL, + size_t length) { cl_int err; - context *SyclCtx; - if(!CtxRef) { - // \todo handle error - return nullptr; - } - - SyclCtx = unwrap(CtxRef); - auto CLCtx = SyclCtx->get(); + auto CLCtx = SyclCtx.get(); auto CLProgram = clCreateProgramWithIL(CLCtx, IL, length, &err); if (err) { // \todo: record the error string and any other information. @@ -61,7 +52,7 @@ DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef, "binary. OpenCL Error " << err << ".\n"; return nullptr; } - auto SyclDevices = SyclCtx->get_devices(); + auto SyclDevices = SyclCtx.get_devices(); // Get a list of CL Devices from the Sycl devices auto CLDevices = new cl_device_id[SyclDevices.size()]; @@ -83,18 +74,50 @@ DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef, // Create the Sycl program from OpenCL program try { - auto SyclProgram = new program(*SyclCtx, CLProgram); + auto SyclProgram = new program(SyclCtx, CLProgram); return wrap(SyclProgram); - } catch (invalid_object_error) { + } catch (invalid_object_error &e) { // \todo record error + std::cerr << e.what() << '\n'; return nullptr; } } -__dpctl_give DPCTLSyclProgramRef -DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx, - __dpctl_keep const char *Source, - __dpctl_keep const char *CompileOpts) +} /* end of anonymous namespace */ + +__dppl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef CtxRef, + __dppl_keep const void *IL, + size_t length) +{ + DPPLSyclProgramRef Pref = nullptr; + context *SyclCtx = nullptr; + if(!CtxRef) { + // \todo handle error + return Pref; + } + + SyclCtx = unwrap(CtxRef); + // get the backend type + auto BE = SyclCtx->get_platform().get_backend(); + switch (BE) + { + case backend::opencl: + Pref = createOpenCLInterOpProgram(*SyclCtx, IL, length); + break; + case backend::level_zero: + break; + default: + break; + } + + return Pref; +} + +__dppl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, + __dppl_keep const char *Source, + __dppl_keep const char *CompileOpts) { std::string compileOpts; context *SyclCtx = nullptr; @@ -118,23 +141,43 @@ DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx, compileOpts = CompileOpts; } - try{ - SyclProgram->build_with_source(source, compileOpts); - return wrap(SyclProgram); - } catch (compile_program_error) { - delete SyclProgram; - // \todo record error + // get the backend type + auto BE = SyclCtx->get_platform().get_backend(); + switch (BE) + { + case backend::opencl: + try { + SyclProgram->build_with_source(source, compileOpts); + return wrap(SyclProgram); + } catch (compile_program_error &e) { + std::cerr << e.what() << '\n'; + delete SyclProgram; + // \todo record error + return nullptr; + } catch (feature_not_supported &e) { + std::cerr << e.what() << '\n'; + delete SyclProgram; + // \todo record error + return nullptr; + } catch (runtime_error &e) { + std::cerr << e.what() << '\n'; + delete SyclProgram; + // \todo record error + return nullptr; + } + break; + case backend::level_zero: + std::cerr << "CreateFromSource is not supported in Level Zero.\n"; return nullptr; - } catch (feature_not_supported) { - delete SyclProgram; - // \todo record error + default: + std::cerr << "CreateFromSource is not supported in unknown backend.\n"; return nullptr; } } __dpctl_give DPCTLSyclKernelRef DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef, - __dpctl_keep const char *KernelName) + __dpctl_keep const char *KernelName) { if(!PRef) { // \todo record error @@ -149,15 +192,16 @@ DPCTLProgram_GetKernel (__dpctl_keep DPCTLSyclProgramRef PRef, try { auto SyclKernel = new kernel(SyclProgram->get_kernel(name)); return wrap(SyclKernel); - } catch (invalid_object_error) { + } catch (invalid_object_error &e) { // \todo record error + std::cerr << e.what() << '\n'; return nullptr; } } bool DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef, - __dpctl_keep const char *KernelName) + __dpctl_keep const char *KernelName) { if(!PRef) { // \todo handle error @@ -167,7 +211,8 @@ DPCTLProgram_HasKernel (__dpctl_keep DPCTLSyclProgramRef PRef, auto SyclProgram = unwrap(PRef); try { return SyclProgram->has_kernel(KernelName); - } catch (invalid_object_error) { + } catch (invalid_object_error &e) { + std::cerr << e.what() << '\n'; return false; } } From fe7b59a0d32a3efd1579fef9b52ab42ad60dd7d7 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Thu, 3 Dec 2020 14:43:23 -0600 Subject: [PATCH 6/8] Minor formatting edits. --- dpctl/__init__.pxd | 51 ++++++++++++++++++------------------ dpctl/__init__.py | 48 +++++++++++++++++----------------- dpctl/_backend.pxd | 50 ++++++++++++++++++------------------ dpctl/memory/__init__.pxd | 50 ++++++++++++++++++------------------ dpctl/memory/__init__.py | 50 ++++++++++++++++++------------------ dpctl/memory/_memory.pxd | 38 +++++++++++++-------------- dpctl/memory/_memory.pyx | 54 +++++++++++++++++++-------------------- 7 files changed, 170 insertions(+), 171 deletions(-) diff --git a/dpctl/__init__.pxd b/dpctl/__init__.pxd index 87a5878b3f..f4467c606e 100644 --- a/dpctl/__init__.pxd +++ b/dpctl/__init__.pxd @@ -1,32 +1,31 @@ -##===-------------- __init__.pxd - dpctl module --------*- Cython -*-------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file declares the extension types and functions for the Cython API -## implemented in sycl_core.pyx. -## -##===----------------------------------------------------------------------===## +#===------------- __init__.pxd - dpctl module --------*- Cython -*----------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file declares the extension types and functions for the Cython API +# implemented in sycl_core.pyx. +# +#===------------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 from dpctl._sycl_core cimport * from dpctl._memory import * - diff --git a/dpctl/__init__.py b/dpctl/__init__.py index a06c121057..db52c956c0 100644 --- a/dpctl/__init__.py +++ b/dpctl/__init__.py @@ -1,27 +1,27 @@ -##===----------------- __init__.py - dpctl module -------*- Cython -*------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This top-level dpctl module. -## -##===----------------------------------------------------------------------===## +#===----------------- __init__.py - dpctl module -------*- Cython -*--------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# The top-level dpctl module. +# +#===------------------------------------------------------------------------===# """ **Data Parallel Control (dpCtl)** diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 4922086eca..21efe767f2 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -1,28 +1,28 @@ -##===------------- backend.pyx - dpctl module -------*- Cython -*----------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file defines the Cython extern types for the functions and opaque data -## types defined by dpctl's C API. -## -##===----------------------------------------------------------------------===## +#===------------- backend.pyx - dpctl module -------*- Cython -*------------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file defines the Cython extern types for the functions and opaque data +# types defined by dpctl's C API. +# +#===------------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/memory/__init__.pxd b/dpctl/memory/__init__.pxd index 62b84d5eba..23768f3b3e 100644 --- a/dpctl/memory/__init__.pxd +++ b/dpctl/memory/__init__.pxd @@ -1,28 +1,28 @@ -##===----------- __init__.pxd - dpctl.memory module ----*- Cython -*-------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file declares the extension types and functions for the Cython API -## implemented in dpctl.memory_memory.pyx. -## -##===----------------------------------------------------------------------===## +#===----------- __init__.pxd - dpctl.memory module ----*- Cython -*---------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file declares the extension types and functions for the Cython API +# implemented in dpctl.memory._memory.pyx. +# +#===------------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/memory/__init__.py b/dpctl/memory/__init__.py index fc8c25f217..6541c406e9 100644 --- a/dpctl/memory/__init__.py +++ b/dpctl/memory/__init__.py @@ -1,28 +1,28 @@ -##===---------- __init__.py - dpctl.memory module -------*- Python -*------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This is the dpctl.memory module containing the USM memory manager features -## of dpctl. -## -##===----------------------------------------------------------------------===## +#===---------- __init__.py - dpctl.memory module -------*- Python -*--------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This is the dpctl.memory module containing the USM memory manager features +# of dpctl. +# +#===------------------------------------------------------------------------===# """ **Data Parallel Control Memory** diff --git a/dpctl/memory/_memory.pxd b/dpctl/memory/_memory.pxd index 7b5a8e1051..6140a25f87 100644 --- a/dpctl/memory/_memory.pxd +++ b/dpctl/memory/_memory.pxd @@ -1,22 +1,22 @@ -##===--------------- _memory.pxd - dpctl module --------*- Cython -*-------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## +#===--------------- _memory.pxd - dpctl module --------*- Cython -*---------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/memory/_memory.pyx b/dpctl/memory/_memory.pyx index 23c061f9e8..fb121e3c3d 100644 --- a/dpctl/memory/_memory.pyx +++ b/dpctl/memory/_memory.pyx @@ -1,29 +1,29 @@ -##===--------------- _memory.pyx - dpctl module --------*- Cython -*-------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file implements Python buffer protocol using Sycl USM shared and host -## allocators. The USM device allocator is also exposed through this module for -## use in other Python modules. -## -##===----------------------------------------------------------------------===## +#===--------------- _memory.pyx - dpctl module --------*- Cython -*---------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file implements Python buffer protocol using Sycl USM shared and host +# allocators. The USM device allocator is also exposed through this module for +# use in other Python modules. +# +#===------------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 @@ -440,7 +440,7 @@ cdef class _Memory: cdef const char * usm_type = DPCTLUSM_GetPointerType(p, ctx.get_context_ref()) return usm_type - + cdef class MemoryUSMShared(_Memory): """ From 8ddfa5c49dd32ef65daadbacc637855d551b7d52 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Thu, 3 Dec 2020 15:54:03 -0600 Subject: [PATCH 7/8] Move SyclKernel, SyclProgram, program creation functions into a separate sub-module. --- .../source/dpctl_sycl_program_interface.cpp | 20 +- dpctl/_sycl_core.pxd | 79 +++---- dpctl/_sycl_core.pyx | 214 ++---------------- dpctl/program/__init__.pxd | 30 +++ dpctl/program/__init__.py | 36 +++ dpctl/program/_program.pxd | 63 ++++++ dpctl/program/_program.pyx | 186 +++++++++++++++ dpctl/tests/test_sycl_kernel_submit.py | 3 +- dpctl/tests/test_sycl_program.py | 20 +- setup.py | 53 +++-- 10 files changed, 414 insertions(+), 290 deletions(-) create mode 100644 dpctl/program/__init__.pxd create mode 100644 dpctl/program/__init__.py create mode 100644 dpctl/program/_program.pxd create mode 100644 dpctl/program/_program.pyx diff --git a/dpctl-capi/source/dpctl_sycl_program_interface.cpp b/dpctl-capi/source/dpctl_sycl_program_interface.cpp index 700628d8e3..7f8b75cf63 100644 --- a/dpctl-capi/source/dpctl_sycl_program_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_program_interface.cpp @@ -38,9 +38,9 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(program, DPCTLSyclProgramRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) -__dppl_give DPCTLSyclProgramRef +__dpctl_give DPCTLSyclProgramRef createOpenCLInterOpProgram (const context &SyclCtx, - __dppl_keep const void *IL, + __dpctl_keep const void *IL, size_t length) { cl_int err; @@ -85,12 +85,12 @@ createOpenCLInterOpProgram (const context &SyclCtx, } /* end of anonymous namespace */ -__dppl_give DPCTLSyclProgramRef -DPCTLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef CtxRef, - __dppl_keep const void *IL, +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSpirv (__dpctl_keep const DPCTLSyclContextRef CtxRef, + __dpctl_keep const void *IL, size_t length) { - DPPLSyclProgramRef Pref = nullptr; + DPCTLSyclProgramRef Pref = nullptr; context *SyclCtx = nullptr; if(!CtxRef) { // \todo handle error @@ -114,10 +114,10 @@ DPCTLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef CtxRef, return Pref; } -__dppl_give DPCTLSyclProgramRef -DPCTLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, - __dppl_keep const char *Source, - __dppl_keep const char *CompileOpts) +__dpctl_give DPCTLSyclProgramRef +DPCTLProgram_CreateFromOCLSource (__dpctl_keep const DPCTLSyclContextRef Ctx, + __dpctl_keep const char *Source, + __dpctl_keep const char *CompileOpts) { std::string compileOpts; context *SyclCtx = nullptr; diff --git a/dpctl/_sycl_core.pxd b/dpctl/_sycl_core.pxd index 66767d9620..cbc82fa8dc 100644 --- a/dpctl/_sycl_core.pxd +++ b/dpctl/_sycl_core.pxd @@ -1,33 +1,34 @@ -##===------------- sycl_core.pxd - dpctl module --------*- Cython -*-------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file declares the extension types and functions for the Cython API -## implemented in sycl_core.pyx. -## -##===----------------------------------------------------------------------===## +# ===------------- sycl_core.pxd - dpctl module --------*- Cython -*--------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# This file declares the extension types and functions for the Cython API +# implemented in sycl_core.pyx. +# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 from ._backend cimport * +from .program._program cimport SyclKernel from libc.stdint cimport uint32_t @@ -85,34 +86,6 @@ cdef class SyclEvent: cpdef void wait (self) -cdef class SyclKernel: - ''' Wraps a sycl::kernel object created from an OpenCL interoperability - kernel. - ''' - cdef DPCTLSyclKernelRef _kernel_ref - cdef const char *_function_name - cdef DPCTLSyclKernelRef get_kernel_ref (self) - - @staticmethod - cdef SyclKernel _create (DPCTLSyclKernelRef kref) - - -cdef class SyclProgram: - ''' Wraps a sycl::program object created from an OpenCL interoperability - program. - - SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A - SyclProgram can be created from either a source string or a SPIR-V - binary file. - ''' - cdef DPCTLSyclProgramRef _program_ref - - @staticmethod - cdef SyclProgram _create (DPCTLSyclProgramRef pref) - cdef DPCTLSyclProgramRef get_program_ref (self) - cpdef SyclKernel get_sycl_kernel(self, str kernel_name) - - cdef class SyclQueue: ''' Wrapper class for a Sycl queue. ''' diff --git a/dpctl/_sycl_core.pyx b/dpctl/_sycl_core.pyx index de19924ed1..997ec0edef 100644 --- a/dpctl/_sycl_core.pyx +++ b/dpctl/_sycl_core.pyx @@ -1,27 +1,27 @@ -##===------------- sycl_core.pyx - dpctl module -------*- Cython -*--------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## This file implements a sub-set of Sycl's interface using dpctl's CAPI. -## -##===----------------------------------------------------------------------===## +# ===------------ sycl_core.pyx - dpctl module -------*- Cython -*----------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# This file implements a sub-set of Sycl's interface using dpctl's CAPI. +# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 @@ -46,16 +46,12 @@ __all__ = [ "has_sycl_platforms", "set_default_queue", "is_in_device_context", - "create_program_from_source", - "create_program_from_spirv", "device_type", "backend_type", "device_context", "SyclContext", "SyclDevice", "SyclEvent", - "SyclKernel", - "SyclProgram", "SyclQueue" ] @@ -92,12 +88,6 @@ cdef class UnsupportedDeviceError (Exception): """ pass -cdef class SyclProgramCompilationError (Exception): - """This exception is raised when a sycl program could not be built from - either a spirv binary file or a string source. - """ - pass - cdef class SyclKernelSubmitError (Exception): """This exception is raised when a sycl program could not be built from either a spirv binary file or a string source. @@ -306,88 +296,6 @@ cdef class SyclEvent: """ return int(self._event_ref) - -cdef class SyclKernel: - """ Wraps a sycl::kernel object created from an OpenCL interoperability - kernel. - """ - - @staticmethod - cdef SyclKernel _create (DPCTLSyclKernelRef kref): - cdef SyclKernel ret = SyclKernel.__new__(SyclKernel) - ret._kernel_ref = kref - ret._function_name = DPCTLKernel_GetFunctionName(kref) - return ret - - def __dealloc__ (self): - DPCTLKernel_Delete(self._kernel_ref) - DPCTLCString_Delete(self._function_name) - - def get_function_name (self): - """ Returns the name of the Kernel function. - """ - return self._function_name.decode() - - def get_num_args (self): - """ Returns the number of arguments for this kernel function. - """ - return DPCTLKernel_GetNumArgs(self._kernel_ref) - - cdef DPCTLSyclKernelRef get_kernel_ref (self): - """ Returns the DPCTLSyclKernelRef pointer for this SyclKernel. - """ - return self._kernel_ref - - def addressof_ref (self): - """ Returns the address of the C API DPCTLSyclKernelRef pointer - as a long. - - Returns: - The address of the DPCTLSyclKernelRef object used to create this - SyclKernel cast to a long. - """ - return int(self._kernel_ref) - -cdef class SyclProgram: - """ Wraps a sycl::program object created from an OpenCL interoperability - program. - - SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A - SyclProgram can be created from either a source string or a SPIR-V - binary file. - """ - - @staticmethod - cdef SyclProgram _create (DPCTLSyclProgramRef pref): - cdef SyclProgram ret = SyclProgram.__new__(SyclProgram) - ret._program_ref = pref - return ret - - def __dealloc__ (self): - DPCTLProgram_Delete(self._program_ref) - - cdef DPCTLSyclProgramRef get_program_ref (self): - return self._program_ref - - cpdef SyclKernel get_sycl_kernel(self, str kernel_name): - name = kernel_name.encode('utf8') - return SyclKernel._create(DPCTLProgram_GetKernel(self._program_ref, - name)) - - def has_sycl_kernel(self, str kernel_name): - name = kernel_name.encode('utf8') - return DPCTLProgram_HasKernel(self._program_ref, name) - - def addressof_ref (self): - """Returns the address of the C API DPCTLSyclProgramRef pointer - as a long. - - Returns: - The address of the DPCTLSyclProgramRef object used to create this - SyclProgram cast to a long. - """ - return int(self._program_ref) - import ctypes cdef class SyclQueue: @@ -894,80 +802,6 @@ cpdef get_current_backend(): """ return _mgr.get_current_backend() -def create_program_from_source (SyclQueue q, unicode source, unicode copts=""): - """ - Creates a Sycl interoperability program from an OpenCL source string. - - We use the DPCTLProgram_CreateFromOCLSource() C API function to create - a Sycl progrma from an OpenCL source program that can contain multiple - kernels. - - Parameters: - q (SyclQueue) : The :class:`SyclQueue` for which the - :class:`SyclProgram` is going to be built. - source (unicode): Source string for an OpenCL program. - copts (unicode) : Optional compilation flags that will be used - when compiling the program. - - Returns: - program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API. - """ - - BE = q.get_sycl_backend() - if BE != backend_type.opencl: - raise ValueError( - "Cannot create program for a ", BE, "type backend. Currently only " - "OpenCL devices are supported for program creations." - ) - - cdef DPCTLSyclProgramRef Pref - cdef bytes bSrc = source.encode('utf8') - cdef bytes bCOpts = copts.encode('utf8') - cdef const char *Src = bSrc - cdef const char *COpts = bCOpts - cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() - Pref = DPCTLProgram_CreateFromOCLSource(CRef, Src, COpts) - - if Pref is NULL: - raise SyclProgramCompilationError() - - return SyclProgram._create(Pref) - -cimport cython.array - -def create_program_from_spirv (SyclQueue q, const unsigned char[:] IL): - """ - Creates a Sycl interoperability program from an SPIR-V binary. - - We use the DPCTLProgram_CreateFromOCLSpirv() C API function to create - a Sycl progrma from an compiled SPIR-V binary file. - - Parameters: - q (SyclQueue): The :class:`SyclQueue` for which the - :class:`SyclProgram` is going to be built. - IL (const char[:]) : SPIR-V binary IL file for an OpenCL program. - - Returns: - program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API. - """ - BE = q.get_sycl_backend() - if BE != backend_type.opencl: - raise ValueError( - "Cannot create program for a ", BE, "type backend. Currently only " - "OpenCL devices are supported for program creations." - ) - - cdef DPCTLSyclProgramRef Pref - cdef const unsigned char *dIL = &IL[0] - cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() - cdef size_t length = IL.shape[0] - Pref = DPCTLProgram_CreateFromOCLSpirv(CRef, dIL, length) - if Pref is NULL: - raise SyclProgramCompilationError() - - return SyclProgram._create(Pref) - - from contextlib import contextmanager @contextmanager diff --git a/dpctl/program/__init__.pxd b/dpctl/program/__init__.pxd new file mode 100644 index 0000000000..3771ce2849 --- /dev/null +++ b/dpctl/program/__init__.pxd @@ -0,0 +1,30 @@ +#===----------- __init__.pxd - dpctl.program module -*- Cython -*-----------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===## +# +# \file +# This file declares the extension types and functions for the Cython API +# implemented in dpctl.program._program.pyx. +# +#===------------------------------------------------------------------------===# + +# distutils: language = c++ +# cython: language_level=3 + +from dpctl.program._program cimport * diff --git a/dpctl/program/__init__.py b/dpctl/program/__init__.py new file mode 100644 index 0000000000..904760cd92 --- /dev/null +++ b/dpctl/program/__init__.py @@ -0,0 +1,36 @@ +#===---------- __init__.py - dpctl.program module ----*---- Python ----*----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This dpctl.program module wraps Sycl program creation functions defined in +# dppl_sycl_program_interface.h. +# +#===------------------------------------------------------------------------===# +""" + **Data Parallel Control Program** + + `dpctl.program` module provides a way to create a SYCL kernel from either a + source string or SPIR-V binary file. + +""" +from ._program import * +from ._program import __all__ as _program__all__ + +__all__ = _program__all__ diff --git a/dpctl/program/_program.pxd b/dpctl/program/_program.pxd new file mode 100644 index 0000000000..1001d2c5af --- /dev/null +++ b/dpctl/program/_program.pxd @@ -0,0 +1,63 @@ +#===-------------- _program.pxd - dpctl.program module -*-- Cython ----*----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file has the Cython function declarations for the functions defined +# in dpctl.program._program.pyx +# +#===------------------------------------------------------------------------===# + +# distutils: language = c++ +# cython: language_level=3 + +from .._backend cimport DPCTLSyclKernelRef, DPCTLSyclProgramRef +from .._sycl_core cimport SyclQueue, SyclDevice, SyclContext + + +cdef class SyclKernel: + ''' Wraps a sycl::kernel object created from an OpenCL interoperability + kernel. + ''' + cdef DPCTLSyclKernelRef _kernel_ref + cdef const char *_function_name + cdef DPCTLSyclKernelRef get_kernel_ref (self) + + @staticmethod + cdef SyclKernel _create (DPCTLSyclKernelRef kref) + + +cdef class SyclProgram: + ''' Wraps a sycl::program object created from an OpenCL interoperability + program. + + SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A + SyclProgram can be created from either a source string or a SPIR-V + binary file. + ''' + cdef DPCTLSyclProgramRef _program_ref + + @staticmethod + cdef SyclProgram _create (DPCTLSyclProgramRef pref) + cdef DPCTLSyclProgramRef get_program_ref (self) + cpdef SyclKernel get_sycl_kernel(self, str kernel_name) + + +cpdef create_program_from_source (SyclQueue q, unicode source, unicode copts=*) +cpdef create_program_from_spirv (SyclQueue q, const unsigned char[:] IL) diff --git a/dpctl/program/_program.pyx b/dpctl/program/_program.pyx new file mode 100644 index 0000000000..9c08dc0afb --- /dev/null +++ b/dpctl/program/_program.pyx @@ -0,0 +1,186 @@ +#===------- _program.pyx - dpctl.program module ---*--- Cython ------*------===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#===------------------------------------------------------------------------===# +# +# \file +# This file implements a a Python interface for SYCL's program and kernel +# runtime classes. Convenience functions to create a SYCL program for either +# a OpenCL source file or a SPIR-V binary file are also included in the +# module. +# +#===------------------------------------------------------------------------===# + +# distutils: language = c++ +# cython: language_level=3 + +from __future__ import print_function +from dpctl._backend cimport * + +__all__ = [ + "create_program_from_source", + "create_program_from_spirv", + "SyclKernel", + "SyclProgram", + "SyclProgramCompilationError", +] + +cdef class SyclProgramCompilationError (Exception): + """This exception is raised when a sycl program could not be built from + either a spirv binary file or a string source. + """ + pass + +cdef class SyclKernel: + """ + """ + @staticmethod + cdef SyclKernel _create (DPCTLSyclKernelRef kref): + cdef SyclKernel ret = SyclKernel.__new__(SyclKernel) + ret._kernel_ref = kref + ret._function_name = DPCTLKernel_GetFunctionName(kref) + return ret + + def __dealloc__ (self): + DPCTLKernel_Delete(self._kernel_ref) + DPCTLCString_Delete(self._function_name) + + def get_function_name (self): + """ Returns the name of the Kernel function. + """ + return self._function_name.decode() + + def get_num_args (self): + """ Returns the number of arguments for this kernel function. + """ + return DPCTLKernel_GetNumArgs(self._kernel_ref) + + cdef DPCTLSyclKernelRef get_kernel_ref (self): + """ Returns the DPCTLSyclKernelRef pointer for this SyclKernel. + """ + return self._kernel_ref + + def addressof_ref (self): + """ Returns the address of the C API DPCTLSyclKernelRef pointer + as a long. + + Returns: + The address of the DPCTLSyclKernelRef object used to create this + SyclKernel cast to a long. + """ + return int(self._kernel_ref) + +cdef class SyclProgram: + """ Wraps a sycl::program object created from an OpenCL interoperability + program. + + SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A + SyclProgram can be created from either a source string or a SPIR-V + binary file. + """ + + @staticmethod + cdef SyclProgram _create (DPCTLSyclProgramRef pref): + cdef SyclProgram ret = SyclProgram.__new__(SyclProgram) + ret._program_ref = pref + return ret + + def __dealloc__ (self): + DPCTLProgram_Delete(self._program_ref) + + cdef DPCTLSyclProgramRef get_program_ref (self): + return self._program_ref + + cpdef SyclKernel get_sycl_kernel(self, str kernel_name): + name = kernel_name.encode('utf8') + return SyclKernel._create(DPCTLProgram_GetKernel(self._program_ref, + name)) + + def has_sycl_kernel(self, str kernel_name): + name = kernel_name.encode('utf8') + return DPCTLProgram_HasKernel(self._program_ref, name) + + def addressof_ref (self): + """Returns the address of the C API DPCTLSyclProgramRef pointer + as a long. + + Returns: + The address of the DPCTLSyclProgramRef object used to create this + SyclProgram cast to a long. + """ + return int(self._program_ref) + +cpdef create_program_from_source (SyclQueue q, unicode src, unicode copts=""): + """ + Creates a Sycl interoperability program from an OpenCL source string. + + We use the DPCTLProgram_CreateFromOCLSource() C API function to create + a Sycl progrma from an OpenCL source program that can contain multiple + kernels. + + Parameters: + q (SyclQueue) : The :class:`SyclQueue` for which the + :class:`SyclProgram` is going to be built. + src (unicode): Source string for an OpenCL program. + copts (unicode) : Optional compilation flags that will be used + when compiling the program. + + Returns: + program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API. + """ + + cdef DPCTLSyclProgramRef Pref + cdef bytes bSrc = src.encode('utf8') + cdef bytes bCOpts = copts.encode('utf8') + cdef const char *Src = bSrc + cdef const char *COpts = bCOpts + cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() + Pref = DPCTLProgram_CreateFromOCLSource(CRef, Src, COpts) + + if Pref is NULL: + raise SyclProgramCompilationError() + + return SyclProgram._create(Pref) + +cimport cython.array + +cpdef create_program_from_spirv (SyclQueue q, const unsigned char[:] IL): + """ + Creates a Sycl interoperability program from an SPIR-V binary. + + We use the DPCTLProgram_CreateFromOCLSpirv() C API function to create + a Sycl progrma from an compiled SPIR-V binary file. + + Parameters: + q (SyclQueue): The :class:`SyclQueue` for which the + :class:`SyclProgram` is going to be built. + IL (const char[:]) : SPIR-V binary IL file for an OpenCL program. + + Returns: + program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API. + """ + + cdef DPCTLSyclProgramRef Pref + cdef const unsigned char *dIL = &IL[0] + cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref() + cdef size_t length = IL.shape[0] + Pref = DPCTLProgram_CreateFromOCLSpirv(CRef, dIL, length) + if Pref is NULL: + raise SyclProgramCompilationError() + + return SyclProgram._create(Pref) diff --git a/dpctl/tests/test_sycl_kernel_submit.py b/dpctl/tests/test_sycl_kernel_submit.py index e1ffa96e19..b124f30041 100644 --- a/dpctl/tests/test_sycl_kernel_submit.py +++ b/dpctl/tests/test_sycl_kernel_submit.py @@ -26,6 +26,7 @@ import dpctl import unittest import dpctl.memory as dpctl_mem +import dpctl.program as dpctl_prog import numpy as np @@ -39,7 +40,7 @@ def test_create_program_from_source(self): }" with dpctl.device_context("opencl:gpu:0"): q = dpctl.get_current_queue() - prog = dpctl.create_program_from_source(q, oclSrc) + prog = dpctl_prog.create_program_from_source(q, oclSrc) axpyKernel = prog.get_sycl_kernel("axpy") abuf = dpctl_mem.MemoryUSMShared(1024 * np.dtype("i").itemsize) diff --git a/dpctl/tests/test_sycl_program.py b/dpctl/tests/test_sycl_program.py index 0e695bf6bb..f4ebeaaf7a 100644 --- a/dpctl/tests/test_sycl_program.py +++ b/dpctl/tests/test_sycl_program.py @@ -24,6 +24,7 @@ ##===----------------------------------------------------------------------===## import dpctl +import dpctl.program as dpctl_prog import unittest import os @@ -42,7 +43,7 @@ def test_create_program_from_source(self): }" with dpctl.device_context("opencl:gpu:0"): q = dpctl.get_current_queue() - prog = dpctl.create_program_from_source(q, oclSrc) + prog = dpctl_prog.create_program_from_source(q, oclSrc) self.assertIsNotNone(prog) self.assertTrue(prog.has_sycl_kernel("add")) @@ -67,7 +68,7 @@ def test_create_program_from_spirv(self): spirv = fin.read() with dpctl.device_context("opencl:gpu:0"): q = dpctl.get_current_queue() - prog = dpctl.create_program_from_spirv(q, spirv) + prog = dpctl_prog.create_program_from_spirv(q, spirv) self.assertIsNotNone(prog) self.assertTrue(prog.has_sycl_kernel("add")) self.assertTrue(prog.has_sycl_kernel("axpy")) @@ -86,6 +87,7 @@ def test_create_program_from_spirv(self): "No Level0 GPU queues available", ) class TestProgramForLevel0GPU(unittest.TestCase): + @unittest.expectedFailure def test_create_program_from_spirv(self): CURR_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -94,12 +96,9 @@ def test_create_program_from_spirv(self): spirv = fin.read() with dpctl.device_context("level0:gpu:0"): q = dpctl.get_current_queue() - try: - prog = dpctl.create_program_from_spirv(q, spirv) - self.fail("Tried to create program for an unsupported Level0 GPU.") - except ValueError: - pass + prog = dpctl_prog.create_program_from_spirv(q, spirv) + @unittest.expectedFailure def test_create_program_from_source(self): oclSrc = " \ kernel void add(global int* a, global int* b, global int* c) { \ @@ -112,12 +111,7 @@ def test_create_program_from_source(self): }" with dpctl.device_context("level0:gpu:0"): q = dpctl.get_current_queue() - try: - prog = dpctl.create_program_from_source(q, oclSrc) - self.fail("Tried to create program for an unsupported Level0 GPU.") - except ValueError: - pass - + prog = dpctl_prog.create_program_from_source(q, oclSrc) if __name__ == "__main__": unittest.main() diff --git a/setup.py b/setup.py index 087d78f4dd..14d3153e26 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,26 @@ -##===------------- setup.py - dpctl.ocldrv interface -----*- Python -*-----===## -## -## Data Parallel Control Library (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### This file builds the dpctl and dpctl.ocldrv extension modules. -##===----------------------------------------------------------------------===## +# ===-------------------- setup.py - dpctl -----*----- Python -------*------===# +# +# Data Parallel Control Library (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# This file builds all the extension modules for dpctl. +# ===-----------------------------------------------------------------------===# import os import os.path import sys @@ -177,6 +177,13 @@ def extensions(): ], **extension_args ), + Extension( + "dpctl.program._program", + [ + os.path.join("dpctl", "program", "_program.pyx"), + ], + **extension_args + ), ] exts = cythonize(extensions) From fdfdcafeecaa1aa30531bdc9288cbb333a3aa5d7 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Thu, 3 Dec 2020 18:57:11 -0600 Subject: [PATCH 8/8] Standardize license headers while keeping black happy. --- dpctl/__init__.pxd | 6 ++-- dpctl/__init__.py | 6 ++-- dpctl/_backend.pxd | 6 ++-- dpctl/_sycl_core.pxd | 2 +- dpctl/memory/__init__.pxd | 6 ++-- dpctl/memory/__init__.py | 6 ++-- dpctl/memory/_memory.pxd | 10 ++++-- dpctl/memory/_memory.pyx | 6 ++-- dpctl/program/__init__.pxd | 6 ++-- dpctl/program/__init__.py | 6 ++-- dpctl/program/_program.pxd | 6 ++-- dpctl/program/_program.pyx | 6 ++-- dpctl/tests/__init__.py | 46 ++++++++++++------------ dpctl/tests/test_dump_functions.py | 46 ++++++++++++------------ dpctl/tests/test_sycl_device.py | 46 ++++++++++++------------ dpctl/tests/test_sycl_kernel_submit.py | 47 ++++++++++++------------ dpctl/tests/test_sycl_program.py | 49 +++++++++++++------------- dpctl/tests/test_sycl_queue.py | 46 ++++++++++++------------ dpctl/tests/test_sycl_queue_manager.py | 46 ++++++++++++------------ dpctl/tests/test_sycl_queue_memcpy.py | 46 ++++++++++++------------ dpctl/tests/test_sycl_usm.py | 46 ++++++++++++------------ 21 files changed, 248 insertions(+), 242 deletions(-) diff --git a/dpctl/__init__.pxd b/dpctl/__init__.pxd index f4467c606e..f56e84c7f8 100644 --- a/dpctl/__init__.pxd +++ b/dpctl/__init__.pxd @@ -1,4 +1,4 @@ -#===------------- __init__.pxd - dpctl module --------*- Cython -*----------===# +# ===------------ __init__.pxd - dpctl module --------*- Cython -*----------===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file declares the extension types and functions for the Cython API # implemented in sycl_core.pyx. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/__init__.py b/dpctl/__init__.py index db52c956c0..d453eeeb45 100644 --- a/dpctl/__init__.py +++ b/dpctl/__init__.py @@ -1,4 +1,4 @@ -#===----------------- __init__.py - dpctl module -------*- Cython -*--------===# +# ===---------------- __init__.py - dpctl module -------*- Cython -*--------===# # # Data Parallel Control (dpCtl) # @@ -16,12 +16,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # The top-level dpctl module. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# """ **Data Parallel Control (dpCtl)** diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 21efe767f2..ff6d0c536f 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -1,4 +1,4 @@ -#===------------- backend.pyx - dpctl module -------*- Cython -*------------===# +# ===------------ backend.pyx - dpctl module -------*- Cython -*------------===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file defines the Cython extern types for the functions and opaque data # types defined by dpctl's C API. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/_sycl_core.pxd b/dpctl/_sycl_core.pxd index cbc82fa8dc..ae2d650c60 100644 --- a/dpctl/_sycl_core.pxd +++ b/dpctl/_sycl_core.pxd @@ -1,4 +1,4 @@ -# ===------------- sycl_core.pxd - dpctl module --------*- Cython -*--------===# +# ===------------ sycl_core.pxd - dpctl module --------*- Cython -*---------===# # # Data Parallel Control (dpCtl) # diff --git a/dpctl/memory/__init__.pxd b/dpctl/memory/__init__.pxd index 23768f3b3e..042238c8e3 100644 --- a/dpctl/memory/__init__.pxd +++ b/dpctl/memory/__init__.pxd @@ -1,4 +1,4 @@ -#===----------- __init__.pxd - dpctl.memory module ----*- Cython -*---------===# +# ===---------- __init__.pxd - dpctl.memory module ----*- Cython -*---------===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file declares the extension types and functions for the Cython API # implemented in dpctl.memory._memory.pyx. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/memory/__init__.py b/dpctl/memory/__init__.py index 6541c406e9..0f39591e02 100644 --- a/dpctl/memory/__init__.py +++ b/dpctl/memory/__init__.py @@ -1,4 +1,4 @@ -#===---------- __init__.py - dpctl.memory module -------*- Python -*--------===# +# ===--------- __init__.py - dpctl.memory module -------*- Python -*--------===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This is the dpctl.memory module containing the USM memory manager features # of dpctl. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# """ **Data Parallel Control Memory** diff --git a/dpctl/memory/_memory.pxd b/dpctl/memory/_memory.pxd index 6140a25f87..789546e81a 100644 --- a/dpctl/memory/_memory.pxd +++ b/dpctl/memory/_memory.pxd @@ -1,4 +1,4 @@ -#===--------------- _memory.pxd - dpctl module --------*- Cython -*---------===# +# ===-------------- _memory.pxd - dpctl module --------*- Cython -*---------===# # # Data Parallel Control (dpCtl) # @@ -16,7 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===-----------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# +# +# \file +# This file has the Cython function declarations for the functions defined +# in dpctl.memory._memory.pyx +# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/memory/_memory.pyx b/dpctl/memory/_memory.pyx index fb121e3c3d..d01d147980 100644 --- a/dpctl/memory/_memory.pyx +++ b/dpctl/memory/_memory.pyx @@ -1,4 +1,4 @@ -#===--------------- _memory.pyx - dpctl module --------*- Cython -*---------===# +# ===-------------- _memory.pyx - dpctl module --------*- Cython -*---------===# # # Data Parallel Control (dpCtl) # @@ -16,14 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file implements Python buffer protocol using Sycl USM shared and host # allocators. The USM device allocator is also exposed through this module for # use in other Python modules. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/program/__init__.pxd b/dpctl/program/__init__.pxd index 3771ce2849..5e7f23a705 100644 --- a/dpctl/program/__init__.pxd +++ b/dpctl/program/__init__.pxd @@ -1,4 +1,4 @@ -#===----------- __init__.pxd - dpctl.program module -*- Cython -*-----------===# +# ===---------- __init__.pxd - dpctl.program module -*- Cython -*-----------===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===## +# ===----------------------------------------------------------------------===## # # \file # This file declares the extension types and functions for the Cython API # implemented in dpctl.program._program.pyx. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/program/__init__.py b/dpctl/program/__init__.py index 904760cd92..2f6edf569f 100644 --- a/dpctl/program/__init__.py +++ b/dpctl/program/__init__.py @@ -1,4 +1,4 @@ -#===---------- __init__.py - dpctl.program module ----*---- Python ----*----===# +# ==---------- __init__.py - dpctl.program module ----*---- Python ----*----===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ==------------------------------------------------------------------------===# # # \file # This dpctl.program module wraps Sycl program creation functions defined in # dppl_sycl_program_interface.h. # -#===------------------------------------------------------------------------===# +# ==------------------------------------------------------------------------===# """ **Data Parallel Control Program** diff --git a/dpctl/program/_program.pxd b/dpctl/program/_program.pxd index 1001d2c5af..27f0716791 100644 --- a/dpctl/program/_program.pxd +++ b/dpctl/program/_program.pxd @@ -1,4 +1,4 @@ -#===-------------- _program.pxd - dpctl.program module -*-- Cython ----*----===# +# ===------------- _program.pxd - dpctl.program module -*-- Cython ----*----===# # # Data Parallel Control (dpCtl) # @@ -16,13 +16,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file has the Cython function declarations for the functions defined # in dpctl.program._program.pyx # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/program/_program.pyx b/dpctl/program/_program.pyx index 9c08dc0afb..ee7a89cd1f 100644 --- a/dpctl/program/_program.pyx +++ b/dpctl/program/_program.pyx @@ -1,4 +1,4 @@ -#===------- _program.pyx - dpctl.program module ---*--- Cython ------*------===# +# ===------- _program.pyx - dpctl.program module ---*--- Cython ------*-----===# # # Data Parallel Control (dpCtl) # @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # # \file # This file implements a a Python interface for SYCL's program and kernel @@ -24,7 +24,7 @@ # a OpenCL source file or a SPIR-V binary file are also included in the # module. # -#===------------------------------------------------------------------------===# +# ===-----------------------------------------------------------------------===# # distutils: language = c++ # cython: language_level=3 diff --git a/dpctl/tests/__init__.py b/dpctl/tests/__init__.py index a53980d17a..001378d541 100644 --- a/dpctl/tests/__init__.py +++ b/dpctl/tests/__init__.py @@ -1,26 +1,26 @@ -##===-------- tests/dpctl_tests/__init__.py - dpctl ------*- Python -*----===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Top-level module of all dpctl Python unit test cases. -##===----------------------------------------------------------------------===## +# ===-------- tests/dpctl_tests/__init__.py - dpctl ------*- Python -*-----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Top-level module of all dpctl Python unit test cases. +# ===-----------------------------------------------------------------------===# from .test_dump_functions import * from .test_sycl_device import * diff --git a/dpctl/tests/test_dump_functions.py b/dpctl/tests/test_dump_functions.py index 07c4b2d09b..47d103d89c 100644 --- a/dpctl/tests/test_dump_functions.py +++ b/dpctl/tests/test_dump_functions.py @@ -1,26 +1,26 @@ -##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### A basic unit test to verify that dpctl and dpct.ocldrv exist. -##===----------------------------------------------------------------------===## +# ===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# A basic unit test to verify that dpctl and dpct.ocldrv exist. +# ===-----------------------------------------------------------------------===# import unittest diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 1b1229c39a..5b0b8d5177 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -1,26 +1,26 @@ -##===------------ test_sycl_device.py - dpctl -------*- Python -*---------===## -## -## Data Parallel Control (dpctl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Defines unit test cases for the SyclDevice classes defined in sycl_core.pyx. -##===----------------------------------------------------------------------===## +# ===------------- test_sycl_device.py - dpctl -------*- Python -*---------===# +# +# Data Parallel Control (dpctl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the SyclDevice classes defined in sycl_core.pyx. +# ===-----------------------------------------------------------------------===# import dpctl import unittest diff --git a/dpctl/tests/test_sycl_kernel_submit.py b/dpctl/tests/test_sycl_kernel_submit.py index b124f30041..a85702c362 100644 --- a/dpctl/tests/test_sycl_kernel_submit.py +++ b/dpctl/tests/test_sycl_kernel_submit.py @@ -1,27 +1,26 @@ -##===------------- test_sycl_kernel_submit.py - dpctl -----*- Python -*---===## -## -## Data Parallel Control (dpctl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Defines unit test cases for kernel submission to a sycl::queue. -## -##===----------------------------------------------------------------------===## +# ===------------- test_sycl_kernel_submit.py - dpctl -----*- Python -*---===## +# +# Data Parallel Control (dpctl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for kernel submission to a sycl::queue. +# ===-----------------------------------------------------------------------===# import ctypes import dpctl import unittest diff --git a/dpctl/tests/test_sycl_program.py b/dpctl/tests/test_sycl_program.py index f4ebeaaf7a..5eb1c2b66b 100644 --- a/dpctl/tests/test_sycl_program.py +++ b/dpctl/tests/test_sycl_program.py @@ -1,27 +1,27 @@ -##===------------- test_sycl_program.py - dpctl -------*- Python -*-------===## -## -## Data Parallel Control (dpctl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Defines unit test cases for the SyclProgram and SyclKernel classes defined -## in sycl_core.pyx. -##===----------------------------------------------------------------------===## +# ===------------- test_sycl_program.py - dpctl -------*- Python -*--------===# +# +# Data Parallel Control (dpctl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the SyclProgram and SyclKernel classes defined +# in sycl_core.pyx. +# ===-----------------------------------------------------------------------===# import dpctl import dpctl.program as dpctl_prog @@ -113,5 +113,6 @@ def test_create_program_from_source(self): q = dpctl.get_current_queue() prog = dpctl_prog.create_program_from_source(q, oclSrc) + if __name__ == "__main__": unittest.main() diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index 317685c9f3..4d56bfb434 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -1,26 +1,26 @@ -##===------------- test_sycl_queue.py - dpctl -------*- Python -*---------===## -## -## Data Parallel Control (dpctl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Defines unit test cases for the SyclQueue classes defined in sycl_core.pyx. -##===----------------------------------------------------------------------===## +# ===------------- test_sycl_queue.py - dpctl -------*- Python -*----------===# +# +# Data Parallel Control (dpctl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the SyclQueue classes defined in sycl_core.pyx. +# ===-----------------------------------------------------------------------===# import dpctl import unittest diff --git a/dpctl/tests/test_sycl_queue_manager.py b/dpctl/tests/test_sycl_queue_manager.py index 7cc5c8f513..d340fda03c 100644 --- a/dpctl/tests/test_sycl_queue_manager.py +++ b/dpctl/tests/test_sycl_queue_manager.py @@ -1,26 +1,26 @@ -##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### Defines unit test cases for the SyclQueueManager class in sycl_core.pyx. -##===----------------------------------------------------------------------===## +# ===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the SyclQueueManager class in sycl_core.pyx. +# ===-----------------------------------------------------------------------===# import dpctl import unittest diff --git a/dpctl/tests/test_sycl_queue_memcpy.py b/dpctl/tests/test_sycl_queue_memcpy.py index 6e3bb7dc72..de6d860712 100644 --- a/dpctl/tests/test_sycl_queue_memcpy.py +++ b/dpctl/tests/test_sycl_queue_memcpy.py @@ -1,26 +1,26 @@ -##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### Defines unit test cases for the SyclQueue.memcpy in sycl_core.pyx. -##===----------------------------------------------------------------------===## +# ===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the SyclQueue.memcpy in sycl_core.pyx. +# ===-----------------------------------------------------------------------===# import dpctl import dpctl.memory diff --git a/dpctl/tests/test_sycl_usm.py b/dpctl/tests/test_sycl_usm.py index a8d6bdc744..520cd8f8ff 100644 --- a/dpctl/tests/test_sycl_usm.py +++ b/dpctl/tests/test_sycl_usm.py @@ -1,26 +1,26 @@ -##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -## -## \file -## Defines unit test cases for the Memory classes in _memory.pyx. -##===----------------------------------------------------------------------===## +# ===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===# +# +# Data Parallel Control (dpCtl) +# +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ===-----------------------------------------------------------------------===# +# +# \file +# Defines unit test cases for the Memory classes in _memory.pyx. +# ===-----------------------------------------------------------------------===# import unittest import dpctl