Skip to content

Commit 11df804

Browse files
committed
Address review comments. Disable tests properly.
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent bc7001d commit 11df804

File tree

11 files changed

+136
-88
lines changed

11 files changed

+136
-88
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//==----- device_binary_image.hpp --- SYCL device binary image abstraction -==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <CL/sycl/detail/os_util.hpp>
11+
#include <CL/sycl/detail/pi.hpp>
12+
13+
#include <memory>
14+
15+
__SYCL_INLINE_NAMESPACE(cl) {
16+
namespace sycl {
17+
namespace detail {
18+
19+
// SYCL RT wrapper over PI binary image.
20+
class RTDeviceBinaryImage : public pi::DeviceBinaryImage {
21+
public:
22+
RTDeviceBinaryImage(OSModuleHandle ModuleHandle)
23+
: pi::DeviceBinaryImage(), ModuleHandle(ModuleHandle) {}
24+
RTDeviceBinaryImage(pi_device_binary Bin, OSModuleHandle ModuleHandle)
25+
: pi::DeviceBinaryImage(Bin), ModuleHandle(ModuleHandle) {}
26+
OSModuleHandle getOSModuleHandle() const { return ModuleHandle; }
27+
28+
~RTDeviceBinaryImage() override {}
29+
30+
bool supportsSpecConstants() const {
31+
return getFormat() == PI_DEVICE_BINARY_TYPE_SPIRV;
32+
}
33+
34+
const pi_device_binary_struct &getRawData() const { return *get(); }
35+
36+
void print() const override {
37+
pi::DeviceBinaryImage::print();
38+
std::cerr << " OSModuleHandle=" << ModuleHandle << "\n";
39+
}
40+
41+
protected:
42+
OSModuleHandle ModuleHandle;
43+
};
44+
45+
// Dynamically allocated device binary image, which de-allocates its binary
46+
// data in destructor.
47+
class DynRTDeviceBinaryImage : public RTDeviceBinaryImage {
48+
public:
49+
DynRTDeviceBinaryImage(std::unique_ptr<char[]> &&DataPtr, size_t DataSize,
50+
OSModuleHandle M);
51+
~DynRTDeviceBinaryImage() override;
52+
53+
void print() const override {
54+
RTDeviceBinaryImage::print();
55+
std::cerr << " DYNAMICALLY CREATED\n";
56+
}
57+
58+
protected:
59+
std::unique_ptr<char[]> Data;
60+
};
61+
62+
} // namespace detail
63+
} // namespace sycl
64+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/spec_constant_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace detail {
2222
// Represents a specialization constant value in SYCL runtime.
2323
class spec_constant_impl {
2424
public:
25-
spec_constant_impl() = default;
25+
spec_constant_impl() : Size(0), Bytes{0} {};
2626

2727
spec_constant_impl(size_t Size, const void *Val) { set(Size, Val); }
2828

@@ -33,7 +33,7 @@ class spec_constant_impl {
3333
bool isSet() const { return Size != 0; }
3434

3535
private:
36-
size_t Size; // size of its value
36+
size_t Size; // the size of the spec constant value
3737
// TODO invent more flexible approach to support values of arbitrary type:
3838
unsigned char Bytes[8]; // memory to hold the value bytes
3939
};

sycl/include/CL/sycl/experimental/spec_constant.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ __SYCL_INLINE_NAMESPACE(cl) {
2424
namespace sycl {
2525
namespace experimental {
2626

27-
class spec_const_error : public compile_program_error {};
27+
class spec_const_error : public compile_program_error {
28+
using compile_program_error::compile_program_error;
29+
};
2830

2931
template <typename T, typename ID = T> class spec_constant {
3032
private:

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ set(SYCL_SOURCES
106106
"detail/common.cpp"
107107
"detail/config.cpp"
108108
"detail/context_impl.cpp"
109+
"detail/device_binary_image.cpp"
109110
"detail/device_impl.cpp"
110111
"detail/error_handling/enqueue_kernel.cpp"
111112
"detail/event_impl.cpp"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//==----- device_binary_image.cpp --- SYCL device binary image abstraction -==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <CL/sycl/detail/pi.hpp>
10+
11+
#include <memory>
12+
13+
#include <CL/sycl/detail/device_binary_image.hpp>
14+
15+
using namespace sycl::detail;
16+
17+
DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
18+
std::unique_ptr<char[]> &&DataPtr, size_t DataSize, OSModuleHandle M)
19+
: RTDeviceBinaryImage(M) {
20+
Data = std::move(DataPtr);
21+
Bin = new pi_device_binary_struct();
22+
Bin->Version = PI_DEVICE_BINARY_VERSION;
23+
Bin->Kind = PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL;
24+
Bin->DeviceTargetSpec = PI_DEVICE_BINARY_TARGET_UNKNOWN;
25+
Bin->CompileOptions = "";
26+
Bin->LinkOptions = "";
27+
Bin->ManifestStart = nullptr;
28+
Bin->ManifestEnd = nullptr;
29+
Bin->BinaryStart = reinterpret_cast<unsigned char *>(Data.get());
30+
Bin->BinaryEnd = Bin->BinaryStart + DataSize;
31+
Bin->EntriesBegin = nullptr;
32+
Bin->EntriesEnd = nullptr;
33+
Bin->Format = pi::getBinaryImageFormat(Bin->BinaryStart, DataSize);
34+
init(Bin);
35+
}
36+
37+
DynRTDeviceBinaryImage::~DynRTDeviceBinaryImage() {
38+
delete Bin;
39+
Bin = nullptr;
40+
}

sycl/source/detail/program_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void program_impl::flush_spec_constants(const RTDeviceBinaryImage &Img,
485485

486486
auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms();
487487

488-
for (SCItTy SCIt = SCRange.begin(); SCIt != SCRange.end(); SCIt++) {
488+
for (SCItTy SCIt : SCRange) {
489489
const char *SCName = (*SCIt)->Name;
490490
auto SCEntry = SpecConstRegistry.find(SCName);
491491
if (SCEntry == SpecConstRegistry.end())

sycl/source/detail/program_impl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ class program_impl {
315315
detail::stableSerializeSpecConstRegistry(SpecConstRegistry, Dst);
316316
}
317317

318+
/// Tells whether a specialization constant has been set for this program.
319+
bool hasSetSpecConstants() const { return !SpecConstRegistry.empty(); }
320+
318321
private:
319322
// Deligating Constructor used in Implementation.
320323
program_impl(ContextImplPtr Context, pi_native_handle InteropProgram,

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <CL/sycl/detail/util.hpp>
1616
#include <CL/sycl/device.hpp>
1717
#include <CL/sycl/exception.hpp>
18+
#include <CL/sycl/experimental/spec_constant.hpp>
1819
#include <CL/sycl/stl.hpp>
1920
#include <detail/context_impl.hpp>
2021
#include <detail/device_impl.hpp>
@@ -928,38 +929,15 @@ void ProgramManager::dumpImage(const RTDeviceBinaryImage &Img,
928929
F.close();
929930
}
930931

931-
DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
932-
std::unique_ptr<char[]> &&DataPtr, size_t DataSize, OSModuleHandle M)
933-
: RTDeviceBinaryImage(M) {
934-
Data = std::move(DataPtr);
935-
Bin = new pi_device_binary_struct();
936-
Bin->Version = PI_DEVICE_BINARY_VERSION;
937-
Bin->Kind = PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL;
938-
Bin->DeviceTargetSpec = PI_DEVICE_BINARY_TARGET_UNKNOWN;
939-
Bin->CompileOptions = "";
940-
Bin->LinkOptions = "";
941-
Bin->ManifestStart = nullptr;
942-
Bin->ManifestEnd = nullptr;
943-
Bin->BinaryStart = reinterpret_cast<unsigned char *>(Data.get());
944-
Bin->BinaryEnd = Bin->BinaryStart + DataSize;
945-
Bin->EntriesBegin = nullptr;
946-
Bin->EntriesEnd = nullptr;
947-
Bin->Format = pi::getBinaryImageFormat(Bin->BinaryStart, DataSize);
948-
init(Bin);
949-
}
950-
951-
DynRTDeviceBinaryImage::~DynRTDeviceBinaryImage() {
952-
delete Bin;
953-
Bin = nullptr;
954-
}
955-
956932
void ProgramManager::flushSpecConstants(const program_impl &Prg,
957933
RT::PiProgram NativePrg,
958934
const RTDeviceBinaryImage *Img) {
959935
if (DbgProgMgr > 2) {
960936
std::cerr << ">>> ProgramManager::flushSpecConstants(" << Prg.get()
961937
<< ",...)\n";
962938
}
939+
if (!Prg.hasSetSpecConstants())
940+
return; // nothing to do
963941
pi::PiProgram PrgHandle = Prg.getHandleRef();
964942
// program_impl can't correspond to two different native programs
965943
assert(!NativePrg || !PrgHandle || (NativePrg == PrgHandle));
@@ -971,20 +949,20 @@ void ProgramManager::flushSpecConstants(const program_impl &Prg,
971949
ContextImplPtr Ctx = getSyclObjImpl(Prg.get_context());
972950
auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms();
973951
auto It = NativePrograms.find(NativePrg);
974-
if (It == NativePrograms.end()) {
975-
if (DbgProgMgr > 0)
976-
std::cerr << ">>> WARNING: flushSpecConstants requested on a "
977-
"program w/o known binary image\n";
978-
return; // program origin is unknown
979-
}
952+
if (It == NativePrograms.end())
953+
throw sycl::experimental::spec_const_error(
954+
"spec constant is set in a program w/o a binary image",
955+
PI_INVALID_OPERATION);
980956
Img = It->second;
981957
}
982958
if (!Img->supportsSpecConstants()) {
983959
if (DbgProgMgr > 0)
984960
std::cerr << ">>> ProgramManager::flushSpecConstants: binary image "
985961
<< &Img->getRawData() << " doesn't support spec constants\n";
986-
// this device binary image does not support runtime setting of
987-
// specialization constants; compiler must have generated default values
962+
// This device binary image does not support runtime setting of
963+
// specialization constants; compiler must have generated default values.
964+
// NOTE: Can't throw here, as it would always take place with AOT
965+
//-compiled code. New Khronos 2020 spec should fix this inconsistency.
988966
return;
989967
}
990968
}

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/detail/device_binary_image.hpp>
1213
#include <CL/sycl/detail/export.hpp>
1314
#include <CL/sycl/detail/os_util.hpp>
1415
#include <CL/sycl/detail/pi.hpp>
@@ -51,49 +52,6 @@ enum DeviceLibExt {
5152
cl_intel_devicelib_complex_fp64
5253
};
5354

54-
// SYCL RT wrapper over PI binary image.
55-
class RTDeviceBinaryImage : public pi::DeviceBinaryImage {
56-
public:
57-
RTDeviceBinaryImage(OSModuleHandle ModuleHandle)
58-
: pi::DeviceBinaryImage(), ModuleHandle(ModuleHandle) {}
59-
RTDeviceBinaryImage(pi_device_binary Bin, OSModuleHandle ModuleHandle)
60-
: pi::DeviceBinaryImage(Bin), ModuleHandle(ModuleHandle) {}
61-
OSModuleHandle getOSModuleHandle() const { return ModuleHandle; }
62-
63-
~RTDeviceBinaryImage() override {}
64-
65-
bool supportsSpecConstants() const {
66-
return getFormat() == PI_DEVICE_BINARY_TYPE_SPIRV;
67-
}
68-
69-
const pi_device_binary_struct &getRawData() const { return *get(); }
70-
71-
void print() const override {
72-
pi::DeviceBinaryImage::print();
73-
std::cerr << " OSModuleHandle=" << ModuleHandle << "\n";
74-
}
75-
76-
protected:
77-
OSModuleHandle ModuleHandle;
78-
};
79-
80-
// Dynamically allocated device binary image, which de-allocates its binary data
81-
// in destructor.
82-
class DynRTDeviceBinaryImage : public RTDeviceBinaryImage {
83-
public:
84-
DynRTDeviceBinaryImage(std::unique_ptr<char[]> &&DataPtr, size_t DataSize,
85-
OSModuleHandle M);
86-
~DynRTDeviceBinaryImage() override;
87-
88-
void print() const override {
89-
RTDeviceBinaryImage::print();
90-
std::cerr << " DYNAMICALLY CREATED\n";
91-
}
92-
93-
protected:
94-
std::unique_ptr<char[]> Data;
95-
};
96-
9755
// Provides single loading and building OpenCL programs with unique contexts
9856
// that is necessary for no interoperability cases with lambda.
9957
class ProgramManager {

sycl/test/spec_const/spec_const_hw.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
3-
// TODO: re-enable after OpenCL RT is fixed:
4-
// RUNx: %CPU_RUN_PLACEHOLDER %t.out
5-
// RUNx: %GPU_RUN_PLACEHOLDER %t.out
6-
// RUNx: %ACC_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
// TODO: re-enable after CI drivers are updated to newer which support spec
7+
// constants:
8+
// XFAIL: acc,cpu,cuda,gen
79
//
810
//==----------- spec_const_hw.cpp ------------------------------------------==//
911
//

sycl/test/spec_const/spec_const_redefine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
3-
// TODO re-enable CPU device test once CI CPU OCL RT is updated:
4-
// RUNx: env SYCL_PI_TRACE=2 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
3+
// RUN: env SYCL_PI_TRACE=2 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
54
// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER
65
// RUN: env SYCL_PI_TRACE=2 %ACC_RUN_PLACEHOLDER %t.out 2>&1 %ACC_CHECK_PLACEHOLDER
7-
// TODO the test currently fails on these devices:
8-
// XFAIL: acc,cuda
6+
// TODO: re-enable after CI drivers are updated to newer which support spec
7+
// constants:
8+
// XFAIL: acc,cpu,cuda,gen
99
//
1010
//==----------- spec_const_redefine.cpp ------------------------------------==//
1111
//

0 commit comments

Comments
 (0)