Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions jitify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,47 @@ inline bool load_source(
comment;
}

// WAR where nvrtc can fail to correctly return if an include is present
if (cleanline.find("#if __has_include") != std::string::npos) {
Comment thread
maddyscientist marked this conversation as resolved.
Outdated
// check for angle bracket include
size_t start = cleanline.find("<") + 1;
Comment thread
maddyscientist marked this conversation as resolved.
Outdated
size_t count = cleanline.find(">") - start;
std::string has_include_name = cleanline.substr(start, count);

#if JITIFY_PRINT_HEADER_PATHS
std::cout << "Found #if __has_include(<" << has_include_name << ">)" << " from "
<< filename << ":" << linenum << std::endl;
#endif
// Try loading from filesystem
bool found_file = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but I wonder if this would be cleaner as an immediately-called lambda (bool found_file = [&] { ... }(); so that found_file = true can be replaced with return true etc.).

std::string has_include_fullpath = path_join(current_dir, has_include_name);
if (search_current_dir) {
Comment thread
maddyscientist marked this conversation as resolved.
Outdated
file_stream.open(has_include_fullpath.c_str());
if (file_stream) found_file = true;
}
// Search include directories
if (!found_file) {
for (int i = 0; i < (int)include_paths.size(); ++i) {
has_include_fullpath = path_join(include_paths[i], has_include_name);
file_stream.open(has_include_fullpath.c_str());
if (file_stream) {
found_file = true;
break;
}
}
if (!found_file) {
// Try loading from builtin headers
has_include_fullpath = path_join("__jitify_builtin", has_include_name);
auto it = get_jitsafe_headers_map().find(has_include_name);
if (it != get_jitsafe_headers_map().end()) {
found_file = true;
}
}
}

line = found_file ? "#if 1" : "#if 0";
}

source += line + "\n";
}
// HACK TESTING (WAR for cub)
Expand Down
2 changes: 0 additions & 2 deletions jitify_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,6 @@ static const char* const builtin_numeric_cuda_std_limits_program_source =
"builtin_numeric_cuda_std_limits_program\n"
"#include <climits>\n"
"#include <limits>\n"
"#include <cuda/std/climits>\n" // test fails without this explicit include
"#include <cuda/std/limits>\n"
"struct MyType {};\n"
"namespace cuda {\n"
"namespace std {\n"
Expand Down