Skip to content

Commit 9b33a43

Browse files
authoredJan 30, 2024
[SYCL] Add support for ext_intel_matrix aspect (#12512)
This PR adds the aspect for the sycl_ext_intel_matrix extension and allows code to verify whether the device supports the advanced matrix API. The aspect has been added to the aspect definition file and the corresponding macro has been added to the feature test file set to 1 meaning supported.
1 parent a934d57 commit 9b33a43

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed
 

‎llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def AspectExt_oneapi_ballot_group : Aspect<"ext_oneapi_ballot_group">;
6666
def AspectExt_oneapi_fixed_size_group : Aspect<"ext_oneapi_fixed_size_group">;
6767
def AspectExt_oneapi_opportunistic_group : Aspect<"ext_oneapi_opportunistic_group">;
6868
def AspectExt_oneapi_tangle_group : Aspect<"ext_oneapi_tangle_group">;
69+
def AspectExt_intel_matrix : Aspect<"ext_intel_matrix">;
6970
// Deprecated aspects
7071
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
7172
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics">;
@@ -115,7 +116,7 @@ def : TargetInfo<"__TestAspectList",
115116
AspectExt_oneapi_interop_memory_import, AspectExt_oneapi_interop_memory_export,
116117
AspectExt_oneapi_interop_semaphore_import, AspectExt_oneapi_interop_semaphore_export,
117118
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd,
118-
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group, AspectExt_oneapi_tangle_group],
119+
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group, AspectExt_oneapi_tangle_group, AspectExt_intel_matrix],
119120
[]>;
120121
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
121122
// match.

‎sycl/include/sycl/device_aspect_macros.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@
298298
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_tangle_group__ 0
299299
#endif
300300

301+
#ifndef __SYCL_ALL_DEVICES_HAVE_ext_intel_matrix__
302+
// __SYCL_ASPECT(ext_intel_matrix, 58)
303+
#define __SYCL_ALL_DEVICES_HAVE_ext_intel_matrix__ 0
304+
#endif
305+
301306
#ifndef __SYCL_ANY_DEVICE_HAS_host__
302307
// __SYCL_ASPECT(host, 0)
303308
#define __SYCL_ANY_DEVICE_HAS_host__ 0
@@ -587,3 +592,8 @@
587592
// __SYCL_ASPECT(ext_oneapi_tangle_group, 57)
588593
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_tangle_group__ 0
589594
#endif
595+
596+
#ifndef __SYCL_ANY_DEVICE_HAS_ext_intel_matrix__
597+
// __SYCL_ASPECT(ext_intel_matrix, 58)
598+
#define __SYCL_ANY_DEVICE_HAS_ext_intel_matrix__ 0
599+
#endif

‎sycl/include/sycl/info/aspects.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ __SYCL_ASPECT(ext_oneapi_ballot_group, 54)
5252
__SYCL_ASPECT(ext_oneapi_fixed_size_group, 55)
5353
__SYCL_ASPECT(ext_oneapi_opportunistic_group, 56)
5454
__SYCL_ASPECT(ext_oneapi_tangle_group, 57)
55+
__SYCL_ASPECT(ext_intel_matrix, 58)

‎sycl/source/detail/device_impl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ bool device_impl::has(aspect Aspect) const {
567567
return (this->getBackend() == backend::ext_oneapi_level_zero) ||
568568
(this->getBackend() == backend::opencl);
569569
}
570+
case aspect::ext_intel_matrix: {
571+
using arch = sycl::ext::oneapi::experimental::architecture;
572+
const std::vector<arch> supported_archs = {
573+
arch::intel_cpu_spr, arch::intel_gpu_pvc, arch::intel_gpu_dg2_g10,
574+
arch::intel_gpu_dg2_g11, arch::intel_gpu_dg2_g12};
575+
try {
576+
return std::any_of(
577+
supported_archs.begin(), supported_archs.end(),
578+
[=](const arch a) { return this->extOneapiArchitectureIs(a); });
579+
} catch (const sycl::exception &) {
580+
// If we're here it means the device does not support architecture
581+
// querying
582+
return false;
583+
}
584+
}
570585
}
571586
throw runtime_error("This device aspect has not been implemented yet.",
572587
PI_ERROR_INVALID_DEVICE);

‎sycl/source/detail/device_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ class device_impl {
234234

235235
std::string getDeviceName() const;
236236

237-
bool extOneapiArchitectureIs(ext::oneapi::experimental::architecture Arch) {
237+
bool
238+
extOneapiArchitectureIs(ext::oneapi::experimental::architecture Arch) const {
238239
return Arch == getDeviceArch();
239240
}
240241

‎sycl/source/feature_test.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ inline namespace _V1 {
9999
#define SYCL_EXT_INTEL_FP_CONTROL 1
100100
#define SYCL_EXT_ONEAPI_NON_UNIFORM_GROUPS 1
101101
#define SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS 1
102+
#define SYCL_EXT_INTEL_MATRIX 1
102103

103104
#ifndef __has_include
104105
#define __has_include(x) 0

‎sycl/test-e2e/Basic/AMX_aspect.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %t.out
3+
//
4+
5+
//==--------------- AMX_aspect.cpp - SYCL device test
6+
//------------------------==//
7+
//
8+
// Checks that the has(aspect) method on a device returns the correct answer
9+
// when queried about ext_intel_matrix AMX aspect.
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include <iostream>
18+
#include <sycl/sycl.hpp>
19+
20+
using namespace sycl;
21+
using arch = sycl::ext::oneapi::experimental::architecture;
22+
int main() {
23+
const std::vector<arch> supported_archs = {
24+
arch::intel_cpu_spr, arch::intel_gpu_pvc, arch::intel_gpu_dg2_g10,
25+
arch::intel_gpu_dg2_g11, arch::intel_gpu_dg2_g12};
26+
for (const auto &plt : platform::get_platforms()) {
27+
for (auto &dev : plt.get_devices()) {
28+
try {
29+
if (std::any_of(supported_archs.begin(), supported_archs.end(),
30+
[&](const auto &a) {
31+
return dev.ext_oneapi_architecture_is(a);
32+
})) {
33+
assert(dev.has(sycl::aspect::ext_intel_matrix));
34+
}
35+
} catch (sycl::exception &) {
36+
}
37+
}
38+
}
39+
return 0;
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.