diff options
author | Pradeep Garigipati <pradeep.garigipati@gmail.com> | 2020-06-05 12:00:45 +0530 |
---|---|---|
committer | Pradeep Garigipati <pradeep.garigipati@gmail.com> | 2020-06-05 12:00:45 +0530 |
commit | aec71699f8278df31b16fa544138f3bd60940c8c (patch) | |
tree | 2a3c1c095b4a6d5dc00afa5ebe278f519c564ea2 /src/clpp11.hpp | |
parent | da0e657d392cdcba6313f4f708cf064566f173a0 (diff) |
Fix Program::GetIR to handle programs with multiple devices
Diffstat (limited to 'src/clpp11.hpp')
-rw-r--r-- | src/clpp11.hpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp index 4ed157ea..7465fd94 100644 --- a/src/clpp11.hpp +++ b/src/clpp11.hpp @@ -509,12 +509,31 @@ class Program { // Retrieves a binary or an intermediate representation of the compiled program std::string GetIR() const { - auto bytes = size_t{0}; - CheckError(clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &bytes, nullptr)); + cl_uint num_devices = 0; + CheckError(clGetProgramInfo(program_, CL_PROGRAM_NUM_DEVICES, + sizeof(cl_uint), &num_devices, nullptr)); + + std::vector<size_t> binSizesInBytes(num_devices, 0); + CheckError(clGetProgramInfo(program_, CL_PROGRAM_BINARY_SIZES, + num_devices * sizeof(size_t), binSizesInBytes.data(), nullptr)); + + auto bytes = size_t{0}; + auto binSizeIter = size_t{0}; + for (; binSizeIter < binSizesInBytes.size(); ++binSizeIter) { + if (binSizesInBytes[binSizeIter] > 0) { + bytes = binSizesInBytes[binSizeIter]; + break; + } + } auto result = std::string{}; result.resize(bytes); - auto result_ptr = result.data(); - CheckError(clGetProgramInfo(program_, CL_PROGRAM_BINARIES, sizeof(char*), &result_ptr, nullptr)); + + std::vector<char*> out(num_devices, nullptr); + out[binSizeIter] = const_cast<char*>(result.data()); + + CheckError(clGetProgramInfo(program_, CL_PROGRAM_BINARIES, + num_devices * sizeof(char*), + out.data(), nullptr)); return result; } |