Skip to content

Commit

Permalink
Update and use getCUDAQXLibraryPath
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Howe <[email protected]>
  • Loading branch information
bmhowe23 committed Jan 18, 2025
1 parent 58b6f99 commit 9f6790d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

namespace cudaqx::__internal__ {

enum class CudaQXLibType { Solvers, QEC };

/// @brief Structure to hold CUDAQX library data.
struct CUDAQXLibraryData {
std::string path; ///< The path to the CUDAQX library.
std::string libName; // The name to search for
};

#if defined(__APPLE__) && defined(__MACH__)
Expand All @@ -31,11 +34,11 @@ struct CUDAQXLibraryData {
/// path.
inline static void getCUDAQXLibraryPath(CUDAQXLibraryData *data) {
auto nLibs = _dyld_image_count();
auto casted = static_cast<CUDAQLibraryData *>(data);
for (uint32_t i = 0; i < nLibs; i++) {
auto ptr = _dyld_get_image_name(i);
std::string libName(ptr);
if (libName.find("cudaq-core") != std::string::npos) {
auto casted = static_cast<CUDAQLibraryData *>(data);
if (libName.find(casted->libName) != std::string::npos) {
casted->path = std::string(ptr);
}
}
Expand All @@ -51,8 +54,8 @@ inline static void getCUDAQXLibraryPath(CUDAQXLibraryData *data) {
inline static int getCUDAQXLibraryPath(struct dl_phdr_info *info, size_t size,
void *data) {
std::string libraryName(info->dlpi_name);
if (libraryName.find("cudaq-solvers") != std::string::npos) {
auto casted = static_cast<CUDAQXLibraryData *>(data);
auto casted = static_cast<CUDAQXLibraryData *>(data);
if (libraryName.find(casted->libName) != std::string::npos) {
casted->path = std::string(info->dlpi_name);
}
return 0;
Expand All @@ -61,8 +64,18 @@ inline static int getCUDAQXLibraryPath(struct dl_phdr_info *info, size_t size,

/// @brief Retrieves the path of the CUDAQX library.
/// @return A string containing the path to the CUDAQX library.
inline static std::string getCUDAQXLibraryPath() {
inline static std::string getCUDAQXLibraryPath(const CudaQXLibType lib) {
__internal__::CUDAQXLibraryData data;
data.libName = [&]() -> std::string {
switch (lib) {
case CudaQXLibType::QEC:
return "cudaq-qec";
case CudaQXLibType::Solvers:
return "cudaq-solvers";
}
return "UNKNOWN";
}();

#if defined(__APPLE__) && defined(__MACH__)
getCUDAQXLibraryPath(&data);
#else
Expand Down
5 changes: 4 additions & 1 deletion libs/qec/lib/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <filesystem>
#include <vector>

#include "cuda-qx/core/library_utils.h"

INSTANTIATE_REGISTRY(cudaq::qec::decoder, const cudaqx::tensor<uint8_t> &)
INSTANTIATE_REGISTRY(cudaq::qec::decoder, const cudaqx::tensor<uint8_t> &,
const cudaqx::heterogeneous_map &)
Expand Down Expand Up @@ -79,7 +81,8 @@ std::unique_ptr<decoder> get_decoder(const std::string &name,
// Constructor function for auto-loading plugins
__attribute__((constructor)) void load_decoder_plugins() {
// Load plugins from the decoder-specific plugin directory
std::filesystem::path cudaqLibPath{cudaq::getCUDAQLibraryPath()};
std::filesystem::path cudaqLibPath{cudaqx::__internal__::getCUDAQXLibraryPath(
cudaqx::__internal__::CudaQXLibType::QEC)};
auto pluginPath = cudaqLibPath.parent_path() / "decoder-plugins";
load_plugins(pluginPath.string(), PluginType::DECODER);
}
Expand Down
5 changes: 3 additions & 2 deletions libs/solvers/lib/operators/molecule/drivers/pyscf_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "nlohmann/json.hpp"

#include "cuda-qx/core/library_utils.h"
#include "cuda-qx/core/tensor.h"
#include "library_utils.h"
#include "process.h"
#include "cudaq/solvers/operators/molecule/fermion_compiler.h"
#include "cudaq/solvers/operators/molecule/molecule_package_driver.h"
Expand Down Expand Up @@ -62,7 +62,8 @@ class RESTPySCFDriver : public MoleculePackageDriver {
std::unique_ptr<tear_down> make_available() const override {

// Start up the web service, if failed, return nullptr
std::filesystem::path libPath{cudaqx::__internal__::getCUDAQXLibraryPath()};
std::filesystem::path libPath{cudaqx::__internal__::getCUDAQXLibraryPath(
cudaqx::__internal__::CudaQXLibType::Solvers)};
auto cudaqLibPath = libPath.parent_path();
auto cudaqPySCFTool = cudaqLibPath.parent_path() / "bin" / "cudaq-pyscf";
auto argString = cudaqPySCFTool.string() + " --server-mode";
Expand Down

0 comments on commit 9f6790d

Please sign in to comment.