Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions c10/xpu/XPUDeviceProp.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ namespace c10::xpu {
/* the number of hardware threads per EU of GPU. */ \
_(gpu_hw_threads_per_eu, 8)

#define AT_FORALL_XPU_EXP_DEVICE_PROPERTIES(_) \
/* the device architecture of this SYCL device. \
0x9900000000000000 - should be unkown, but was \
added only recentely at \
https://github.com/intel/llvm/pull/14077 \
In version before 2025 it represents x86_64 \
Use zero for now, since this is the default value \
for triton */ \
_(architecture, 0)

#define AT_FORALL_XPU_DEVICE_ASPECT(_) \
/* sycl::half is supported on device. */ \
_(fp16) \
Expand All @@ -148,6 +158,10 @@ namespace c10::xpu {
#define DEFINE_EXT_DEVICE_PROP(property, ...) \
_DEFINE_SYCL_PROP(sycl::ext::intel::info::device, property, property)

#define DEFINE_EXP_DEVICE_PROP(property, ...) \
_DEFINE_SYCL_PROP( \
sycl::ext::oneapi::experimental::info::device, property, property)

#define DEFINE_DEVICE_ASPECT(member) bool has_##member;

struct C10_XPU_API DeviceProp {
Expand All @@ -158,6 +172,8 @@ struct C10_XPU_API DeviceProp {

AT_FORALL_XPU_EXT_DEVICE_PROPERTIES(DEFINE_EXT_DEVICE_PROP);

AT_FORALL_XPU_EXP_DEVICE_PROPERTIES(DEFINE_EXP_DEVICE_PROP);

AT_FORALL_XPU_DEVICE_ASPECT(DEFINE_DEVICE_ASPECT);
};

Expand Down
10 changes: 10 additions & 0 deletions c10/xpu/XPUFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ void initDeviceProperties(DeviceProp* device_prop, int device) {
? raw_device.get_info<intel::info::device::property>() \
: default_value;

#define ASSIGN_EXP_DEVICE_PROP(property, default_value) \
try { \
device_prop->property = \
raw_device.get_info<oneapi::experimental::info::device::property>(); \
} catch (...) { \
device_prop->property = oneapi::experimental::property(default_value); \
}

#define ASSIGN_DEVICE_ASPECT(member) \
device_prop->has_##member = raw_device.has(sycl::aspect::member);

Expand All @@ -96,6 +104,8 @@ void initDeviceProperties(DeviceProp* device_prop, int device) {

AT_FORALL_XPU_EXT_DEVICE_PROPERTIES(ASSIGN_EXT_DEVICE_PROP);

AT_FORALL_XPU_EXP_DEVICE_PROPERTIES(ASSIGN_EXP_DEVICE_PROP);

AT_FORALL_XPU_DEVICE_ASPECT(ASSIGN_DEVICE_ASPECT);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions test/test_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def test_get_device_properties(self):
self.assertEqual(
device_properties.driver_version, device_capability["driver_version"]
)
self.assertEqual(
device_properties.device_arch, device_capability["device_arch"]
)
self.assertEqual(device_properties.has_fp16, device_capability["has_fp16"])
self.assertEqual(device_properties.has_fp64, device_capability["has_fp64"])
self.assertEqual(
Expand Down
1 change: 1 addition & 0 deletions torch/_C/__init__.pyi.in
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,7 @@ def _xpu_emptyCache() -> None: ...
class _XpuDeviceProperties:
name: str
platform_name: str
device_arch: _int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
device_arch: _int
architecture: _int

vendor: str
driver_version: str
version: str
Expand Down
8 changes: 7 additions & 1 deletion torch/csrc/xpu/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ static void registerXpuDeviceProperties(PyObject* module) {
}
return stream.str();
};
auto get_device_architecture = [](const DeviceProp& prop) {
return static_cast<uint64_t>(prop.architecture);
};
auto gpu_subslice_count = [](const DeviceProp& prop) {
return (prop.gpu_eu_count / prop.gpu_eu_count_per_subslice);
};
Expand All @@ -247,12 +250,15 @@ static void registerXpuDeviceProperties(PyObject* module) {
.def_readonly("has_fp64", &DeviceProp::has_fp64)
.def_readonly("has_atomic64", &DeviceProp::has_atomic64)
.def_property_readonly("type", get_device_type)
.def_property_readonly("device_arch", get_device_architecture)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.def_property_readonly("device_arch", get_device_architecture)
.def_readonly("architecture", &DeviceProp::architecture)

Copy link
Author

@ZzEeKkAa ZzEeKkAa Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to cast from architecture to int using this way. The only option documentation suggests in this case is to import whole enum https://pybind11.readthedocs.io/en/stable/classes.html#enumerations-and-internal-types , but considering other comment it is not the intension.

I'm getting this error:

TypeError: Unable to convert function return value to a Python type! The signature was
        (self: torch._C._XpuDeviceProperties) -> sycl::_V1::ext::oneapi::experimental::architecture

.def(
"__repr__",
[&get_device_type, &gpu_subslice_count](const DeviceProp& prop) {
std::ostringstream stream;
stream << "_XpuDeviceProperties(name='" << prop.name
<< "', platform_name='" << prop.platform_name << "', type='"
<< "', platform_name='" << prop.platform_name
<< "', device_arch='"
<< static_cast<uint64_t>(prop.architecture) << "', type='"
<< get_device_type(prop) << "', driver_version='"
<< prop.driver_version << "', total_memory="
<< prop.global_mem_size / (1024ull * 1024)
Expand Down