Skip to content

Commit

Permalink
make use of the new environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
PearCoding committed Jun 20, 2024
1 parent 6bf7d02 commit c1bba28
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/runtime/RuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/runtime/RuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/runtime/device/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include "RuntimeInfo.h"
#include "StringUtils.h"

#include <cstdlib>

#include <unordered_set>

#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* (*)();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c1bba28

Please sign in to comment.