MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / get_cuda_include_path

Method get_cuda_include_path

src/core/impl/utils/cuda_helper.cpp:118–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116} // namespace
117
118std::vector<std::string> mgb::get_cuda_include_path() {
119 std::vector<std::string> paths;
120 // 1. use CUDA_BIN_PATH
121 auto cuda_path = getenv("CUDA_BIN_PATH");
122 if (cuda_path) {
123 paths.emplace_back(std::string(cuda_path) + PATH_SPLITER + "include");
124 paths.emplace_back(
125 std::string(cuda_path) + PATH_SPLITER + ".." + PATH_SPLITER +
126 "include");
127 }
128
129 // 2. use nvcc path
130 auto nvcc_path = get_nvcc_root_path();
131 if (!nvcc_path.empty()) {
132 auto cudart_header_path = nvcc_path + ".." + PATH_SPLITER + "include" +
133 PATH_SPLITER + "cuda_runtime.h";
134 //! double check path_to_nvcc/../include/cuda_runtime.h exists
135 auto ret = check_file_exist(cudart_header_path.c_str(), F_OK);
136 if (ret == 0) {
137 paths.emplace_back(nvcc_path + "..");
138 paths.emplace_back(nvcc_path + ".." + PATH_SPLITER + "include");
139 }
140 }
141
142 // 3. use libcudart.so library path
143 char cuda_lib_path[PATH_MAX];
144 auto handle = dlopen("libcudart.so", RTLD_GLOBAL | RTLD_LAZY);
145 if (handle != nullptr) {
146 mgb_assert(
147 dlinfo(handle, RTLD_DI_ORIGIN, cuda_lib_path) != -1, "%s", dlerror());
148 paths.emplace_back(
149 std::string(cuda_lib_path) + PATH_SPLITER + ".." + PATH_SPLITER +
150 "include");
151 }
152 mgb_assert(
153 paths.size() > 0,
154 "can't find cuda include path, check your environment of cuda, "
155 "try one of this solutions "
156 "1. set CUDA_BIN_PATH to cuda home path "
157 "2. add nvcc path in PATH "
158 "3. add libcudart.so path in LD_LIBRARY_PATH");
159 return paths;
160}
161
162#else
163

Callers

nothing calls this directly

Calls 8

get_nvcc_root_pathFunction · 0.85
check_file_existFunction · 0.85
dlinfoFunction · 0.85
emplace_backMethod · 0.80
dlopenFunction · 0.70
dlerrorFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected