|
| 1 | +#include "dpctl4pybind11.hpp" |
| 2 | +#include <pybind11/pybind11.h> |
| 3 | +#include <pybind11/stl.h> |
| 4 | +#include <sycl/sycl.hpp> |
| 5 | + |
| 6 | +#include <cstddef> |
| 7 | +#include <cstdint> |
| 8 | + |
| 9 | +namespace |
| 10 | +{ |
| 11 | + |
| 12 | +std::uint32_t py_intel_device_id(const sycl::device &d) |
| 13 | +{ |
| 14 | + static constexpr std::uint32_t device_id_unavailable = 0; |
| 15 | + |
| 16 | + if (d.has(sycl::aspect::ext_intel_device_id)) { |
| 17 | + return d.get_info<sycl::ext::intel::info::device::device_id>(); |
| 18 | + } |
| 19 | + |
| 20 | + return device_id_unavailable; |
| 21 | +} |
| 22 | + |
| 23 | +std::uint32_t py_intel_gpu_eu_count(const sycl::device &d) |
| 24 | +{ |
| 25 | + static constexpr std::uint32_t eu_count_unavailable = 0; |
| 26 | + |
| 27 | + if (d.has(sycl::aspect::ext_intel_gpu_eu_count)) { |
| 28 | + return d.get_info<sycl::ext::intel::info::device::gpu_eu_count>(); |
| 29 | + } |
| 30 | + |
| 31 | + return eu_count_unavailable; |
| 32 | +} |
| 33 | + |
| 34 | +std::uint32_t py_intel_gpu_hw_threads_per_eu(const sycl::device &d) |
| 35 | +{ |
| 36 | + static constexpr std::uint32_t thread_count_unavailable = 0; |
| 37 | + |
| 38 | + if (d.has(sycl::aspect::ext_intel_gpu_hw_threads_per_eu)) { |
| 39 | + return d |
| 40 | + .get_info<sycl::ext::intel::info::device::gpu_hw_threads_per_eu>(); |
| 41 | + } |
| 42 | + |
| 43 | + return thread_count_unavailable; |
| 44 | +} |
| 45 | + |
| 46 | +std::uint32_t py_intel_gpu_eu_simd_width(const sycl::device &d) |
| 47 | +{ |
| 48 | + static constexpr std::uint32_t width_unavailable = 0; |
| 49 | + |
| 50 | + if (d.has(sycl::aspect::ext_intel_gpu_eu_simd_width)) { |
| 51 | + return d.get_info<sycl::ext::intel::info::device::gpu_eu_simd_width>(); |
| 52 | + } |
| 53 | + |
| 54 | + return width_unavailable; |
| 55 | +} |
| 56 | + |
| 57 | +std::uint32_t py_intel_gpu_slices(const sycl::device &d) |
| 58 | +{ |
| 59 | + static constexpr std::uint32_t count_unavailable = 0; |
| 60 | + |
| 61 | + if (d.has(sycl::aspect::ext_intel_gpu_slices)) { |
| 62 | + return d.get_info<sycl::ext::intel::info::device::gpu_slices>(); |
| 63 | + } |
| 64 | + |
| 65 | + return count_unavailable; |
| 66 | +} |
| 67 | + |
| 68 | +std::uint32_t py_intel_gpu_subslices_per_slice(const sycl::device &d) |
| 69 | +{ |
| 70 | + static constexpr std::uint32_t count_unavailable = 0; |
| 71 | + |
| 72 | + if (d.has(sycl::aspect::ext_intel_gpu_subslices_per_slice)) { |
| 73 | + return d.get_info< |
| 74 | + sycl::ext::intel::info::device::gpu_subslices_per_slice>(); |
| 75 | + } |
| 76 | + |
| 77 | + return count_unavailable; |
| 78 | +} |
| 79 | + |
| 80 | +std::uint32_t py_intel_gpu_eu_count_per_subslice(const sycl::device &d) |
| 81 | +{ |
| 82 | + static constexpr std::uint32_t count_unavailable = 0; |
| 83 | + |
| 84 | + if (d.has(sycl::aspect::ext_intel_gpu_eu_count_per_subslice)) { |
| 85 | + return d.get_info< |
| 86 | + sycl::ext::intel::info::device::gpu_eu_count_per_subslice>(); |
| 87 | + } |
| 88 | + |
| 89 | + return count_unavailable; |
| 90 | +} |
| 91 | + |
| 92 | +std::uint64_t py_intel_max_mem_bandwidth(const sycl::device &d) |
| 93 | +{ |
| 94 | + static constexpr std::uint64_t bandwidth_unavailable = 0; |
| 95 | + |
| 96 | + if (d.has(sycl::aspect::ext_intel_max_mem_bandwidth)) { |
| 97 | + return d.get_info<sycl::ext::intel::info::device::max_mem_bandwidth>(); |
| 98 | + } |
| 99 | + |
| 100 | + return bandwidth_unavailable; |
| 101 | +} |
| 102 | + |
| 103 | +}; // namespace |
| 104 | + |
| 105 | +PYBIND11_MODULE(_device_queries, m) |
| 106 | +{ |
| 107 | + m.def("intel_device_info_device_id", &py_intel_device_id, |
| 108 | + "Get ext_intel_device_id for the device, zero if not an intel device", |
| 109 | + py::arg("device")); |
| 110 | + |
| 111 | + m.def("intel_device_info_gpu_eu_count", &py_intel_gpu_eu_count, |
| 112 | + "Returns the number of execution units (EUs) associated with the " |
| 113 | + "Intel GPU.", |
| 114 | + py::arg("device")); |
| 115 | + |
| 116 | + m.def("intel_device_info_gpu_hw_threads_per_eu", |
| 117 | + &py_intel_gpu_hw_threads_per_eu, |
| 118 | + "Returns the number of hardware threads in EU.", py::arg("device")); |
| 119 | + |
| 120 | + m.def("intel_device_info_gpu_eu_simd_width", &py_intel_gpu_eu_simd_width, |
| 121 | + "Returns the physical SIMD width of the execution unit (EU).", |
| 122 | + py::arg("device")); |
| 123 | + |
| 124 | + m.def("intel_device_info_gpu_slices", &py_intel_gpu_slices, |
| 125 | + "Returns the number of slices in the GPU device, or zero.", |
| 126 | + py::arg("device")); |
| 127 | + |
| 128 | + m.def("intel_device_info_gpu_subslices_per_slice", |
| 129 | + &py_intel_gpu_subslices_per_slice, |
| 130 | + "Returns the number of subslices per slice.", py::arg("device")); |
| 131 | + |
| 132 | + m.def("intel_device_info_gpu_eu_count_per_subslice", |
| 133 | + &py_intel_gpu_eu_count_per_subslice, |
| 134 | + "Returns the number of EUs per subslice of GPU.", py::arg("device")); |
| 135 | + |
| 136 | + m.def("intel_device_info_max_mem_bandwidth", &py_intel_max_mem_bandwidth, |
| 137 | + "Returns the maximum memory bandwidth in units of bytes/second.", |
| 138 | + py::arg("device")); |
| 139 | +} |
0 commit comments