clover: Refuse to build a program if there are kernel objects attached to it.
authorFrancisco Jerez <currojerez@riseup.net>
Sat, 16 Aug 2014 13:25:34 +0000 (16:25 +0300)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 18 Aug 2014 06:32:24 +0000 (09:32 +0300)
Fixes piglit cl-api-build-program.

Tested-by: EdB <edb+mesa@sigluy.net>
src/gallium/state_trackers/clover/api/program.cpp
src/gallium/state_trackers/clover/core/kernel.cpp
src/gallium/state_trackers/clover/core/kernel.hpp
src/gallium/state_trackers/clover/core/program.cpp
src/gallium/state_trackers/clover/core/program.hpp

index 8d9d3ac62d5d7e56f1ade15485dafc1c3e507a89..67717353a8cca0c9f5aa2ef8abfa96fc3887a15c 100644 (file)
@@ -167,6 +167,9 @@ clBuildProgram(cl_program d_prog, cl_uint num_devs,
          }, devs))
       throw error(CL_INVALID_DEVICE);
 
+   if (prog.kernel_ref_count())
+      throw error(CL_INVALID_OPERATION);
+
    prog.build(devs, opts);
    return CL_SUCCESS;
 
index 5e5fe51f1c029da8d3da46e4d44dde8241674f5a..e4b2152e4abfacb3b45846ce18305da4a774a4df 100644 (file)
@@ -30,7 +30,8 @@ using namespace clover;
 
 kernel::kernel(clover::program &prog, const std::string &name,
                const std::vector<module::argument> &margs) :
-   program(prog), _name(name), exec(*this) {
+   program(prog), _name(name), exec(*this),
+   program_ref(prog._kernel_ref_counter) {
    for (auto &marg : margs) {
       if (marg.type == module::argument::scalar)
          _args.emplace_back(new scalar_argument(marg.size));
index e544ec64b63bb86154966d9a52e97ff966bfd2fe..f9e2765ee365ae818194e25d7c2805ff912ce798 100644 (file)
@@ -225,6 +225,7 @@ namespace clover {
       std::vector<std::unique_ptr<argument>> _args;
       std::string _name;
       exec_context exec;
+      const ref_holder program_ref;
    };
 }
 
index e09c3aaa2cfc9dea5337135cc4908fcbc51d77cf..30a1f0e0762cfc6bc6522ac386e8eb694f6d6232 100644 (file)
 using namespace clover;
 
 program::program(clover::context &ctx, const std::string &source) :
-   has_source(true), context(ctx), _source(source) {
+   has_source(true), context(ctx), _source(source), _kernel_ref_counter(0) {
 }
 
 program::program(clover::context &ctx,
                  const ref_vector<device> &devs,
                  const std::vector<module> &binaries) :
    has_source(false), context(ctx),
-   _devices(devs) {
+   _devices(devs), _kernel_ref_counter(0) {
    for_each([&](device &dev, const module &bin) {
          _binaries.insert({ &dev, bin });
       },
@@ -110,3 +110,8 @@ program::symbols() const {
 
    return _binaries.begin()->second.syms;
 }
+
+unsigned
+program::kernel_ref_count() const {
+   return _kernel_ref_counter.ref_count();
+}
index 1081454d01091e26e04c4d86ef707e14f97addfe..4bb5b680d4ede3ee8d7a1e5e5d70d06b4ffe1b20 100644 (file)
@@ -60,14 +60,19 @@ namespace clover {
 
       const compat::vector<module::symbol> &symbols() const;
 
+      unsigned kernel_ref_count() const;
+
       const intrusive_ref<clover::context> context;
 
+      friend class kernel;
+
    private:
       std::vector<intrusive_ref<device>> _devices;
       std::map<const device *, module> _binaries;
       std::map<const device *, std::string> _logs;
       std::map<const device *, std::string> _opts;
       std::string _source;
+      ref_counter _kernel_ref_counter;
    };
 }