Skip to content

Commit 7928588

Browse files
author
AidanBeltonS
authored
[SYCL][COMPAT] Add device_count and testing (#14013)
This PR adds the syclcompat free function `device_count`. It provides testing for this new function and for `get_device_id()`
1 parent 4151c79 commit 7928588

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

sycl/doc/syclcompat/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,12 @@ static inline void list_devices();
918918
// Util function to select a device by its id
919919
static inline unsigned int select_device(unsigned int id);
920920

921+
// Util function to get the device id from a device
922+
static inline unsigned int get_device_id(const sycl::device &dev);
923+
924+
// Util function to get the number of available devices
925+
static inline unsigned int device_count();
926+
921927
} // syclcompat
922928
```
923929

sycl/include/syclcompat/device.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,4 +938,7 @@ static inline unsigned int get_device_id(const sycl::device &dev) {
938938
return detail::dev_mgr::instance().get_device_id(dev);
939939
}
940940
941+
static inline unsigned int device_count() {
942+
return detail::dev_mgr::instance().device_count();
943+
}
941944
} // namespace syclcompat

sycl/test-e2e/syclcompat/device/device.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ void test_list_devices() {
377377
assert(countingBuf.get_line_count() == dtf.get_n_devices());
378378
}
379379

380+
void test_device_count() {
381+
std::cout << __PRETTY_FUNCTION__ << std::endl;
382+
383+
unsigned int count = syclcompat::device_count();
384+
assert(count > 0);
385+
}
386+
387+
void test_get_device_id() {
388+
std::cout << __PRETTY_FUNCTION__ << std::endl;
389+
390+
sycl::device dev = syclcompat::get_device(0);
391+
unsigned int id = syclcompat::get_device_id(dev);
392+
assert(id == 0);
393+
}
394+
380395
int main() {
381396
test_at_least_one_device();
382397
test_matches_id();
@@ -396,6 +411,8 @@ int main() {
396411
test_image_max_attrs();
397412
test_max_nd_range();
398413
test_list_devices();
414+
test_device_count();
415+
test_get_device_id();
399416

400417
return 0;
401418
}

sycl/test-e2e/syclcompat/device/device_fixt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DeviceTestsFixt {
3232

3333
public:
3434
DeviceTestsFixt()
35-
: n_devices{syclcompat::detail::dev_mgr::instance().device_count()},
35+
: n_devices{syclcompat::device_count()},
3636
def_q_{syclcompat::get_default_queue()} {}
3737

3838
unsigned int get_n_devices() { return n_devices; }

0 commit comments

Comments
 (0)