Skip to content

Commit 2b6b51c

Browse files
committed
[SYCL] Throw an exception for unsupported aspect
The runtime must throw an exception whenever the application attempts to submit a kernel to a device where the kernel uses a feature that is not compatible with the device.
1 parent 08b2022 commit 2b6b51c

File tree

6 files changed

+97
-45
lines changed

6 files changed

+97
-45
lines changed

sycl/include/sycl/aspects.hpp

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,13 @@
1212
namespace sycl {
1313
__SYCL_INLINE_VER_NAMESPACE(_V1) {
1414

15+
#define __SYCL_ASPECT(A, B, C) A = B,
16+
#define __SYCL_SPECIAL_ASPECT(A, B, C) A = B,
1517
enum class __SYCL_TYPE(aspect) aspect {
16-
host = 0,
17-
cpu = 1,
18-
gpu = 2,
19-
accelerator = 3,
20-
custom = 4,
21-
fp16 = 5,
22-
fp64 = 6,
23-
int64_base_atomics __SYCL2020_DEPRECATED("use atomic64 instead") = 7,
24-
int64_extended_atomics __SYCL2020_DEPRECATED("use atomic64 instead") = 8,
25-
image = 9,
26-
online_compiler = 10,
27-
online_linker = 11,
28-
queue_profiling = 12,
29-
usm_device_allocations = 13,
30-
usm_host_allocations = 14,
31-
usm_shared_allocations = 15,
32-
usm_restricted_shared_allocations = 16,
33-
usm_system_allocations = 17,
34-
usm_system_allocator __SYCL2020_DEPRECATED(
35-
"use usm_system_allocations instead") = usm_system_allocations,
36-
ext_intel_pci_address = 18,
37-
ext_intel_gpu_eu_count = 19,
38-
ext_intel_gpu_eu_simd_width = 20,
39-
ext_intel_gpu_slices = 21,
40-
ext_intel_gpu_subslices_per_slice = 22,
41-
ext_intel_gpu_eu_count_per_subslice = 23,
42-
ext_intel_max_mem_bandwidth = 24,
43-
ext_intel_mem_channel = 25,
44-
usm_atomic_host_allocations = 26,
45-
usm_atomic_shared_allocations = 27,
46-
atomic64 = 28,
47-
ext_intel_device_info_uuid = 29,
48-
ext_oneapi_srgb = 30,
49-
ext_oneapi_native_assert = 31,
50-
host_debuggable = 32,
51-
ext_intel_gpu_hw_threads_per_eu = 33,
52-
ext_oneapi_cuda_async_barrier = 34,
53-
ext_oneapi_bfloat16 = 35,
54-
ext_intel_free_memory = 36,
18+
#include <sycl/info/aspects.def>
5519
};
20+
#undef __SYCL_SPECIAL_ASPECT
21+
#undef __SYCL_ASPECT
5622

5723
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
5824
} // namespace sycl

sycl/include/sycl/detail/pi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4;
752752
#define __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS "SYCL/exported symbols"
753753
/// PropertySetRegistry::SYCL_DEVICE_GLOBALS defined in PropertySetIO.h
754754
#define __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_GLOBALS "SYCL/device globals"
755+
/// PropertySetRegistry::SYCL_DEVICE_REQUIREMENTS defined in PropertySetIO.h
756+
#define __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_REQUIREMENTS \
757+
"SYCL/device requirements"
755758

756759
/// Program metadata tags recognized by the PI backends. For kernels the tag
757760
/// must appear after the kernel name.

sycl/include/sycl/info/aspects.def

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
__SYCL_ASPECT(host, 0, "host")
2+
__SYCL_ASPECT(cpu, 1, "cpu")
3+
__SYCL_ASPECT(gpu, 2, "gpu")
4+
__SYCL_ASPECT(accelerator, 3, "accelerator")
5+
__SYCL_ASPECT(custom, 4, "custom")
6+
__SYCL_ASPECT(fp16, 5, "fp16")
7+
__SYCL_ASPECT(fp64, 6, "fp64")
8+
__SYCL_ASPECT(int64_base_atomics __SYCL2020_DEPRECATED("use atomic64 instead"), 7, "int64_base_atomics")
9+
__SYCL_ASPECT(int64_extended_atomics __SYCL2020_DEPRECATED("use atomic64 instead"), 8, "int64_extended_atomics")
10+
__SYCL_ASPECT(image, 9, "image")
11+
__SYCL_ASPECT(online_compiler, 10, "online_compiler")
12+
__SYCL_ASPECT(online_linker, 11, "online_linker")
13+
__SYCL_ASPECT(queue_profiling, 12, "queue_profiling")
14+
__SYCL_ASPECT(usm_device_allocations, 13, "usm_device_allocations")
15+
__SYCL_ASPECT(usm_host_allocations, 14, "usm_host_allocations")
16+
__SYCL_ASPECT(usm_shared_allocations, 15, "usm_shared_allocations")
17+
__SYCL_ASPECT(usm_restricted_shared_allocations, 16, "usm_restricted_shared_allocations")
18+
__SYCL_ASPECT(usm_system_allocations, 17, "usm_system_allocations")
19+
__SYCL_SPECIAL_ASPECT(usm_system_allocator __SYCL2020_DEPRECATED("use usm_system_allocations instead"), usm_system_allocations, "usm_system_allocations")
20+
__SYCL_ASPECT(ext_intel_pci_address, 18, "ext_intel_pci_address")
21+
__SYCL_ASPECT(ext_intel_gpu_eu_count, 19, "ext_intel_gpu_eu_count")
22+
__SYCL_ASPECT(ext_intel_gpu_eu_simd_width, 20, "ext_intel_gpu_eu_simd_width")
23+
__SYCL_ASPECT(ext_intel_gpu_slices, 21, "ext_intel_gpu_slices")
24+
__SYCL_ASPECT(ext_intel_gpu_subslices_per_slice, 22, "ext_intel_gpu_subslices_per_slice")
25+
__SYCL_ASPECT(ext_intel_gpu_eu_count_per_subslice, 23, "ext_intel_gpu_eu_count_per_subslice")
26+
__SYCL_ASPECT(ext_intel_max_mem_bandwidth, 24, "ext_intel_max_mem_bandwidth")
27+
__SYCL_ASPECT(ext_intel_mem_channel, 25, "ext_intel_mem_channel")
28+
__SYCL_ASPECT(usm_atomic_host_allocations, 26, "usm_atomic_host_allocations")
29+
__SYCL_ASPECT(usm_atomic_shared_allocations, 27, "usm_atomic_shared_allocations")
30+
__SYCL_ASPECT(atomic64, 28, "atomic64")
31+
__SYCL_ASPECT(ext_intel_device_info_uuid, 29, "ext_intel_device_info_uuid")
32+
__SYCL_ASPECT(ext_oneapi_srgb, 30, "ext_oneapi_srgb")
33+
__SYCL_ASPECT(ext_oneapi_native_assert, 31, "ext_oneapi_native_assert")
34+
__SYCL_ASPECT(host_debuggable, 32, "host_debuggable")
35+
__SYCL_ASPECT(ext_intel_gpu_hw_threads_per_eu, 33, "ext_intel_gpu_hw_threads_per_eu")
36+
__SYCL_ASPECT(ext_oneapi_cuda_async_barrier, 34, "ext_oneapi_cuda_async_barrier")
37+
__SYCL_ASPECT(ext_oneapi_bfloat16, 35, "ext_oneapi_bfloat16")
38+
__SYCL_ASPECT(ext_intel_free_memory, 36, "ext_intel_free_memory")
39+

sycl/source/detail/device_binary_image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ void RTDeviceBinaryImage::init(pi_device_binary Bin) {
175175
ProgramMetadata.init(Bin, __SYCL_PI_PROPERTY_SET_PROGRAM_METADATA);
176176
ExportedSymbols.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS);
177177
DeviceGlobals.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_GLOBALS);
178+
DeviceRequirements.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_REQUIREMENTS);
178179
}
179180

180181
DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(

sycl/source/detail/device_binary_image.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ class RTDeviceBinaryImage {
190190
const PropertyRange &getProgramMetadata() const { return ProgramMetadata; }
191191
const PropertyRange &getExportedSymbols() const { return ExportedSymbols; }
192192
const PropertyRange &getDeviceGlobals() const { return DeviceGlobals; }
193+
const PropertyRange &getDeviceRequirements() const {
194+
return DeviceRequirements;
195+
}
193196

194197
protected:
195198
void init(pi_device_binary Bin);
@@ -207,6 +210,7 @@ class RTDeviceBinaryImage {
207210
RTDeviceBinaryImage::PropertyRange ProgramMetadata;
208211
RTDeviceBinaryImage::PropertyRange ExportedSymbols;
209212
RTDeviceBinaryImage::PropertyRange DeviceGlobals;
213+
RTDeviceBinaryImage::PropertyRange DeviceRequirements;
210214
};
211215

212216
// Dynamically allocated device binary image, which de-allocates its binary

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <detail/program_impl.hpp>
1616
#include <detail/program_manager/program_manager.hpp>
1717
#include <detail/spec_constant_impl.hpp>
18+
#include <sycl/aspects.hpp>
1819
#include <sycl/backend_types.hpp>
1920
#include <sycl/context.hpp>
2021
#include <sycl/detail/common.hpp>
@@ -543,14 +544,52 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(
543544

544545
DeviceImplPtr Dev =
545546
(MustBuildOnSubdevice == PI_TRUE) ? DeviceImpl : RootDevImpl;
546-
auto BuildF = [this, &M, &KSId, &ContextImpl, &Dev, Prg, &CompileOpts,
547-
&LinkOpts, &JITCompilationIsRequired, SpecConsts] {
548-
auto Context = createSyclObjFromImpl<context>(ContextImpl);
549-
auto Device = createSyclObjFromImpl<device>(Dev);
547+
auto Context = createSyclObjFromImpl<context>(ContextImpl);
548+
auto Device = createSyclObjFromImpl<device>(Dev);
549+
const RTDeviceBinaryImage &Img =
550+
getDeviceImage(M, KSId, Context, Device, JITCompilationIsRequired);
551+
552+
// Check that device supports all aspects used by the kernel
553+
const RTDeviceBinaryImage::PropertyRange &ARange =
554+
Img.getDeviceRequirements();
555+
556+
#define __SYCL_ASPECT(A, B, C) \
557+
case aspect::A: \
558+
return C;
559+
#define __SYCL_SPECIAL_ASPECT(A, B, C)
560+
auto getAspectNameStr = [](aspect AspectNum) -> std::string {
561+
switch (AspectNum) {
562+
#include <sycl/info/aspects.def>
563+
default:
564+
throw sycl::exception(
565+
errc::kernel_not_supported,
566+
"Unknown aspect " + std::to_string(static_cast<unsigned>(AspectNum)));
567+
}
568+
};
569+
#undef __SYCL_SPECIAL_ASPECT
570+
#undef __SYCL_ASPECT
550571

551-
const RTDeviceBinaryImage &Img =
552-
getDeviceImage(M, KSId, Context, Device, JITCompilationIsRequired);
572+
for (RTDeviceBinaryImage::PropertyRange::ConstIterator It : ARange) {
573+
auto KName = std::string((*It)->Name);
574+
if (KName != "aspects")
575+
continue;
576+
ByteArray Aspects = DeviceBinaryProperty(*It).asByteArray();
577+
// 8 because we need to skip 64-bits of size of the byte array
578+
auto *AIt = reinterpret_cast<const std::uint32_t *>(&Aspects[8]);
579+
auto *AEnd =
580+
reinterpret_cast<const std::uint32_t *>(&Aspects[0] + Aspects.size());
581+
while (AIt != AEnd) {
582+
auto Aspect = static_cast<aspect>(*AIt);
583+
if (!Dev->has(Aspect))
584+
throw sycl::exception(errc::kernel_not_supported,
585+
"Required aspect " + getAspectNameStr(Aspect) +
586+
" is not supported on the device");
587+
++AIt;
588+
}
589+
}
553590

591+
auto BuildF = [this, &Img, &Context, &ContextImpl, &Device, Prg, &CompileOpts,
592+
&LinkOpts, SpecConsts, &KernelName] {
554593
applyOptionsFromImage(CompileOpts, LinkOpts, Img);
555594

556595
const detail::plugin &Plugin = ContextImpl->getPlugin();

0 commit comments

Comments
 (0)