Skip to content

Commit 92dce3d

Browse files
committed
Drop device from queries
Signed-off-by: Julian Oppermann <[email protected]>
1 parent ae8f617 commit 92dce3d

File tree

6 files changed

+43
-63
lines changed

6 files changed

+43
-63
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,17 @@ class __SYCL_EXPORT kernel_bundle_plain {
242242
ext_oneapi_get_raw_kernel_name(detail::string_view{name}).c_str()};
243243
}
244244

245-
bool ext_oneapi_has_device_global(const std::string &name,
246-
const device &dev) {
247-
return ext_oneapi_has_device_global(detail::string_view{name}, dev);
245+
bool ext_oneapi_has_device_global(const std::string &name) {
246+
return ext_oneapi_has_device_global(detail::string_view{name});
248247
}
249248

250249
void *ext_oneapi_get_device_global_address(const std::string &name,
251250
const device &dev) {
252251
return ext_oneapi_get_device_global_address(detail::string_view{name}, dev);
253252
}
254253

255-
size_t ext_oneapi_get_device_global_size(const std::string &name,
256-
const device &dev) {
257-
return ext_oneapi_get_device_global_size(detail::string_view{name}, dev);
254+
size_t ext_oneapi_get_device_global_size(const std::string &name) {
255+
return ext_oneapi_get_device_global_size(detail::string_view{name});
258256
}
259257

260258
protected:
@@ -287,12 +285,10 @@ class __SYCL_EXPORT kernel_bundle_plain {
287285
kernel ext_oneapi_get_kernel(detail::string_view name);
288286
detail::string ext_oneapi_get_raw_kernel_name(detail::string_view name);
289287

290-
bool ext_oneapi_has_device_global(detail::string_view name,
291-
const device &dev);
288+
bool ext_oneapi_has_device_global(detail::string_view name);
292289
void *ext_oneapi_get_device_global_address(detail::string_view name,
293290
const device &dev);
294-
size_t ext_oneapi_get_device_global_size(detail::string_view name,
295-
const device &dev);
291+
size_t ext_oneapi_get_device_global_size(detail::string_view name);
296292
};
297293

298294
} // namespace detail
@@ -524,20 +520,21 @@ class kernel_bundle : public detail::kernel_bundle_plain,
524520

525521
/////////////////////////
526522
// ext_oneapi_has_device_global
527-
// only true if created from source and has this global for the given device
523+
// only true if kernel_bundle was created from source and has this device
524+
// global
528525
/////////////////////////
529526
template <bundle_state _State = State,
530527
typename = std::enable_if_t<_State == bundle_state::executable>>
531-
bool ext_oneapi_has_device_global(const std::string &name,
532-
const device &dev) {
533-
return detail::kernel_bundle_plain::ext_oneapi_has_device_global(name, dev);
528+
bool ext_oneapi_has_device_global(const std::string &name) {
529+
return detail::kernel_bundle_plain::ext_oneapi_has_device_global(name);
534530
}
535531

536532
/////////////////////////
537533
// ext_oneapi_get_device_global_address
538-
// kernel_bundle must be created from source, throws if device global is not
539-
// present for the given device, or has `device_image_scope` property.
540-
// Returns a USM pointer to the variable's allocation on the device.
534+
// kernel_bundle must be created from source, throws if bundle was not built
535+
// for this device, or device global is either not present or has
536+
// `device_image_scope` property.
537+
// Returns a USM pointer to the variable's initialized storage on the device.
541538
/////////////////////////
542539
template <bundle_state _State = State,
543540
typename = std::enable_if_t<_State == bundle_state::executable>>
@@ -550,14 +547,12 @@ class kernel_bundle : public detail::kernel_bundle_plain,
550547
/////////////////////////
551548
// ext_oneapi_get_device_global_size
552549
// kernel_bundle must be created from source, throws if device global is not
553-
// present for the given device. Returns size in bytes.
550+
// present. Returns the variable's size in bytes.
554551
/////////////////////////
555552
template <bundle_state _State = State,
556553
typename = std::enable_if_t<_State == bundle_state::executable>>
557-
size_t ext_oneapi_get_device_global_size(const std::string &name,
558-
const device &dev) {
559-
return detail::kernel_bundle_plain::ext_oneapi_get_device_global_size(name,
560-
dev);
554+
size_t ext_oneapi_get_device_global_size(const std::string &name) {
555+
return detail::kernel_bundle_plain::ext_oneapi_get_device_global_size(name);
561556
}
562557

563558
private:

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -760,29 +760,16 @@ class kernel_bundle_impl {
760760
return "_Z" + std::to_string(Name.length()) + Name;
761761
}
762762

763-
bool is_valid_device(const device &DeviceCand) {
764-
// Check if the device is in this bundle's list of devices.
765-
if (std::count(MDevices.begin(), MDevices.end(), DeviceCand)) {
766-
return true;
767-
}
768-
769-
// Otherwise, if the device candidate is a sub-device it is also valid if
770-
// its parent is valid.
771-
return !getSyclObjImpl(DeviceCand)->isRootDevice() &&
772-
is_valid_device(DeviceCand.get_info<info::device::parent_device>());
773-
}
774-
775-
DeviceGlobalMapEntry *get_device_global_entry(const std::string &Name,
776-
const device &Dev) {
763+
DeviceGlobalMapEntry *get_device_global_entry(const std::string &Name) {
777764
if (MLanguage != syclex::source_language::sycl_jit || MPrefix.empty()) {
778765
throw sycl::exception(make_error_code(errc::invalid),
779766
"Querying device globals by name is only available "
780767
"in kernel_bundles successfully built from "
781-
"kernel_bundle<bundle_state:ext_oneapi_source> "
768+
"kernel_bundle<bundle_state>::ext_oneapi_source> "
782769
"with 'sycl_jit' source language.");
783770
}
784771

785-
if (!ext_oneapi_has_device_global(Name, Dev)) {
772+
if (!ext_oneapi_has_device_global(Name)) {
786773
throw sycl::exception(make_error_code(errc::invalid),
787774
"device global '" + Name +
788775
"' not found in kernel_bundle");
@@ -892,38 +879,37 @@ class kernel_bundle_impl {
892879
return AdjustedName;
893880
}
894881

895-
bool ext_oneapi_has_device_global(const std::string &Name,
896-
const device &Dev) {
897-
if (!is_valid_device(Dev)) {
898-
return false;
899-
}
900-
882+
bool ext_oneapi_has_device_global(const std::string &Name) {
901883
std::string MangledName = mangle_device_global_name(Name);
902884
return std::find(MDeviceGlobalNames.begin(), MDeviceGlobalNames.end(),
903885
MangledName) != MDeviceGlobalNames.end();
904886
}
905887

906888
void *ext_oneapi_get_device_global_address(const std::string &Name,
907889
const device &Dev) {
908-
DeviceGlobalMapEntry *Entry = get_device_global_entry(Name, Dev);
890+
if (std::find(MDevices.begin(), MDevices.end(), Dev) == MDevices.end()) {
891+
throw sycl::exception(make_error_code(errc::invalid),
892+
"kernel_bundle not built for device");
893+
}
894+
895+
DeviceGlobalMapEntry *Entry = get_device_global_entry(Name);
909896
if (Entry->MIsDeviceImageScopeDecorated) {
910897
throw sycl::exception(make_error_code(errc::invalid),
911898
"Cannot query USM pointer for device global with "
912899
"'device_image_scope' property");
913900
}
914901

915-
// TODO: Is this the right approach? Should we just pass the queue as an
916-
// argument?
902+
// TODO: Add context-only initialization via `urUSMContextMemcpyExp` instead
903+
// of using a throw-away queue.
917904
queue InitQueue{MContext, Dev};
918905
auto &USMMem =
919906
Entry->getOrAllocateDeviceGlobalUSM(getSyclObjImpl(InitQueue));
920907
InitQueue.wait_and_throw();
921908
return USMMem.getPtr();
922909
}
923910

924-
size_t ext_oneapi_get_device_global_size(const std::string &Name,
925-
const device &Dev) {
926-
return get_device_global_entry(Name, Dev)->MDeviceGlobalTSize;
911+
size_t ext_oneapi_get_device_global_size(const std::string &Name) {
912+
return get_device_global_entry(Name)->MDeviceGlobalTSize;
927913
}
928914

929915
bool empty() const noexcept { return MDeviceImages.empty(); }

sycl/source/kernel_bundle.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,19 @@ kernel_bundle_plain::ext_oneapi_get_raw_kernel_name(detail::string_view name) {
142142
return detail::string{impl->ext_oneapi_get_raw_kernel_name(name.data())};
143143
}
144144

145-
bool kernel_bundle_plain::ext_oneapi_has_device_global(detail::string_view name,
146-
const device &dev) {
147-
return impl->ext_oneapi_has_device_global(name.data(), dev);
145+
bool kernel_bundle_plain::ext_oneapi_has_device_global(
146+
detail::string_view name) {
147+
return impl->ext_oneapi_has_device_global(name.data());
148148
}
149149

150150
void *kernel_bundle_plain::ext_oneapi_get_device_global_address(
151151
detail::string_view name, const device &dev) {
152152
return impl->ext_oneapi_get_device_global_address(name.data(), dev);
153153
}
154154

155-
size_t
156-
kernel_bundle_plain::ext_oneapi_get_device_global_size(detail::string_view name,
157-
const device &dev) {
158-
return impl->ext_oneapi_get_device_global_size(name.data(), dev);
155+
size_t kernel_bundle_plain::ext_oneapi_get_device_global_size(
156+
detail::string_view name) {
157+
return impl->ext_oneapi_get_device_global_size(name.data());
159158
}
160159

161160
//////////////////////////////////

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit_device_globals.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ int test_device_global() {
6969
auto addK = kbExe1.ext_oneapi_get_kernel("ff_dg_adder");
7070

7171
// Check presence of device globals.
72-
assert(kbExe1.ext_oneapi_has_device_global("DG", d));
72+
assert(kbExe1.ext_oneapi_has_device_global("DG"));
7373
// Querying a non-existing device global shall not crash.
74-
assert(!kbExe1.ext_oneapi_has_device_global("bogus_DG", d));
74+
assert(!kbExe1.ext_oneapi_has_device_global("bogus_DG"));
7575

7676
void *dgAddr = kbExe1.ext_oneapi_get_device_global_address("DG", d);
77-
size_t dgSize = kbExe1.ext_oneapi_get_device_global_size("DG", d);
77+
size_t dgSize = kbExe1.ext_oneapi_get_device_global_size("DG");
7878
assert(dgSize == 4);
7979

8080
int32_t val;

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,10 +3278,10 @@ _ZN4sycl3_V16detail18make_kernel_bundleEmRKNS0_7contextEbNS0_12bundle_stateENS0_
32783278
_ZN4sycl3_V16detail18stringifyErrorCodeEi
32793279
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_get_kernelENS1_11string_viewE
32803280
_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_has_kernelENS1_11string_viewE
3281-
_ZN4sycl3_V16detail19kernel_bundle_plain28ext_oneapi_has_device_globalENS1_11string_viewERKNS0_6deviceE
3281+
_ZN4sycl3_V16detail19kernel_bundle_plain28ext_oneapi_has_device_globalENS1_11string_viewE
32823282
_ZN4sycl3_V16detail19kernel_bundle_plain30ext_oneapi_get_raw_kernel_nameENS1_11string_viewE
32833283
_ZN4sycl3_V16detail19kernel_bundle_plain32set_specialization_constant_implEPKcPvm
3284-
_ZN4sycl3_V16detail19kernel_bundle_plain33ext_oneapi_get_device_global_sizeENS1_11string_viewERKNS0_6deviceE
3284+
_ZN4sycl3_V16detail19kernel_bundle_plain33ext_oneapi_get_device_global_sizeENS1_11string_viewE
32853285
_ZN4sycl3_V16detail19kernel_bundle_plain36ext_oneapi_get_device_global_addressENS1_11string_viewERKNS0_6deviceE
32863286
_ZN4sycl3_V16detail20associateWithHandlerERNS0_7handlerEPNS1_16AccessorBaseHostENS0_6access6targetE
32873287
_ZN4sycl3_V16detail20associateWithHandlerERNS0_7handlerEPNS1_28SampledImageAccessorBaseHostENS0_12image_targetE

sycl/test/e2e_test_requirements/no_sycl_hpp_in_e2e_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK-DAG: README.md
77
// CHECK-DAG: lit.cfg.py
88
//
9-
// CHECK-NUM-MATCHES: 12
9+
// CHECK-NUM-MATCHES: 14
1010
//
1111
// This test verifies that `<sycl/sycl.hpp>` isn't used in E2E tests. Instead,
1212
// fine-grained includes should used, see

0 commit comments

Comments
 (0)