"Dorrington, Albert" <[email protected]> writes: > Hi Tom and Francisco, > > When I tried to use Clang from the command line to produce binaries, all I > could get was the LLVM IR code, so I adapted my test program to produce a > binary using clGetProgramInfo(). > (I have been following code examples in book 'OpenCL Programming Guide') > > I have been stepping through the existing code in this area, using GDB, for > the past few days, trying to get the binary to load successfully, and I have > also stepped through the code behind clCreateProgramWithSource() - so I have > started getting familiar with the process that is going on. > > I thought, if I generated the binary using clGetProgramInfo() after > clBuildProgram() that the binary would be in the same format as would be > needed. > > So far, I have run into two main issues. > The first is, if there is only one kernel in the binary, it seems that > clCreateProgramWithBinary() thinks there are two, due to (I think) an issue > with the range() processing. > In the debugger I see a second pair of binary/length fields in the result > map, and when the 'return new program()' call is made at the end of > clCreateProgramWithBinary() I get a SegFault after the first (only) binary is > deserialized. > > So, I added a second kernel function to the CL program, and I am able to get > through clCreateProgramWithBinary() without crashing, but quickly ran into a > second issue. > > My code currently calls in the order: > clCreateProgramWithBinary(); > clBuildProgram(); > clCreateKernel(); > > The clCreateKernel() call fails with a -46/Invalid Kernel Name; stepping > through the debugger, I believe I can see the two loaded kernels, however I > cannot find the names in what was loaded. > > For now, I don't need Clang/LLVM to produce the binary without Mesa/Clover, I > am fine with Mesa/Clover producing the binary. >
Hi Albert, can you give the attached patch a try? It fixes a couple of issues I've found in the clCreateProgramWithBinary path. Let me know if it helps. Thanks. > Tom, from what you wrote below, it sounds like the clBuildProgram() > implementation may only be expecting IR code and not a binary input? > > Since getting this to function is related to my current assignment at work, I > do have a lot of time I can spend on this task. > > Thanks! > -Al >
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index 7d060c4..6049209 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -69,7 +69,7 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
throw error(CL_INVALID_DEVICE);
// Deserialize the provided binaries,
- auto result = map(
+ std::vector<std::pair<cl_int, module>> result = map(
[](const unsigned char *p, size_t l) -> std::pair<cl_int, module> {
if (!p || !l)
return { CL_INVALID_VALUE, {} };
diff --git a/src/gallium/state_trackers/clover/core/module.cpp b/src/gallium/state_trackers/clover/core/module.cpp
index 040f521..3e3ad99 100644
--- a/src/gallium/state_trackers/clover/core/module.cpp
+++ b/src/gallium/state_trackers/clover/core/module.cpp
@@ -108,6 +108,9 @@ namespace {
proc(S &s, QT &x) {
_proc(s, x.type);
_proc(s, x.size);
+ _proc(s, x.target_size);
+ _proc(s, x.target_align);
+ _proc(s, x.ext_type);
}
};
diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index 6d4a9ba..fb7e8d1 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -26,13 +26,13 @@
using namespace clover;
program::program(context &ctx, const std::string &source) :
- ctx(ctx), _source(source) {
+ has_source(true), ctx(ctx), _source(source) {
}
program::program(context &ctx,
const ref_vector<device> &devs,
const std::vector<module> &binaries) :
- ctx(ctx) {
+ has_source(false), ctx(ctx) {
for_each([&](device &dev, const module &bin) {
_binaries.insert({ &dev, bin });
},
@@ -41,23 +41,25 @@ program::program(context &ctx,
void
program::build(const ref_vector<device> &devs, const char *opts) {
- for (auto &dev : devs) {
- _binaries.erase(&dev);
- _logs.erase(&dev);
- _opts.erase(&dev);
-
- _opts.insert({ &dev, opts });
-
- try {
- auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
- compile_program_tgsi(_source) :
- compile_program_llvm(_source, dev.ir_format(),
- dev.ir_target(), build_opts(dev)));
- _binaries.insert({ &dev, module });
-
- } catch (build_error &e) {
- _logs.insert({ &dev, e.what() });
- throw;
+ if (has_source) {
+ for (auto &dev : devs) {
+ _binaries.erase(&dev);
+ _logs.erase(&dev);
+ _opts.erase(&dev);
+
+ _opts.insert({ &dev, opts });
+
+ try {
+ auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
+ compile_program_tgsi(_source) :
+ compile_program_llvm(_source, dev.ir_format(),
+ dev.ir_target(), build_opts(dev)));
+ _binaries.insert({ &dev, module });
+
+ } catch (build_error &e) {
+ _logs.insert({ &dev, e.what() });
+ throw;
+ }
}
}
}
diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp
index 25ec239..d36982c 100644
--- a/src/gallium/state_trackers/clover/core/program.hpp
+++ b/src/gallium/state_trackers/clover/core/program.hpp
@@ -49,6 +49,7 @@ namespace clover {
void build(const ref_vector<device> &devs, const char *opts);
+ const bool has_source;
const std::string &source() const;
device_range devices() const;
diff --git a/src/gallium/state_trackers/clover/util/functional.hpp b/src/gallium/state_trackers/clover/util/functional.hpp
index 8e0b483a..2d8c4c4 100644
--- a/src/gallium/state_trackers/clover/util/functional.hpp
+++ b/src/gallium/state_trackers/clover/util/functional.hpp
@@ -289,17 +289,17 @@ namespace clover {
struct keys {
template<typename P>
- typename std::remove_reference<P>::type::first_type &
- operator()(P &&p) const {
- return p.first;
+ auto
+ operator()(P &&p) const -> decltype(std::get<0>(std::forward<P>(p))) {
+ return std::get<0>(std::forward<P>(p));
}
};
struct values {
template<typename P>
- typename std::remove_reference<P>::type::second_type &
- operator()(P &&p) const {
- return p.second;
+ auto
+ operator()(P &&p) const -> decltype(std::get<1>(std::forward<P>(p))) {
+ return std::get<1>(std::forward<P>(p));
}
};
pgphgVDCD90sX.pgp
Description: PGP signature
_______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
