Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify RTC include paths #801

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Several environmental variables are used or required by FLAME GPU 2.
+ Alternatively `CUDA_HOME` may be used if `CUDA_PATH` was not set.
+ `FLAMEGPU_INC_DIR` - When RTC compilation is required, if the location of the `include` directory cannot be found it must be specified using the `FLAMEGPU_INC_DIR` environment variable.
+ `FLAMEGPU_TMP_DIR` - FLAME GPU may cache some files to a temporary directory on the system, using the temporary directory returned by [`std::filesystem::temp_directory_path`](https://en.cppreference.com/w/cpp/filesystem/temp_directory_path). The location can optionally be overridden using the `FLAMEGPU_TMP_DIR` environment variable.
+ `FLAMEGPU_RTC_INCLUDE_DIRS` - A list of include directories that should be provided to the RTC compiler, these should be separated using `;` (Windows) or `:` (Linux). If this variable is not found, the working directory will be used as a default.

## Running the Test Suite(s)

Expand Down
35 changes: 35 additions & 0 deletions src/flamegpu/util/detail/JitifyCache.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <filesystem>
using std::tr2::sys::temp_directory_path;
using std::tr2::sys::exists;
using std::tr2::sys::current_path;
using std::tr2::sys::path;
using std::tr2::sys::directory_iterator;
#else
Expand All @@ -22,6 +23,7 @@ using std::tr2::sys::directory_iterator;
#include <experimental/filesystem>
using std::experimental::filesystem::v1::temp_directory_path;
using std::experimental::filesystem::v1::exists;
using std::experimental::filesystem::v1::current_path;
using std::experimental::filesystem::v1::path;
using std::experimental::filesystem::v1::directory_iterator;
#endif
Expand Down Expand Up @@ -66,6 +68,35 @@ path getTMP() {
}
return result;
}
/**
* Returns the user-defined include directories
*/
std::vector<path> getIncludeDirs() {
static std::vector<path> rtn;
if (rtn.empty()) {
if (std::getenv("FLAMEGPU_RTC_INCLUDE_DIRS")) {
const std::string s = std::getenv("FLAMEGPU_RTC_INCLUDE_DIRS");
// Split the string by ; (windows), : (linux)
#if defined(_MSC_VER)
std::string delimiter = ";";
#else
std::string delimiter = ":";
#endif
size_t start = 0, end = s.find(delimiter);
std::string token;
do {
path p = s.substr(start, end - start);
if (!p.empty()) {
rtn.push_back(p);
}
start = end + delimiter.length();
} while ((end = s.find(delimiter, start))!= std::string::npos);
} else {
rtn.push_back(current_path());
}
}
return rtn;
}
std::string loadFile(const path &filepath) {
std::ifstream ifs;
ifs.open(filepath, std::ifstream::binary);
Expand Down Expand Up @@ -272,6 +303,10 @@ std::unique_ptr<KernelInstantiation> JitifyCache::compileKernel(const std::strin
// cuda include directory (via CUDA_PATH)
options.push_back(std::string("-I" + cuda_include_dir));

// Add user specified include paths
for (const auto &p : getIncludeDirs())
options.push_back(std::string("-I" + p.generic_string()));

#ifdef USE_GLM
// GLM headers increase build time ~5x, so only enable glm if user is using it
if (kernel_src.find("glm") != std::string::npos) {
Expand Down