void SoAction::apply(const SoPathList &pathList, SbBool obeysRules) // //////////////////////////////////////////////////////////////////////// { // Check for empty path list if (pathList.getLength() == 0) return; // If path list obeys the rules, just apply the action to it if (obeysRules) { apply(pathList, pathList, TRUE); return; } // // Otherwise, we may have to break it into smaller lists that do // obey the rules // // First, sort the paths SoPathList sortedPathList(pathList); sortedPathList.sort(); // Remove any duplicate paths and any paths that continue through // the tail node of another path sortedPathList.uniquify(); int numPaths = sortedPathList.getLength(); // If all the remaining paths have the same head, just apply to // the sorted path list const SoNode *firstHead = sortedPathList[0]->getHead(); if (sortedPathList[numPaths-1]->getHead() == firstHead) apply(sortedPathList, pathList, TRUE); // Otherwise, we have to break the path list into smaller ones else splitPathList(sortedPathList, pathList); }
void CudaCompiler::staticInit(void) { if (s_inited) { return; } s_inited = true; // Search for CUDA on Linux system std::vector<std::string> potentialCudaPaths; potentialCudaPaths.push_back( "/usr/local/cuda" );// // Query environment variables. std::string pathEnv = queryEnv("PATH"); std::string includeEnv = queryEnv("INCLUDE"); std::string cudaBinEnv = queryEnv("CUDA_BIN_PATH"); std::string cudaIncEnv = queryEnv("CUDA_INC_PATH"); // Find CUDA binary path. std::vector<std::string> cudaBinList; if (s_staticCudaBinPath.length()) { cudaBinList.push_back(s_staticCudaBinPath); } else { cudaBinList.push_back(cudaBinEnv); splitPathList(cudaBinList, pathEnv); for (size_t i = 0u; i < potentialCudaPaths.size(); ++i) { cudaBinList.push_back(potentialCudaPaths[i] + "/bin"); cudaBinList.push_back(potentialCudaPaths[i] + "/bin64"); } } std::string cudaBinPath; for (size_t i = 0u; i < cudaBinList.size(); ++i) { if (!cudaBinList[i].length() || !fileExists(cudaBinList[i] + "/nvcc")) { continue; } // Execute "nvcc --version". std::string cmd = "\"" + cudaBinList[i] + "/nvcc\" --version 2>/dev/null"; FILE* pipe = popen( cmd.c_str(), "r"); if (!pipe) { continue; } std::vector<char> output; while (!feof(pipe)) { output.push_back((char)fgetc(pipe)); } pclose(pipe); output.push_back('\0'); // Test wether nvcc --version output is standard or not (kind of a hack) // Invalid response => ignore. std::string response(&output[0]); if (response.find_first_of("nvcc: NVIDIA") != 0u) { continue; } // A (supposed) valid nvcc compiler has been found cudaBinPath = cudaBinList[i]; s_nvccVersionHash = hash<std::string>(response); // break; } if (!cudaBinPath.size()) { fail( "Unable to detect CUDA Toolkit binary path!\nPlease set CUDA_BIN_PATH"\ " environment variable." ); } // Find CUDA include path. std::vector<std::string> cudaIncList; cudaIncList.push_back(cudaBinPath + "/../include"); cudaIncList.push_back(cudaIncEnv); splitPathList(cudaIncList, includeEnv); std::string cudaIncPath; for (size_t i=0u; i<cudaIncList.size(); ++i) { if (cudaIncList[i].length() && fileExists(cudaIncList[i] + "/cuda.h")) { cudaIncPath = cudaIncList[i]; break; } } if (!cudaIncPath.length()) { fail("Unable to detect CUDA Toolkit include path!\n" "Please set CUDA_INC_PATH environment variable."); } system( ("export PATH=$PATH:" + cudaBinPath).c_str() ); s_nvccCommand = "nvcc -I\"" + cudaIncPath + "\" -I. -D_CRT_SECURE_NO_DEPRECATE"; }