Skip to content

Commit b1619f7

Browse files
authored
[SYCL] Throw an exception for unsupported aspect (#6989)
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. Co-authored-by: @AlexeySachkov
1 parent e49aa08 commit b1619f7

File tree

8 files changed

+108
-45
lines changed

8 files changed

+108
-45
lines changed

sycl/include/sycl/aspects.hpp

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

15+
#define __SYCL_ASPECT(ASPECT, ID) ASPECT = ID,
16+
#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) \
17+
ASPECT __SYCL2020_DEPRECATED(MESSAGE) = ID,
18+
#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE) \
19+
__SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE)
1520
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,
21+
#include <sycl/info/aspects.def>
22+
#include <sycl/info/aspects_deprecated.def>
5523
};
24+
#undef __SYCL_ASPECT_DEPRECATED_ALIAS
25+
#undef __SYCL_ASPECT_DEPRECATED
26+
#undef __SYCL_ASPECT
5627

5728
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
5829
} // 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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
__SYCL_ASPECT(host, 0)
2+
__SYCL_ASPECT(cpu, 1)
3+
__SYCL_ASPECT(gpu, 2)
4+
__SYCL_ASPECT(accelerator, 3)
5+
__SYCL_ASPECT(custom, 4)
6+
__SYCL_ASPECT(fp16, 5)
7+
__SYCL_ASPECT(fp64, 6)
8+
__SYCL_ASPECT(image, 9)
9+
__SYCL_ASPECT(online_compiler, 10)
10+
__SYCL_ASPECT(online_linker, 11)
11+
__SYCL_ASPECT(queue_profiling, 12)
12+
__SYCL_ASPECT(usm_device_allocations, 13)
13+
__SYCL_ASPECT(usm_host_allocations, 14)
14+
__SYCL_ASPECT(usm_shared_allocations, 15)
15+
__SYCL_ASPECT(usm_restricted_shared_allocations, 16)
16+
__SYCL_ASPECT(usm_system_allocations, 17)
17+
__SYCL_ASPECT(ext_intel_pci_address, 18)
18+
__SYCL_ASPECT(ext_intel_gpu_eu_count, 19)
19+
__SYCL_ASPECT(ext_intel_gpu_eu_simd_width, 20)
20+
__SYCL_ASPECT(ext_intel_gpu_slices, 21)
21+
__SYCL_ASPECT(ext_intel_gpu_subslices_per_slice, 22)
22+
__SYCL_ASPECT(ext_intel_gpu_eu_count_per_subslice, 23)
23+
__SYCL_ASPECT(ext_intel_max_mem_bandwidth, 24)
24+
__SYCL_ASPECT(ext_intel_mem_channel, 25)
25+
__SYCL_ASPECT(usm_atomic_host_allocations, 26)
26+
__SYCL_ASPECT(usm_atomic_shared_allocations, 27)
27+
__SYCL_ASPECT(atomic64, 28)
28+
__SYCL_ASPECT(ext_intel_device_info_uuid, 29)
29+
__SYCL_ASPECT(ext_oneapi_srgb, 30)
30+
__SYCL_ASPECT(ext_oneapi_native_assert, 31)
31+
__SYCL_ASPECT(host_debuggable, 32)
32+
__SYCL_ASPECT(ext_intel_gpu_hw_threads_per_eu, 33)
33+
__SYCL_ASPECT(ext_oneapi_cuda_async_barrier, 34)
34+
__SYCL_ASPECT(ext_oneapi_bfloat16, 35)
35+
__SYCL_ASPECT(ext_intel_free_memory, 36)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__SYCL_ASPECT_DEPRECATED(int64_base_atomics, 7, "use atomic64 instead")
2+
__SYCL_ASPECT_DEPRECATED(int64_extended_atomics, 8, "use atomic64 instead")
3+
// Special macro for aspects that don't have own token
4+
__SYCL_ASPECT_DEPRECATED_ALIAS(usm_system_allocator, usm_system_allocations, "use usm_system_allocations instead")

sycl/include/sycl/stl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <memory>
2020
#include <mutex>
2121
#include <string>
22+
#include <string_view>
2223
#include <vector>
2324

2425
namespace sycl {

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: 50 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,57 @@ 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(ASPECT, ID) \
557+
case aspect::ASPECT: \
558+
return #ASPECT;
559+
#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) __SYCL_ASPECT(ASPECT, ID)
560+
// We don't need "case aspect::usm_allocator" here because it will duplicate
561+
// "case aspect::usm_system_allocations", therefore leave this macro empty
562+
#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE)
563+
auto getAspectNameStr = [](aspect AspectNum) -> std::string {
564+
switch (AspectNum) {
565+
#include <sycl/info/aspects.def>
566+
#include <sycl/info/aspects_deprecated.def>
567+
default:
568+
throw sycl::exception(
569+
errc::kernel_not_supported,
570+
"Unknown aspect " + std::to_string(static_cast<unsigned>(AspectNum)));
571+
}
572+
};
573+
#undef __SYCL_ASPECT_DEPRECATED_ALIAS
574+
#undef __SYCL_ASPECT_DEPRECATED
575+
#undef __SYCL_ASPECT
550576

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

596+
auto BuildF = [this, &Img, &Context, &ContextImpl, &Device, Prg, &CompileOpts,
597+
&LinkOpts, SpecConsts, &KernelName] {
554598
applyOptionsFromImage(CompileOpts, LinkOpts, Img);
555599

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

0 commit comments

Comments
 (0)