Skip to content

Commit 4897bc2

Browse files
Change device_count to a property
Added two more tests to test_sycl_context.py One of them is skipped due to a bug in DPC++, which is expected to be fixed in update 2 of oneAPI 2021
1 parent b2ebb8a commit 4897bc2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

dpctl/_sycl_context.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ cdef class SyclContext(_SyclContext):
207207
devices.append(SyclDevice._create(DRef))
208208
DPCTLDeviceVector_Delete(DVRef)
209209
return devices
210-
210+
211+
@property
211212
def device_count (self):
212213
"""
213-
Returns the number of sycl devices associated with SyclContext instance.
214+
The number of sycl devices associated with SyclContext instance.
214215
"""
215216
cdef size_t num_devs = DPCTLContext_DeviceCount(self.get_context_ref())
216217
if num_devs:
@@ -224,7 +225,7 @@ cdef class SyclContext(_SyclContext):
224225
return "SyclContext"
225226

226227
def __repr__(self):
227-
cdef size_t n = self.device_count()
228+
cdef size_t n = self.device_count
228229
if n == 1:
229230
return ("<dpctl." + self.__name__ + " at {}>".format(hex(id(self))))
230231
else:

dpctl/tests/test_sycl_context.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
""" Defines unit test cases for the SyclQueue class.
17+
""" Defines unit test cases for the SyclContxt class.
1818
"""
1919

2020
import dpctl
2121
import pytest
2222

23+
2324
list_of_standard_selectors = [
2425
dpctl.select_accelerator_device,
2526
dpctl.select_cpu_device,
@@ -358,3 +359,24 @@ def test_context_equals():
358359
except dpctl.SyclQueueCreationError:
359360
pytest.skip()
360361
assert ctx0.equals(ctx1)
362+
363+
364+
def test_context_can_be_used_in_queue(valid_filter):
365+
try:
366+
ctx = dpctl.SyclContext(valid_filter)
367+
except ValueError:
368+
pytest.skip()
369+
devs = ctx.get_devices()
370+
assert len(devs) == ctx.device_count
371+
for d in devs:
372+
q = dpctl.SyclQueue(ctx, d)
373+
374+
375+
@pytest.mark.xfail(reason="DPC++ bug in device equality")
376+
def test_context_can_be_used_in_queue2(valid_filter):
377+
d = dpctl.SyclDevice(valid_filter)
378+
if d.default_selector_score < 0:
379+
# skip test for devices rejected by default selector
380+
pytest.skip()
381+
ctx = dpctl.SyclContext(d)
382+
q = dpctl.SyclQueue(ctx, d)

0 commit comments

Comments
 (0)