From dcf00f67a83c1da129c28b36a50ba419df5f598f Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 12:58:08 -0500 Subject: [PATCH 1/9] Added `size_t DPCTLQueue_Hash(QRef)` --- .../include/dpctl_sycl_queue_interface.h | 10 +++++++ .../source/dpctl_sycl_queue_interface.cpp | 26 ++++++++++++++++--- .../tests/test_sycl_queue_interface.cpp | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dpctl-capi/include/dpctl_sycl_queue_interface.h b/dpctl-capi/include/dpctl_sycl_queue_interface.h index 8871e58dcc..9ace0ecf39 100644 --- a/dpctl-capi/include/dpctl_sycl_queue_interface.h +++ b/dpctl-capi/include/dpctl_sycl_queue_interface.h @@ -331,4 +331,14 @@ void DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef, DPCTL_API bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef); +/*! + * @brief C-API wrapper for std::hash's operator(). + * + * @param QRef An opaque pointer to the sycl queue. + * @return Hash value. + * @ingroup QueueInterface + */ +DPCTL_API +size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef); + DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/source/dpctl_sycl_queue_interface.cpp b/dpctl-capi/source/dpctl_sycl_queue_interface.cpp index cf679a2ed5..8a93b31f4f 100644 --- a/dpctl-capi/source/dpctl_sycl_queue_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_queue_interface.cpp @@ -454,9 +454,15 @@ void 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); - if (SyclQueue) - SyclQueue->wait(); + if (QRef) { + auto SyclQueue = unwrap(QRef); + if (SyclQueue) + SyclQueue->wait(); + } + else { + // todo: log error + std::cerr << "Argument QRef is NULL" << '\n'; + } } void DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef, @@ -504,3 +510,17 @@ bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef) else return false; } + +size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef) +{ + auto Q = unwrap(QRef); + if (Q) { + std::hash hash_fn; + return hash_fn(*Q); + } + else { + // todo: log error + std::cerr << "Argument QRef is null" << '\n'; + return 0; + } +} diff --git a/dpctl-capi/tests/test_sycl_queue_interface.cpp b/dpctl-capi/tests/test_sycl_queue_interface.cpp index 3120bc3446..d2f3504f3d 100644 --- a/dpctl-capi/tests/test_sycl_queue_interface.cpp +++ b/dpctl-capi/tests/test_sycl_queue_interface.cpp @@ -166,11 +166,13 @@ TEST_F(TestDPCTLSyclQueueInterface, CheckAreEq) } EXPECT_TRUE(DPCTLQueue_AreEq(Q1, Q2)); + EXPECT_TRUE(DPCTLQueue_Hash(Q1) == DPCTLQueue_Hash(Q2)); auto Q3 = DPCTLQueue_CreateForDevice(DRef, nullptr, 0); auto Q4 = DPCTLQueue_CreateForDevice(DRef, nullptr, 0); // These are different queues EXPECT_FALSE(DPCTLQueue_AreEq(Q3, Q4)); + EXPECT_FALSE(DPCTLQueue_Hash(Q3) == DPCTLQueue_Hash(Q4)); auto C0 = DPCTLQueue_GetContext(Q3); auto C1 = DPCTLQueue_GetContext(Q4); From ea1eba901a007ecacbb7f4bb7d2c8516f3efbecd Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 13:13:05 -0500 Subject: [PATCH 2/9] Added `size_t DPCTLDevice_Hash(DRef)` --- dpctl-capi/include/dpctl_sycl_device_interface.h | 10 ++++++++++ dpctl-capi/source/dpctl_sycl_device_interface.cpp | 15 +++++++++++++++ dpctl-capi/tests/test_sycl_device_interface.cpp | 2 ++ 3 files changed, 27 insertions(+) diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index bfd7708047..4976f3497f 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -555,3 +555,13 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf( DPCTL_API __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * std::hash's operator() + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns hash value. + */ +DPCTL_API +size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef); diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 80a0f983e0..bbf510f5c9 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -690,3 +690,18 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( } return wrap(Devices); } + +size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef) +{ + if (DRef) { + auto D = unwrap(DRef); + std::hash hash_fn; + return hash_fn(*D); + } + else { + // todo: log error + std::cerr << "Argument DRef is null" + << "/n"; + return 0; + } +} diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index a17145e5cb..5a7f898962 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -68,6 +68,8 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCopy) DPCTLSyclDeviceRef Copied_DRef = nullptr; EXPECT_NO_FATAL_FAILURE(Copied_DRef = DPCTLDevice_Copy(DRef)); EXPECT_TRUE(bool(Copied_DRef)); + EXPECT_TRUE(DPCTLDevice_AreEq(DRef, Copied_DRef)); + EXPECT_TRUE(DPCTLDevice_Hash(DRef) == DPCTLDevice_Hash(Copied_DRef)); EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(Copied_DRef)); } From 695616f6d3d84401599a29dba639ec3dbb9dfa05 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 13:39:10 -0500 Subject: [PATCH 3/9] Added `size_t DPCTLContext_Hash(CtxRef)` --- dpctl-capi/include/dpctl_sycl_context_interface.h | 11 +++++++++++ dpctl-capi/source/dpctl_sycl_context_interface.cpp | 14 ++++++++++++++ dpctl-capi/tests/test_sycl_context_interface.cpp | 2 ++ 3 files changed, 27 insertions(+) diff --git a/dpctl-capi/include/dpctl_sycl_context_interface.h b/dpctl-capi/include/dpctl_sycl_context_interface.h index b750084e3f..a5e9526849 100644 --- a/dpctl-capi/include/dpctl_sycl_context_interface.h +++ b/dpctl-capi/include/dpctl_sycl_context_interface.h @@ -161,4 +161,15 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef); DPCTL_API void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef); +/*! + * @brief Wrapper over + * std::hash's operator() + * + * @param CtxRef The DPCTLSyclContextRef pointer. + * @return Hash value of the underlying sycl::context instance. + * @ingroup ContextInterface + */ +DPCTL_API +size_t DPCTLContext_Hash(__dpctl_take DPCTLSyclContextRef CtxRef); + DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/source/dpctl_sycl_context_interface.cpp b/dpctl-capi/source/dpctl_sycl_context_interface.cpp index c45ab6891e..42c24b4e4d 100644 --- a/dpctl-capi/source/dpctl_sycl_context_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_context_interface.cpp @@ -197,3 +197,17 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef) return DPCTL_UNKNOWN_BACKEND; } } + +size_t DPCTLContext_Hash(__dpctl_keep const DPCTLSyclContextRef CtxRef) +{ + if (CtxRef) { + auto C = unwrap(CtxRef); + std::hash hash_fn; + return hash_fn(*C); + } + else { + std::cerr << "Argument CtxRef is null" + << "/n"; + return 0; + } +} diff --git a/dpctl-capi/tests/test_sycl_context_interface.cpp b/dpctl-capi/tests/test_sycl_context_interface.cpp index ae1a06950d..76431bef9d 100644 --- a/dpctl-capi/tests/test_sycl_context_interface.cpp +++ b/dpctl-capi/tests/test_sycl_context_interface.cpp @@ -177,6 +177,8 @@ TEST_P(TestDPCTLContextInterface, ChkAreEq) EXPECT_NO_FATAL_FAILURE(are_not_eq = DPCTLContext_AreEq(CRef1, CRef3)); EXPECT_TRUE(are_eq); EXPECT_FALSE(are_not_eq); + EXPECT_TRUE(DPCTLContext_Hash(CRef1) == DPCTLContext_Hash(CRef2)); + EXPECT_FALSE(DPCTLContext_Hash(CRef1) == DPCTLContext_Hash(CRef3)); EXPECT_NO_FATAL_FAILURE(DPCTLContext_Delete(CRef1)); EXPECT_NO_FATAL_FAILURE(DPCTLContext_Delete(CRef2)); From aa6935cd0f8d40c9c8db69ea64dee080cf29e588 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 13:45:19 -0500 Subject: [PATCH 4/9] added DPCTL_Hash to _backend --- dpctl/_backend.pxd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index cdc3f63e27..14917afe78 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -152,6 +152,7 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef DPCTLSyclPlatformRef DPCTLDevice_GetPlatform( const DPCTLSyclDeviceRef DRef) cdef const char *DPCTLDevice_GetVendor(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_Hash(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsAccelerator(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsCPU(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsGPU(const DPCTLSyclDeviceRef DRef) @@ -268,6 +269,7 @@ cdef extern from "dpctl_sycl_context_interface.h": cdef size_t DPCTLContext_DeviceCount(const DPCTLSyclContextRef CRef) cdef bool DPCTLContext_AreEq(const DPCTLSyclContextRef CtxRef1, const DPCTLSyclContextRef CtxRef2) + cdef size_t DPCTLContext_Hash(const DPCTLSyclContextRef CRef) cdef _backend_type DPCTLContext_GetBackend(const DPCTLSyclContextRef) cdef void DPCTLContext_Delete(DPCTLSyclContextRef CtxRef) @@ -307,6 +309,7 @@ cdef extern from "dpctl_sycl_queue_interface.h": cdef _backend_type DPCTLQueue_GetBackend(const DPCTLSyclQueueRef Q) cdef DPCTLSyclContextRef DPCTLQueue_GetContext(const DPCTLSyclQueueRef Q) cdef DPCTLSyclDeviceRef DPCTLQueue_GetDevice(const DPCTLSyclQueueRef Q) + cdef size_t DPCTLQueue_Hash(const DPCTLSyclQueueRef Q) cdef DPCTLSyclEventRef DPCTLQueue_SubmitRange( const DPCTLSyclKernelRef Ref, const DPCTLSyclQueueRef QRef, From 13dba5bbaf034d196be98ee481a321ba5363c3c0 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Tue, 1 Jun 2021 22:50:48 -0500 Subject: [PATCH 5/9] Defines __hash__ for all classes that define __eq__ method. - SyclContext, SyclDevice, SyclQueue classes previously where not hashable. The PR defines __hash__ function based on the C API DPCTL_Hash function. --- dpctl/_sycl_context.pyx | 8 ++++++++ dpctl/_sycl_device.pyx | 8 ++++++++ dpctl/_sycl_queue.pyx | 8 ++++++++ dpctl/tests/test_sycl_context.py | 9 +++++++++ dpctl/tests/test_sycl_device.py | 9 +++++++++ dpctl/tests/test_sycl_queue.py | 9 +++++++++ 6 files changed, 51 insertions(+) diff --git a/dpctl/_sycl_context.pyx b/dpctl/_sycl_context.pyx index 2ba0fd0e02..3fbdbb6f53 100644 --- a/dpctl/_sycl_context.pyx +++ b/dpctl/_sycl_context.pyx @@ -34,6 +34,7 @@ from ._backend cimport ( # noqa: E211 DPCTLContext_Delete, DPCTLContext_DeviceCount, DPCTLContext_GetDevices, + DPCTLContext_Hash, DPCTLDevice_Copy, DPCTLDevice_Delete, DPCTLDeviceMgr_GetCachedContext, @@ -335,6 +336,13 @@ cdef class SyclContext(_SyclContext): else: return False + def __hash__(self): + """ + Returns hash value corresponding to ``self._ctxt_ref``. + + """ + return DPCTLContext_Hash(self._ctxt_ref) + cdef DPCTLSyclContextRef get_context_ref(self): return self._ctxt_ref diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 5a05e7e8b6..7d40f7aca5 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -58,6 +58,7 @@ from ._backend cimport ( # noqa: E211 DPCTLDevice_GetSubGroupIndependentForwardProgress, DPCTLDevice_GetVendor, DPCTLDevice_HasAspect, + DPCTLDevice_Hash, DPCTLDevice_IsAccelerator, DPCTLDevice_IsCPU, DPCTLDevice_IsGPU, @@ -709,6 +710,13 @@ cdef class SyclDevice(_SyclDevice): + "] at {}>".format(hex(id(self))) ) + def __hash__(self): + """ + Returns hash value corresponding to ``self._device_ref``. + + """ + return DPCTLDevice_Hash(self._device_ref) + cdef list create_sub_devices_equally(self, size_t count): """ Returns a list of sub-devices partitioned from this SYCL device based on the ``count`` parameter. diff --git a/dpctl/_sycl_queue.pyx b/dpctl/_sycl_queue.pyx index 9607f88e15..3e91646644 100644 --- a/dpctl/_sycl_queue.pyx +++ b/dpctl/_sycl_queue.pyx @@ -38,6 +38,7 @@ from ._backend cimport ( # noqa: E211 DPCTLQueue_GetBackend, DPCTLQueue_GetContext, DPCTLQueue_GetDevice, + DPCTLQueue_Hash, DPCTLQueue_IsInOrder, DPCTLQueue_MemAdvise, DPCTLQueue_Memcpy, @@ -863,6 +864,13 @@ cdef class SyclQueue(_SyclQueue): else: return "".format(hex(id(self))) + def __hash__(self): + """ + Returns hash value corresponding to ``self._queue_ref``. + + """ + return DPCTLQueue_Hash(self._queue_ref) + def _get_capsule(self): cdef DPCTLSyclQueueRef QRef = NULL QRef = DPCTLQueue_Copy(self._queue_ref) diff --git a/dpctl/tests/test_sycl_context.py b/dpctl/tests/test_sycl_context.py index 7a71b6626f..f0f8bde8bc 100644 --- a/dpctl/tests/test_sycl_context.py +++ b/dpctl/tests/test_sycl_context.py @@ -157,3 +157,12 @@ def test_context_multi_device(): shmem_1 = dpmem.MemoryUSMShared(256, queue=q1) shmem_2 = dpmem.MemoryUSMDevice(256, queue=q2) shmem_2.copy_from_device(shmem_1) + + +def test_hashing_of_context(): + """ + Test that a SyclContext object can be used as a dictionary key. + + """ + ctx_dict = {dpctl.SyclContext(): "default_context"} + assert ctx_dict diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 882bcebc6b..d98fc32fb9 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -631,3 +631,12 @@ def test_filter_string_method(): ) d_r = dpctl.SyclDevice(dev_id) assert d == d_r, "Failed " + + +def test_hashing_of_device(): + """ + Test that a SyclDevice object can be used as a dictionary key. + + """ + device_dict = {dpctl.SyclDevice(): "default_device"} + assert device_dict diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index c9739f0cda..9410812c07 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -369,3 +369,12 @@ def test_context_equals(): ctx0 = gpuQ0.get_sycl_context() ctx1 = gpuQ1.get_sycl_context() assert ctx0 == ctx1 + + +def test_hashing_of_queue(): + """ + Test that a SyclQueue object can be used as a dictionary key. + + """ + queue_dict = {dpctl.SyclQueue(): "default_queue"} + assert queue_dict From a7378600348bc2718603622b0719f823bc772315 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 14:09:21 -0500 Subject: [PATCH 6/9] Extended tests to check consistency of __eq__ and __hash__ --- dpctl/tests/test_sycl_context.py | 2 ++ dpctl/tests/test_sycl_device.py | 4 ++++ dpctl/tests/test_sycl_queue.py | 2 ++ 3 files changed, 8 insertions(+) diff --git a/dpctl/tests/test_sycl_context.py b/dpctl/tests/test_sycl_context.py index f0f8bde8bc..d4ab8c09a8 100644 --- a/dpctl/tests/test_sycl_context.py +++ b/dpctl/tests/test_sycl_context.py @@ -76,6 +76,7 @@ def test_context_not_equals(): except ValueError: pytest.skip() assert ctx_cpu != ctx_gpu + assert hash(ctx_cpu) != hash(ctx_gpu) def test_context_not_equals2(): @@ -94,6 +95,7 @@ def test_context_equals(): except ValueError: pytest.skip() assert ctx0 == ctx1 + assert hash(ctx0) == hash(ctx1) def test_name(): diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index d98fc32fb9..77a12fc8de 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -615,6 +615,7 @@ def test_filter_string_property(): dev_id = d.filter_string d_r = dpctl.SyclDevice(dev_id) assert d == d_r + assert hash(d) == hash(d_r) def test_filter_string_method(): @@ -631,6 +632,9 @@ def test_filter_string_method(): ) d_r = dpctl.SyclDevice(dev_id) assert d == d_r, "Failed " + assert hash(d) == hash( + d_r + ), "Hash equality is inconsistent with __eq__" def test_hashing_of_device(): diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index 9410812c07..568e709e3c 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -358,6 +358,7 @@ def test_context_not_equals(): pytest.skip() ctx_cpu = cpuQ.get_sycl_context() assert ctx_cpu != ctx_gpu + assert hash(ctx_cpu) != hash(ctx_gpu) def test_context_equals(): @@ -369,6 +370,7 @@ def test_context_equals(): ctx0 = gpuQ0.get_sycl_context() ctx1 = gpuQ1.get_sycl_context() assert ctx0 == ctx1 + assert hash(ctx0) == hash(ctx1) def test_hashing_of_queue(): From 8d76c22aa01d0841f875cdf5daba13064f33fe50 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 18 Jun 2021 16:37:32 -0500 Subject: [PATCH 7/9] try to use 'python -m pytest args' rather than 'pytest args' --- conda-recipe/run_test.bat | 2 +- conda-recipe/run_test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conda-recipe/run_test.bat b/conda-recipe/run_test.bat index 0d7f07db97..d8980568c1 100644 --- a/conda-recipe/run_test.bat +++ b/conda-recipe/run_test.bat @@ -11,5 +11,5 @@ set ERRORLEVEL= "%PYTHON%" -c "import dpctl" if errorlevel 1 exit 1 -pytest -q -ra --disable-warnings --pyargs dpctl -vv +python -m pytest -q -ra --disable-warnings --pyargs dpctl -vv if errorlevel 1 exit 1 diff --git a/conda-recipe/run_test.sh b/conda-recipe/run_test.sh index c0ecfec7e3..bc97603723 100644 --- a/conda-recipe/run_test.sh +++ b/conda-recipe/run_test.sh @@ -6,4 +6,4 @@ set -e source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true ${PYTHON} -c "import dpctl" -pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv +python -m pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv From a005320225e9f6d1ff2c1b80ae86be82431d4cd8 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 21 Jun 2021 10:32:31 -0500 Subject: [PATCH 8/9] Test runners should not be activating oneAPI. More recent run-times are being installed into Python environment and should be used instead of those in the compiler installation --- conda-recipe/run_test.bat | 8 -------- conda-recipe/run_test.sh | 3 --- 2 files changed, 11 deletions(-) diff --git a/conda-recipe/run_test.bat b/conda-recipe/run_test.bat index d8980568c1..2154d564b2 100644 --- a/conda-recipe/run_test.bat +++ b/conda-recipe/run_test.bat @@ -1,11 +1,3 @@ -call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" -if errorlevel 1 ( - echo "oneAPI compiler activation failed%" - exit /b 1 -) -REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. -set ERRORLEVEL= - @echo on "%PYTHON%" -c "import dpctl" diff --git a/conda-recipe/run_test.sh b/conda-recipe/run_test.sh index bc97603723..01cbba54b4 100644 --- a/conda-recipe/run_test.sh +++ b/conda-recipe/run_test.sh @@ -2,8 +2,5 @@ set -e -# Suppress error b/c it could fail on Ubuntu 18.04 -source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true - ${PYTHON} -c "import dpctl" python -m pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv From 75ac845dcd9935589ac21340d5e117befcbf03f9 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 21 Jun 2021 15:14:22 -0500 Subject: [PATCH 9/9] changes per PR feedback --- .../include/dpctl_sycl_context_interface.h | 5 +- .../include/dpctl_sycl_queue_interface.h | 62 ++++++++++--------- dpctl/_sycl_context.pyx | 2 +- dpctl/_sycl_device.pyx | 2 +- dpctl/_sycl_queue.pyx | 2 +- dpctl/tests/test_sycl_context.py | 3 +- dpctl/tests/test_sycl_device.py | 3 +- dpctl/tests/test_sycl_queue.py | 3 +- 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/dpctl-capi/include/dpctl_sycl_context_interface.h b/dpctl-capi/include/dpctl_sycl_context_interface.h index a5e9526849..f93125092d 100644 --- a/dpctl-capi/include/dpctl_sycl_context_interface.h +++ b/dpctl-capi/include/dpctl_sycl_context_interface.h @@ -162,11 +162,10 @@ DPCTL_API void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef); /*! - * @brief Wrapper over - * std::hash's operator() + * @brief Wrapper over std::hash's operator() * * @param CtxRef The DPCTLSyclContextRef pointer. - * @return Hash value of the underlying sycl::context instance. + * @return Hash value of the underlying ``sycl::context`` instance. * @ingroup ContextInterface */ DPCTL_API diff --git a/dpctl-capi/include/dpctl_sycl_queue_interface.h b/dpctl-capi/include/dpctl_sycl_queue_interface.h index 9ace0ecf39..08cfae264d 100644 --- a/dpctl-capi/include/dpctl_sycl_queue_interface.h +++ b/dpctl-capi/include/dpctl_sycl_queue_interface.h @@ -126,10 +126,11 @@ __dpctl_give DPCTLSyclQueueRef DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef); /*! - * @brief Checks if two DPCTLSyclQueueRef 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. + * @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. * @ingroup QueueInterface */ @@ -174,11 +175,12 @@ DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef); * @brief Submits the kernel to the specified queue with the provided range * argument. * - * A wrapper over sycl::queue.submit(). The function takes an interoperability - * kernel, the kernel arguments, and a Sycl queue as input. The kernel is - * submitted as parallel_for(range, *unwrap(KRef)). + * A wrapper over ``sycl::queue.submit()``. The function takes an + * interoperability kernel, the kernel arguments, and a ``sycl::queue`` as + * input. The kernel is submitted as + * ``parallel_for(range, *unwrap(KRef))``. * - * \todo sycl::buffer arguments are not supported yet. + * \todo ``sycl::buffer`` arguments are not supported yet. * \todo Add support for id WorkItemOffset * * @param KRef Opaque pointer to an OpenCL interoperability kernel @@ -195,11 +197,11 @@ DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef); * dimensions. * @param NRange Size of the gRange array. * @param DepEvents List of dependent DPCTLSyclEventRef objects (events) - * for the kernel. We call sycl::handler.depends_on for - * each of the provided 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. + * @return An opaque pointer to the ``sycl::event`` returned by the + * ``sycl::queue.submit()`` function. * @ingroup QueueInterface */ DPCTL_API @@ -218,9 +220,9 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef, * @brief Submits the kernel to the specified queue with the provided nd_range * argument. * - * A wrapper over sycl::queue.submit(). The function takes an interoperability - * kernel, the kernel arguments, and a Sycl queue as input. The kernel is - * submitted as parallel_for(nd_range, *unwrap(KRef)). + * A wrapper over ``sycl::queue.submit()``. The function takes an + * interoperability kernel, the kernel arguments, and a Sycl queue as input. + * The kernel is submitted as ``parallel_for(nd_range, *unwrap(KRef))``. * * \todo sycl::buffer arguments are not supported yet. * \todo Add support for id WorkItemOffset @@ -243,11 +245,11 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef, * @param NDims The number of dimensions for both local and global * ranges. * @param DepEvents List of dependent DPCTLSyclEventRef objects (events) - * for the kernel. We call sycl::handler.depends_on for - * each of the provided 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. + * @return An opaque pointer to the ``sycl::event`` returned by the + * ``sycl::queue.submit()`` function. * @ingroup QueueInterface */ DPCTL_API @@ -264,20 +266,20 @@ DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, size_t NDepEvents); /*! - * @brief Calls the sycl::queue.submit function to do a blocking wait on all - * enqueued tasks in the queue. + * @brief Calls the ``sycl::queue.submit`` function to do a blocking wait on + * all enqueued tasks in the queue. * - * @param QRef Opaque pointer to a sycl::queue. + * @param QRef Opaque pointer to a ``sycl::queue``. * @ingroup QueueInterface */ DPCTL_API void DPCTLQueue_Wait(__dpctl_keep const DPCTLSyclQueueRef QRef); /*! - * @brief C-API wrapper for sycl::queue::memcpy, the function waits on an event - * till the memcpy operation completes. + * @brief C-API wrapper for ``sycl::queue::memcpy``, the function waits on an + * event till the memcpy operation completes. * - * @param QRef An opaque pointer to the sycl queue. + * @param QRef An opaque pointer to the ``sycl::queue``. * @param Dest An USM pointer to the destination memory. * @param Src An USM pointer to the source memory. * @param Count A number of bytes to copy. @@ -290,10 +292,10 @@ void DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef, size_t Count); /*! - * @brief C-API wrapper for sycl::queue::prefetch, the function waits on an + * @brief C-API wrapper for ``sycl::queue::prefetch``, the function waits on an * event till the prefetch operation completes. * - * @param QRef An opaque pointer to the sycl queue. + * @param QRef An opaque pointer to the ``sycl::queue``. * @param Ptr An USM pointer to memory. * @param Count A number of bytes to prefetch. * @ingroup QueueInterface @@ -307,7 +309,7 @@ void DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef, * @brief C-API wrapper for sycl::queue::mem_advise, the function waits on an * event till the operation completes. * - * @param QRef An opaque pointer to the sycl queue. + * @param QRef An opaque pointer to the ``sycl::queue``. * @param Ptr An USM pointer to memory. * @param Count A number of bytes to prefetch. * @param Advice Device-defined advice for the specified allocation. @@ -325,7 +327,7 @@ void DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef, * @brief C-API wrapper for sycl::queue::is_in_order that indicates whether * the referenced queue is in-order or out-of-order. * - * @param QRef An opaque pointer to the sycl queue. + * @param QRef An opaque pointer to the ``sycl::queue``. * @ingroup QueueInterface */ DPCTL_API @@ -334,8 +336,8 @@ bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef); /*! * @brief C-API wrapper for std::hash's operator(). * - * @param QRef An opaque pointer to the sycl queue. - * @return Hash value. + * @param QRef An opaque pointer to the ``sycl::queue``. + * @return Hash value of the underlying ``sycl::queue`` instance. * @ingroup QueueInterface */ DPCTL_API diff --git a/dpctl/_sycl_context.pyx b/dpctl/_sycl_context.pyx index 3fbdbb6f53..0ceafe857c 100644 --- a/dpctl/_sycl_context.pyx +++ b/dpctl/_sycl_context.pyx @@ -338,7 +338,7 @@ cdef class SyclContext(_SyclContext): def __hash__(self): """ - Returns hash value corresponding to ``self._ctxt_ref``. + Returns a hash value by hashing the underlying ``sycl::context`` object. """ return DPCTLContext_Hash(self._ctxt_ref) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 7d40f7aca5..31d20c8928 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -712,7 +712,7 @@ cdef class SyclDevice(_SyclDevice): def __hash__(self): """ - Returns hash value corresponding to ``self._device_ref``. + Returns a hash value by hashing the underlying ``sycl::device`` object. """ return DPCTLDevice_Hash(self._device_ref) diff --git a/dpctl/_sycl_queue.pyx b/dpctl/_sycl_queue.pyx index 3e91646644..41586fd3b5 100644 --- a/dpctl/_sycl_queue.pyx +++ b/dpctl/_sycl_queue.pyx @@ -866,7 +866,7 @@ cdef class SyclQueue(_SyclQueue): def __hash__(self): """ - Returns hash value corresponding to ``self._queue_ref``. + Returns a hash value by hashing the underlying ``sycl::queue`` object. """ return DPCTLQueue_Hash(self._queue_ref) diff --git a/dpctl/tests/test_sycl_context.py b/dpctl/tests/test_sycl_context.py index d4ab8c09a8..756c92cbd7 100644 --- a/dpctl/tests/test_sycl_context.py +++ b/dpctl/tests/test_sycl_context.py @@ -163,7 +163,8 @@ def test_context_multi_device(): def test_hashing_of_context(): """ - Test that a SyclContext object can be used as a dictionary key. + Test that a :class:`dpctl.SyclContext` object can be used + as a dictionary key. """ ctx_dict = {dpctl.SyclContext(): "default_context"} diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 77a12fc8de..ddf72268c8 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -639,7 +639,8 @@ def test_filter_string_method(): def test_hashing_of_device(): """ - Test that a SyclDevice object can be used as a dictionary key. + Test that a :class:`dpctl.SyclDevice` object can be used as + a dictionary key. """ device_dict = {dpctl.SyclDevice(): "default_device"} diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index 568e709e3c..9d3b1008a7 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -375,7 +375,8 @@ def test_context_equals(): def test_hashing_of_queue(): """ - Test that a SyclQueue object can be used as a dictionary key. + Test that a :class:`dpctl.SyclQueue` object can be used as + a dictionary key. """ queue_dict = {dpctl.SyclQueue(): "default_queue"}