@brief Search the targets folder in the install for available targets.
| 106 | |
| 107 | /// @brief Search the targets folder in the install for available targets. |
| 108 | void findAvailableTargets( |
| 109 | const std::filesystem::path &targetPath, |
| 110 | std::unordered_map<std::string, RuntimeTarget> &targets, |
| 111 | std::unordered_map<std::string, RuntimeTarget> &simulationTargets) { |
| 112 | |
| 113 | // directory_iterator ordering is unspecified, so sort it to make it |
| 114 | // repeatable and consistent. |
| 115 | std::vector<std::filesystem::directory_entry> targetEntries; |
| 116 | for (const auto &entry : std::filesystem::directory_iterator{targetPath}) |
| 117 | targetEntries.push_back(entry); |
| 118 | std::sort(targetEntries.begin(), targetEntries.end(), |
| 119 | [](const std::filesystem::directory_entry &a, |
| 120 | const std::filesystem::directory_entry &b) { |
| 121 | return a.path().filename() < b.path().filename(); |
| 122 | }); |
| 123 | |
| 124 | // Loop over all target files |
| 125 | for (const auto &configFile : targetEntries) { |
| 126 | auto path = configFile.path(); |
| 127 | // They must have a .yml suffix |
| 128 | const std::string configFileExt = ".yml"; |
| 129 | if (path.extension().string() == configFileExt) { |
| 130 | auto fileName = path.filename().string(); |
| 131 | auto targetName = |
| 132 | std::regex_replace(fileName, std::regex(configFileExt), ""); |
| 133 | // Open the file and look for the platform, simulator, and description |
| 134 | std::ifstream inFile(path.string()); |
| 135 | const std::string configFileContent( |
| 136 | (std::istreambuf_iterator<char>(inFile)), |
| 137 | std::istreambuf_iterator<char>()); |
| 138 | cudaq::config::TargetConfig config; |
| 139 | llvm::yaml::Input Input(configFileContent.c_str()); |
| 140 | Input >> config; |
| 141 | CUDAQ_INFO("Found Target {} with config file {}", targetName, fileName); |
| 142 | const std::string defaultTargetConfigStr = |
| 143 | cudaq::config::processRuntimeArgs(config, {}); |
| 144 | RuntimeTarget target; |
| 145 | target.config = config; |
| 146 | target.name = targetName; |
| 147 | target.description = config.Description; |
| 148 | auto cudaqLibPath = targetPath.parent_path() / "lib"; |
| 149 | parseRuntimeTarget(cudaqLibPath, target, defaultTargetConfigStr); |
| 150 | CUDAQ_INFO("Found Target: {} -> (sim={}, platform={})", targetName, |
| 151 | target.simulatorName, target.platformName); |
| 152 | // Add the target. |
| 153 | targets.emplace(targetName, target); |
| 154 | |
| 155 | simulationTargets.emplace(targetName, target); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | LinkedLibraryHolder::LinkedLibraryHolder() : availablePlatforms{"default"} { |
| 161 | ScopedTraceWithContext("LinkedLibraryHolder::constructor"); |
no test coverage detected