Skip to content

Commit

Permalink
Merge pull request #1298 from bstatcomp/bug-fix/opencl-options-string…
Browse files Browse the repository at this point in the history
…-key

Fixes #1297 make key of map for opencl kernel options into a string
  • Loading branch information
rok-cesnovar committed Aug 5, 2019
2 parents fc20a23 + fc782a5 commit 806e6d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions stan/math/opencl/kernel_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ inline const std::vector<cl::Event> select_events(
*/
inline auto compile_kernel(const char* name,
const std::vector<const char*>& sources,
std::map<const char*, int>& options) {
std::map<std::string, int>& options) {
std::string kernel_opts = "";
for (auto&& comp_opts : options) {
kernel_opts += std::string(" -D") + comp_opts.first + "="
+ std::to_string(comp_opts.second);
}
std::string kernel_source;
for (const char* source : sources) {
for (auto&& source : sources) {
kernel_source.append(source);
}
cl::Program program;
Expand Down Expand Up @@ -254,7 +254,7 @@ template <typename... Args>
class kernel_functor {
private:
cl::Kernel kernel_;
std::map<const char*, int> opts_;
std::map<std::string, int> opts_;

public:
/**
Expand All @@ -264,7 +264,7 @@ class kernel_functor {
* @param options The values of macros to be passed at compile time.
*/
kernel_functor(const char* name, const std::vector<const char*>& sources,
const std::map<const char*, int>& options) {
const std::map<std::string, int>& options) {
auto base_opts = opencl_context.base_opts();
for (auto& it : options) {
if (base_opts[it.first] > it.second) {
Expand All @@ -280,7 +280,7 @@ class kernel_functor {
/**
* @return The options that the kernel was compiled with.
*/
inline const std::map<const char*, int>& get_opts() const { return opts_; }
inline const std::map<std::string, int>& get_opts() const { return opts_; }
};

/**
Expand All @@ -299,7 +299,7 @@ struct kernel_cl {
* @param options The values of macros to be passed at compile time.
*/
kernel_cl(const char* name, const char* source,
const std::map<const char*, int>& options = {})
const std::map<std::string, int>& options = {})
: make_functor(name, {source}, options) {}
/**
* Creates functor for kernels that only need access to defining
Expand All @@ -309,7 +309,7 @@ struct kernel_cl {
* @param options The values of macros to be passed at compile time.
*/
kernel_cl(const char* name, const std::vector<const char*>& sources,
const std::map<const char*, int>& options = {})
const std::map<std::string, int>& options = {})
: make_functor(name, sources, options) {}
/**
* Executes a kernel
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/opencl_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class opencl_context_base {
// the device

// Holds Default parameter values for each Kernel.
typedef std::map<const char*, int> map_base_opts;
typedef std::map<std::string, int> map_base_opts;
map_base_opts base_opts_
= {{"LOWER", static_cast<int>(matrix_cl_view::Lower)},
{"UPPER", static_cast<int>(matrix_cl_view::Upper)},
Expand Down

0 comments on commit 806e6d6

Please sign in to comment.