Skip to content

Commit

Permalink
Merge branch 'development' into feature/glare_frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
PearCoding committed Jun 20, 2024
2 parents d882493 + c1bba28 commit 8c7b544
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 32 deletions.
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ find_package(TBB REQUIRED)
# ZLib is used in the generator
find_package(ZLIB REQUIRED)

# Locate stuff for windows
# On Linux this is properly propagated
# So it needs a fixing in AnyDSL
if(WIN32)
find_package(CUDAToolkit)
find_package(OpenCL)
endif()

# Locate AnyDSL runtime (general purpose)
find_package(AnyDSL_runtime REQUIRED)

Expand Down
3 changes: 2 additions & 1 deletion cmake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ if(IG_INSTALL_RUNTIME_DEPENDENCIES)
else()
set(exclude_regexes
"libX.*" "libxkb.*" "libwayland.*" "libvorbis.*" "libexpat.*" "libFLAC.*" "libpulse.*" "libasound.*" # Skip media related libraries
"libcuda.*" "libOpenCL.*" "libnvvm.*" "libnvrtc.*" # Ignore CUDA related stuff, as the system should be providing it!
)
endif()

Expand All @@ -62,6 +61,8 @@ if(IG_INSTALL_RUNTIME_DEPENDENCIES)
list(APPEND search_dirs "${Python_RUNTIME_LIBRARY_DIRS}")
list(APPEND search_dirs "${Python_RUNTIME_SABI_LIBRARY_DIRS}")
endif()

find_package(CUDAToolkit)
if(CUDAToolkit_FOUND)
list(APPEND search_dirs "${CUDAToolkit_BIN_DIR}")
endif()
Expand Down
64 changes: 41 additions & 23 deletions src/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,39 @@ list(REMOVE_DUPLICATES _DISABLED_DEVICES)
list(TRANSFORM _DISABLED_DEVICES TOUPPER)

###########################################################
option(IG_ASSUME_NVIDIA "Assume CUDA libraries are available" OFF)
mark_as_advanced(IG_ASSUME_NVIDIA)
if(IG_ASSUME_NVIDIA OR AnyDSL_runtime_HAS_CUDA_SUPPORT)
set(_HAS_CUDA ON)
else()
find_library(CUDA_LIBRARY cudart HINTS ${CUDA_DIR} PATHS /usr/local/cuda
ENV CUDA_PATH
ENV CUDA_LIB_PATH
PATH_SUFFIXES "lib/Win32" "lib" "libWin32")
if(EXISTS "${CUDA_LIBRARY}")
set(_HAS_CUDA ON)
find_package(CUDAToolkit)

if(CUDAToolkit_FOUND)
if(CUDAToolkit_LIBRARY_ROOT)
set(_CUDA_ROOT ${CUDAToolkit_LIBRARY_ROOT})
else()
set(_CUDA_ROOT "${CUDAToolkit_LIBRARY_DIR}/..")
endif()

find_file(_LIBDEVICE_LIB
NAMES libdevice.10.bc
HINTS ${_CUDA_ROOT}
PATH_SUFFIXES nvvm/libdevice)

if(_LIBDEVICE_LIB)
message(STATUS "Redistributing ${_LIBDEVICE_LIB}")
install(FILES ${_LIBDEVICE_LIB} ${_IG_RUNTIME_SET} DESTINATION bin COMPONENT runtime)
else()
message(WARNING "Could not find 'libdevice.10.bc'. Redistribution might fail")
endif()

set(_HAS_CUDA ON)
endif()

###########################################################
option(IG_ASSUME_AMD "Assume AMD rocm libraries are available" OFF)
mark_as_advanced(IG_ASSUME_AMD)

if(IG_ASSUME_AMD OR AnyDSL_runtime_HAS_HSA_SUPPORT)
set(_HAS_HSA ON)
else()
find_library(HSA_LIBRARY hsa-runtime64 HINTS ${HSA_DIR} PATHS /opt/rocm PATH_SUFFIXES lib)

if(EXISTS "${HSA_LIBRARY}")
set(_HAS_HSA ON)
endif()
Expand All @@ -39,42 +51,47 @@ endif()
include(CMakeDependentOption)
option(IG_WITH_DEVICE_CPU "Enable CPU device" ON)
option(IG_WITH_DEVICE_GPU "Enable GPU device" ON)

