From e9a4e74926ab67d1750c39b49a54df6fbcb0b593 Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Sat, 16 Aug 2014 16:25:34 +0300 Subject: [PATCH] clover: Refuse to build a program if there are kernel objects attached to it. Fixes piglit cl-api-build-program. Tested-by: EdB --- src/gallium/state_trackers/clover/api/program.cpp | 3 +++ src/gallium/state_trackers/clover/core/kernel.cpp | 3 ++- src/gallium/state_trackers/clover/core/kernel.hpp | 1 + src/gallium/state_trackers/clover/core/program.cpp | 9 +++++++-- src/gallium/state_trackers/clover/core/program.hpp | 5 +++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index 8d9d3ac62d5..67717353a8c 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -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; diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp index 5e5fe51f1c0..e4b2152e4ab 100644 --- a/src/gallium/state_trackers/clover/core/kernel.cpp +++ b/src/gallium/state_trackers/clover/core/kernel.cpp @@ -30,7 +30,8 @@ using namespace clover; kernel::kernel(clover::program &prog, const std::string &name, const std::vector &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)); diff --git a/src/gallium/state_trackers/clover/core/kernel.hpp b/src/gallium/state_trackers/clover/core/kernel.hpp index e544ec64b63..f9e2765ee36 100644 --- a/src/gallium/state_trackers/clover/core/kernel.hpp +++ b/src/gallium/state_trackers/clover/core/kernel.hpp @@ -225,6 +225,7 @@ namespace clover { std::vector> _args; std::string _name; exec_context exec; + const ref_holder program_ref; }; } diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp index e09c3aaa2cf..30a1f0e0762 100644 --- a/src/gallium/state_trackers/clover/core/program.cpp +++ b/src/gallium/state_trackers/clover/core/program.cpp @@ -26,14 +26,14 @@ 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 &devs, const std::vector &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(); +} diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp index 1081454d010..4bb5b680d4e 100644 --- a/src/gallium/state_trackers/clover/core/program.hpp +++ b/src/gallium/state_trackers/clover/core/program.hpp @@ -60,14 +60,19 @@ namespace clover { const compat::vector &symbols() const; + unsigned kernel_ref_count() const; + const intrusive_ref context; + friend class kernel; + private: std::vector> _devices; std::map _binaries; std::map _logs; std::map _opts; std::string _source; + ref_counter _kernel_ref_counter; }; } -- 2.30.2