|
10 | 10 | #include <CL/sycl/detail/common.hpp>
|
11 | 11 | #include <CL/sycl/detail/os_util.hpp>
|
12 | 12 | #include <CL/sycl/detail/program_manager/program_manager.hpp>
|
| 13 | +#include <CL/sycl/detail/type_traits.hpp> |
13 | 14 | #include <CL/sycl/detail/util.hpp>
|
14 | 15 | #include <CL/sycl/device.hpp>
|
15 | 16 | #include <CL/sycl/exception.hpp>
|
16 | 17 | #include <CL/sycl/stl.hpp>
|
17 | 18 |
|
18 |
| -#include <assert.h> |
| 19 | +#include <cassert> |
19 | 20 | #include <cstdlib>
|
20 | 21 | #include <fstream>
|
21 | 22 | #include <memory>
|
@@ -87,12 +88,19 @@ RT::PiProgram ProgramManager::getBuiltOpenCLProgram(OSModuleHandle M,
|
87 | 88 | std::shared_ptr<context_impl> Ctx = getSyclObjImpl(Context);
|
88 | 89 | std::map<OSModuleHandle, RT::PiProgram> &CachedPrograms =
|
89 | 90 | Ctx->getCachedPrograms();
|
90 |
| - RT::PiProgram &Program = CachedPrograms[M]; |
91 |
| - if (!Program) { |
92 |
| - DeviceImage *Img = nullptr; |
93 |
| - Program = loadProgram(M, Context, &Img); |
94 |
| - build(Program, Img->BuildOptions); |
95 |
| - } |
| 91 | + auto It = CachedPrograms.find(M); |
| 92 | + if (It != CachedPrograms.end()) |
| 93 | + return It->second; |
| 94 | + |
| 95 | + DeviceImage *Img = nullptr; |
| 96 | + using PiProgramT = remove_pointer_t<RT::PiProgram>; |
| 97 | + unique_ptr_class<PiProgramT, decltype(RT::piProgramRelease)> ProgramManaged( |
| 98 | + loadProgram(M, Context, &Img), RT::piProgramRelease); |
| 99 | + |
| 100 | + build(ProgramManaged.get(), Img->BuildOptions); |
| 101 | + RT::PiProgram Program = ProgramManaged.release(); |
| 102 | + CachedPrograms[M] = Program; |
| 103 | + |
96 | 104 | return Program;
|
97 | 105 | }
|
98 | 106 |
|
@@ -150,7 +158,7 @@ string_class ProgramManager::getProgramBuildLog(const RT::PiProgram &Program) {
|
150 | 158 | return Log;
|
151 | 159 | }
|
152 | 160 |
|
153 |
| -void ProgramManager::build(RT::PiProgram &Program, const string_class &Options, |
| 161 | +void ProgramManager::build(RT::PiProgram Program, const string_class &Options, |
154 | 162 | std::vector<RT::PiDevice> Devices) {
|
155 | 163 |
|
156 | 164 | if (DbgProgMgr > 0) {
|
|
0 commit comments