Skip to content

Commit f0f9120

Browse files
alexeyvoronov-intelbader
authored andcommitted
[SYCL] Make the build and compile exceptions messages more descriptive.
Added a build information to exceptions which can be thrown from compile[build]_with_source[kernel_type] methods of program class. Signed-off-by: Alexey Voronov <[email protected]>
1 parent da9b217 commit f0f9120

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ typedef enum {
8181
PI_DEVICE_INFO_TYPE = CL_DEVICE_TYPE,
8282
PI_DEVICE_INFO_PARENT = CL_DEVICE_PARENT_DEVICE,
8383
PI_DEVICE_INFO_PLATFORM = CL_DEVICE_PLATFORM,
84-
PI_DEVICE_INFO_PARTITION_TYPE = CL_DEVICE_PARTITION_TYPE
84+
PI_DEVICE_INFO_PARTITION_TYPE = CL_DEVICE_PARTITION_TYPE,
85+
PI_DEVICE_INFO_NAME = CL_DEVICE_NAME
8586
} _pi_device_info;
8687

8788
// TODO: populate

sycl/include/CL/sycl/detail/program_impl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ class program_impl {
361361
0, nullptr, nullptr, nullptr, nullptr));
362362

363363
if (Err != PI_SUCCESS) {
364-
// TODO make the exception message more descriptive
365-
throw compile_program_error("Program compilation error");
364+
throw compile_program_error("Program compilation error:\n" +
365+
ProgramManager::getProgramBuildLog(Program));
366366
}
367367
CompileOptions = Options;
368368
BuildOptions = Options;
@@ -377,8 +377,8 @@ class program_impl {
377377
nullptr, nullptr));
378378

379379
if (Err != PI_SUCCESS) {
380-
// TODO make the exception message more descriptive
381-
throw compile_program_error("Program build error");
380+
throw compile_program_error("Program build error:\n" +
381+
ProgramManager::getProgramBuildLog(Program));
382382
}
383383
BuildOptions = Options;
384384
}

sycl/include/CL/sycl/detail/program_manager/program_manager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ProgramManager {
6060
void addImages(pi_device_binaries DeviceImages);
6161
void debugDumpBinaryImages() const;
6262
void debugDumpBinaryImage(const DeviceImage *Img) const;
63+
static string_class getProgramBuildLog(const RT::PiProgram &Program);
6364

6465
private:
6566
RT::PiProgram loadProgram(OSModuleHandle M, const context &Context,

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ RT::PiProgram ProgramManager::getClProgramFromClKernel(RT::PiKernel Kernel) {
124124
return Program;
125125
}
126126

127+
string_class ProgramManager::getProgramBuildLog(const RT::PiProgram &Program) {
128+
size_t Size = 0;
129+
PI_CALL(RT::piProgramGetInfo(Program, CL_PROGRAM_DEVICES, 0, nullptr, &Size));
130+
vector_class<RT::PiDevice> PIDevices(Size / sizeof(RT::PiDevice));
131+
PI_CALL(RT::piProgramGetInfo(Program, CL_PROGRAM_DEVICES, Size,
132+
PIDevices.data(), nullptr));
133+
string_class Log = "The program was built for " +
134+
std::to_string(PIDevices.size()) + " devices";
135+
for (RT::PiDevice &Device : PIDevices) {
136+
PI_CALL(RT::piProgramGetBuildInfo(Program, Device, CL_PROGRAM_BUILD_LOG, 0,
137+
nullptr, &Size));
138+
vector_class<char> DeviceBuildInfo(Size);
139+
PI_CALL(RT::piProgramGetBuildInfo(Program, Device, CL_PROGRAM_BUILD_LOG,
140+
Size, DeviceBuildInfo.data(), nullptr));
141+
PI_CALL(
142+
RT::piDeviceGetInfo(Device, PI_DEVICE_INFO_NAME, 0, nullptr, &Size));
143+
vector_class<char> DeviceName(Size);
144+
PI_CALL(RT::piDeviceGetInfo(Device, PI_DEVICE_INFO_NAME, Size,
145+
DeviceName.data(), nullptr));
146+
147+
Log += "\nBuild program log for '" + string_class(DeviceName.data()) +
148+
"':\n" + string_class(DeviceBuildInfo.data());
149+
}
150+
return Log;
151+
}
152+
127153
void ProgramManager::build(RT::PiProgram &Program, const string_class &Options,
128154
std::vector<RT::PiDevice> Devices) {
129155

@@ -148,29 +174,7 @@ void ProgramManager::build(RT::PiProgram &Program, const string_class &Options,
148174
Opts, nullptr, nullptr)) == PI_SUCCESS)
149175
return;
150176

151-
// Get OpenCL build log and add it to the exception message.
152-
size_t Size = 0;
153-
PI_CALL(RT::piProgramGetInfo(
154-
Program, CL_PROGRAM_DEVICES, 0, nullptr, &Size));
155-
156-
std::vector<RT::PiDevice> DevIds(Size / sizeof(RT::PiDevice));
157-
PI_CALL(RT::piProgramGetInfo(
158-
Program, CL_PROGRAM_DEVICES, Size, DevIds.data(), nullptr));
159-
std::string Log;
160-
for (RT::PiDevice &DevId : DevIds) {
161-
PI_CALL(RT::piProgramGetBuildInfo(
162-
Program, DevId, CL_PROGRAM_BUILD_LOG, 0, nullptr, &Size));
163-
std::vector<char> BuildLog(Size);
164-
PI_CALL(RT::piProgramGetBuildInfo(
165-
Program, DevId, CL_PROGRAM_BUILD_LOG, Size,
166-
BuildLog.data(), nullptr));
167-
168-
device Dev = createSyclObjFromImpl<device>(
169-
std::make_shared<device_impl_pi>(DevId));
170-
Log += "\nBuild program fail log for '" +
171-
Dev.get_info<info::device::name>() + "':\n" + BuildLog.data();
172-
}
173-
throw compile_program_error(Log.c_str());
177+
throw compile_program_error(getProgramBuildLog(Program));
174178
}
175179

176180
void ProgramManager::addImages(pi_device_binaries DeviceBinary) {

0 commit comments

Comments
 (0)