# cmake_dependent_option(IG_WITH_DEVICE_CPU_SIMD "Enable CPU vectorized device" ON "IG_WITH_DEVICE_CPU" OFF)
cmake_dependent_option(IG_WITH_DEVICE_GPU_NVIDIA "Enable NVidia GPU device" ON "IG_WITH_DEVICE_GPU;_HAS_CUDA" OFF)
cmake_dependent_option(IG_WITH_DEVICE_GPU_AMD_HSA "Enable AMD GPU device via HSA" ON "IG_WITH_DEVICE_GPU;_HAS_HSA" OFF)
cmake_dependent_option(IG_WITH_DEVICE_GPU_NVIDIA "Enable NVidia GPU device" ON "IG_WITH_DEVICE_GPU;_HAS_CUDA" OFF)
cmake_dependent_option(IG_WITH_DEVICE_GPU_AMD_HSA "Enable AMD GPU device via HSA" ON "IG_WITH_DEVICE_GPU;_HAS_HSA" OFF)

# ##########################################################
set(VARIANTS)
if (IG_WITH_DEVICE_CPU)

if(IG_WITH_DEVICE_CPU)
list(APPEND VARIANTS cpu)
endif()
if (IG_WITH_DEVICE_GPU_NVIDIA)

if(IG_WITH_DEVICE_GPU_NVIDIA)
list(APPEND VARIANTS cuda)
endif()
if (IG_WITH_DEVICE_GPU_AMD_HSA)

if(IG_WITH_DEVICE_GPU_AMD_HSA)
list(APPEND VARIANTS hsa)
endif()

# ##########################################################
set(_targets )
###########################################################
set(_targets)

foreach(var ${VARIANTS})
string(TOUPPER "${var}" VAR_UPPER)
set(_target_name ig_device_${var})
message(STATUS "Adding device for ${var}")

set(AnyDSLRuntimeDevice_LIBRARIES )
set(AnyDSLRuntimeDevice_INCLUDE_DIRS )
set(AnyDSLRuntimeDevice_LIBRARIES)
set(AnyDSLRuntimeDevice_INCLUDE_DIRS)

find_package(AnyDSLRuntimeDevice COMPONENTS ${var})
if (NOT AnyDSLRuntimeDevice_${var}_FOUND)

if(NOT AnyDSLRuntimeDevice_${var}_FOUND)
message(WARNING "No specific AnyDSL runtime for device ${var} found. Using default one")
set(AnyDSLRuntimeDevice_LIBRARIES ${AnyDSL_runtime_LIBRARIES} ${AnyDSL_runtime_ARTIC_JIT_LIBRARIES})
set(AnyDSLRuntimeDevice_INCLUDE_DIRS ${AnyDSL_runtime_INCLUDE_DIRS})
endif()

add_library(${_target_name} MODULE ${SRC})
target_link_libraries(${_target_name} PUBLIC ig_lib_runtime PRIVATE ${AnyDSLRuntimeDevice_LIBRARIES} TBB::tbb TBB::tbbmalloc )
target_link_libraries(${_target_name} PUBLIC ig_lib_runtime PRIVATE ${AnyDSLRuntimeDevice_LIBRARIES} TBB::tbb TBB::tbbmalloc)
target_include_directories(${_target_name} SYSTEM PRIVATE ${AnyDSLRuntimeDevice_INCLUDE_DIRS})
target_compile_definitions(${_target_name} PRIVATE $<BUILD_INTERFACE:"IG_BUILD_DEVICE_${VAR_UPPER}">)
set_target_properties(${_target_name} PROPERTIES PREFIX "")
Expand All @@ -89,6 +106,7 @@ foreach(var ${VARIANTS})
# however devices are dynamically defined and ment to be rebuild anyway.
if(NOT IG_BUILD_DEVICE_PARALLEL)
list(LENGTH _targets _length)

if(_length GREATER 0)
list(GET _targets -1 _prev)
add_dependencies(${_target_name} ${_prev})
Expand Down
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 8c7b544

Please sign in to comment.