Skip to content

Update to latest dev build and swap to COOT_KERNEL_SOURCE_DIR during package load #12

@coatless

Description

@coatless

The version of bandicoot under RcppBandicoot has a shim right now for just OpenCL. Two steps:

  1. 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)
}
}

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions