The version of bandicoot under RcppBandicoot has a shim right now for just OpenCL. Two steps:
- Register environment variable after package load:
|
.onLoad <- function(libname, pkgname) { |
|
# Set the kernel path for Bandicoot OpenCL kernels |
|
kernel_path <- system.file("include/bandicoot_bits/opencl/kernels", |
|
package = "RcppBandicoot") |
|
|
|
if (nzchar(kernel_path)) { |
|
Sys.setenv(COOT_CL_KERNEL_PATH = kernel_path) |
|
} |
|
} |
- Place a check:
|
inline |
|
std::string |
|
read_file(const std::string& filename) |
|
{ |
|
std::string full_filename; |
|
|
|
// Check if COOT_CL_KERNEL_PATH environment variable is set |
|
const char* kernel_path_env = std::getenv("COOT_CL_KERNEL_PATH"); |
|
|
|
if (kernel_path_env != nullptr) |
|
{ |
|
std::string kernel_path_str(kernel_path_env); |
|
if (!kernel_path_str.empty()) |
|
{ |
|
// Use the path from the environment variable |
|
full_filename = kernel_path_str + "/" + filename; |
|
} |
|
else |
|
{ |
|
// Fall back to the original behavior using __FILE__ |
|
const std::string this_file = __FILE__; |
|
// We need to strip the '_src.hpp' from __FILE__. |
|
full_filename = this_file.substr(0, this_file.size() - 8) + "s/" + filename; |
|
} |
|
} |
|
else |
|
{ |
|
// Fall back to the original behavior using __FILE__ |
|
const std::string this_file = __FILE__; |
|
// We need to strip the '_src.hpp' from __FILE__. |
|
full_filename = this_file.substr(0, this_file.size() - 8) + "s/" + filename; |
|
} |
|
|
|
std::ifstream f(full_filename); |
|
std::string file_contents = ""; |
|
if (!f.is_open()) |
|
{ |
|
COOT_CERR_STREAM << "Failed to open " << full_filename << " (kernel source)!\n"; |
|
throw std::runtime_error("Cannot open required kernel source."); |
|
} |
|
|
|
// Allocate memory for file contents. |
|
f.seekg(0, std::ios::end); |
|
file_contents.reserve(f.tellg()); |
|
f.seekg(0, std::ios::beg); |
|
|
|
file_contents.assign(std::istreambuf_iterator<char>(f), |
|
std::istreambuf_iterator<char>()); |
|
|
|
return file_contents; |
|
} |
This should be address for CUDA by merging in the upstream change by Ryan in response to this feedback.
We'll need to switch over to using COOT_KERNEL_SOURCE_DIR instead of what we currently define adhoc COOT_CL_KERNEL_PATH
The version of bandicoot under RcppBandicoot has a shim right now for just OpenCL. Two steps:
rcppbandicoot/R/rcppbandicoot-package.R
Lines 10 to 18 in 8be42b7
rcppbandicoot/inst/include/bandicoot_bits/opencl/kernel_src.hpp
Lines 51 to 101 in 8be42b7
This should be address for CUDA by merging in the upstream change by Ryan in response to this feedback.
We'll need to switch over to using
COOT_KERNEL_SOURCE_DIRinstead of what we currently define adhocCOOT_CL_KERNEL_PATH