diff --git a/src/runtime/RuntimeInfo.cpp b/src/runtime/RuntimeInfo.cpp index 213ebd128..1734a7187 100644 --- a/src/runtime/RuntimeInfo.cpp +++ b/src/runtime/RuntimeInfo.cpp @@ -76,6 +76,21 @@ Path RuntimeInfo::igcPath() return {}; } +Path RuntimeInfo::libdevicePath() +{ + // Should reside in the same directory! + const Path exePath = executablePath(); + if (exePath.empty()) + return {}; + + const Path libPath = exePath.parent_path() / "libdevice.10.bc"; + + if (std::filesystem::exists(libPath)) + return libPath; + else + return {}; +} + Path RuntimeInfo::modulePath(void* func) { if (func == nullptr) diff --git a/src/runtime/RuntimeInfo.h b/src/runtime/RuntimeInfo.h index b9f465b31..a4ee18eed 100644 --- a/src/runtime/RuntimeInfo.h +++ b/src/runtime/RuntimeInfo.h @@ -7,6 +7,7 @@ class IG_LIB RuntimeInfo { public: [[nodiscard]] static Path executablePath(); // Path to the current executable [[nodiscard]] static Path igcPath(); // Path to the ignis jit compiler 'igc' + [[nodiscard]] static Path libdevicePath(); // Path to 'libdevice.10.bc' needed by the cuda device [[nodiscard]] static Path modulePath(void* func = nullptr); // Path to the module/dll for the given function [[nodiscard]] static Path cacheDirectory(); [[nodiscard]] static size_t sizeOfDirectory(const Path& dir); diff --git a/src/runtime/device/DeviceManager.cpp b/src/runtime/device/DeviceManager.cpp index 65c9be699..6d9465749 100644 --- a/src/runtime/device/DeviceManager.cpp +++ b/src/runtime/device/DeviceManager.cpp @@ -4,12 +4,16 @@ #include "RuntimeInfo.h" #include "StringUtils.h" +#include + #include #define _IG_DEVICE_ENV_PATH_NAME "IG_DEVICE_PATH" #define _IG_DEVICE_ENV_SKIP_SYSTEM_PATH "IG_DEVICE_SKIP_SYSTEM_PATH" #define _IG_DEVICE_LIB_PREFIX "ig_device_" +#define ANYDSL_CUDA_LIBDEVICE_PATH_ENV "ANYDSL_CUDA_LIBDEVICE_PATH" + namespace IG { using GetInterfaceFunction = const IDeviceInterface* (*)(); @@ -64,6 +68,16 @@ bool DeviceManager::init(const Path& dir, bool ignoreEnv, bool force) if (!force && !mAvailableDevices.empty()) return true; + const auto libdevicePath = RuntimeInfo::libdevicePath(); + if (!libdevicePath.empty()) { + IG_LOG(L_DEBUG) << "Setting libdevice path " << libdevicePath << " to environment variable " << ANYDSL_CUDA_LIBDEVICE_PATH_ENV << std::endl; +#ifdef IG_OS_WINDOWS + _putenv_s(ANYDSL_CUDA_LIBDEVICE_PATH_ENV, libdevicePath.generic_string().c_str()); +#else + setenv(ANYDSL_CUDA_LIBDEVICE_PATH_ENV, libdevicePath.generic_string().c_str(), 1); +#endif + } + path_set paths; bool skipSystem = false; // Skip the system search path