Skip to content

Commit 2b26dcb

Browse files
kbobrovsvladimirlaz
authored andcommitted
[SYCL] Restore SYCL_USE_KERNEL_SPV env var handling to load SPIRV program from a file.
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com> Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent 60ee031 commit 2b26dcb

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ cnri_program ProgramManager::loadProgram(OSModuleHandle M,
252252
Img->Kind = SYCL_OFFLOAD_KIND;
253253
Img->Format = CNRI_IMG_NONE;
254254
Img->DeviceTargetSpec = CNRI_TGT_STR_UNKNOWN;
255-
Img->BuildOptions = nullptr;
255+
Img->BuildOptions = "";
256256
Img->ManifestStart = nullptr;
257257
Img->ManifestEnd = nullptr;
258258
Img->ImageStart = Data;
@@ -291,13 +291,13 @@ cnri_program ProgramManager::loadProgram(OSModuleHandle M,
291291
assert(Img->ImageEnd >= Img->ImageStart);
292292
size_t ImgSize = static_cast<size_t>(Img->ImageEnd - Img->ImageStart);
293293

294-
// Determine the kind of the image if not set already
295-
if (Img->Kind == CNRI_IMG_NONE) {
294+
// Determine the format of the image if not set already
295+
if (Img->Format == CNRI_IMG_NONE) {
296296
struct {
297297
cnri_device_image_format Fmt;
298-
const int32_t Magic;
298+
const uint32_t Magic;
299299
} Fmts[] = {{CNRI_IMG_SPIRV, 0x07230203},
300-
{CNRI_IMG_LLVMIR_BITCODE, 0x4243C0DE}};
300+
{CNRI_IMG_LLVMIR_BITCODE, 0xDEC04342}};
301301
if (ImgSize >= sizeof(Fmts[0].Magic)) {
302302
std::remove_const<decltype(Fmts[0].Magic)>::type Hdr = 0;
303303
std::copy(Img->ImageStart, Img->ImageStart + sizeof(Hdr),
@@ -308,7 +308,8 @@ cnri_program ProgramManager::loadProgram(OSModuleHandle M,
308308
Img->Format = Fmt.Fmt;
309309

310310
if (DbgProgMgr > 1) {
311-
std::cerr << "determined image format: " << Img->Format;
311+
std::cerr << "determined image format: " << (int)Img->Format
312+
<< "\n";
312313
}
313314
break;
314315
}
@@ -321,9 +322,9 @@ cnri_program ProgramManager::loadProgram(OSModuleHandle M,
321322
Fname += Img->DeviceTargetSpec;
322323
std::string Ext;
323324

324-
if (Img->Kind == CNRI_IMG_SPIRV) {
325+
if (Img->Format == CNRI_IMG_SPIRV) {
325326
Ext = ".spv";
326-
} else if (Img->Kind == CNRI_IMG_LLVMIR_BITCODE) {
327+
} else if (Img->Format == CNRI_IMG_LLVMIR_BITCODE) {
327328
Ext = ".bc";
328329
} else {
329330
Ext = ".bin";

sycl/test/kernel_from_file/hw.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %clang -std=c++11 --sycl -fno-sycl-use-bitcode -Xclang -fsycl-int-header=%t.h -c %s -o %t.spv
2+
// RUN: %clang -std=c++11 -include %t.h -g %s -o %t.out -lOpenCL -lsycl -lstdc++
3+
// RUN: env SYCL_USE_KERNEL_SPV=%t.spv %t.out | FileCheck %s
4+
// CHECK: Passed
5+
6+
7+
#include <CL/sycl.hpp>
8+
#include <iostream>
9+
10+
using namespace cl::sycl;
11+
12+
int main(int argc, char **argv) {
13+
int data = 5;
14+
15+
try {
16+
queue myQueue;
17+
buffer<int, 1> buf(&data, range<1>(1));
18+
19+
event e = myQueue.submit([&](handler& cgh) {
20+
auto ptr = buf.get_access<access::mode::read_write>(cgh);
21+
22+
cgh.single_task<class my_kernel>([=]() {
23+
ptr[0]++;
24+
});
25+
});
26+
e.wait_and_throw();
27+
28+
} catch (cl::sycl::exception const& e) {
29+
std::cerr << "SYCL exception caught:\n";
30+
std::cerr << e.what() << "\n";
31+
return 2;
32+
}
33+
catch (...) {
34+
std::cerr << "unknown exception caught\n";
35+
return 1;
36+
}
37+
38+
if (data == 6) {
39+
std::cout << "Passed\n";
40+
return 0;
41+
} else {
42+
std::cout << "Failed: " << data << "!= 6(gold)\n";
43+
return 1;
44+
}
45+
}
46+

0 commit comments

Comments
 (0)