Skip to content

Fix segfault with incompatible OpenCL #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ static cl_program createBinaryProgram(const cl_context Context,
return Program;
}

cl_program createSpirvProgram(const cl_context Context,
const vector_class<char> &SpirvProg) {
static cl_program createSpirvProgram(const cl_context Context,
const vector_class<char> &SpirvProg) {
cl_int Err = CL_SUCCESS;
cl_program ClProgram = clCreateProgramWithIL(Context, SpirvProg.data(),
SpirvProg.size(), &Err);
CHECK_OCL_CODE(Err);
return ClProgram;
}

static cl_program createProgram(cl_context Context,
static cl_program createProgram(const platform &Platform,
cl_context Context,
const vector_class<char> &DeviceProg) {
cl_program Program = nullptr;
int32_t SpirvMagic = 0;
Expand All @@ -93,7 +94,13 @@ static cl_program createProgram(cl_context Context,
(char*)&SpirvMagic);

if (SpirvMagic == ValidSpirvMagic) {
Program = createSpirvProgram(Context, DeviceProg);
if (Platform.has_extension("cl_khr_il_program") ||
Platform.get_info<info::platform::version>().find(" 2.1") !=
string_class::npos) {
Program = createSpirvProgram(Context, DeviceProg);
} else {
return nullptr;
}
}
}

Expand All @@ -111,7 +118,8 @@ cl_program ProgramManager::getBuiltOpenCLProgram(const context &Context) {
vector_class<char> DeviceProg = getSpirvSource();

cl_context ClContext = Context.get();
ClProgram = createProgram(ClContext, DeviceProg);
const platform &Platform = Context.get_platform();
ClProgram = createProgram(Platform, ClContext, DeviceProg);
clReleaseContext(ClContext);

build(ClProgram);
Expand Down