Skip to content

Commit

Permalink
remove direct link
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Sep 25, 2024
1 parent f768298 commit fec213a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 40 deletions.
9 changes: 0 additions & 9 deletions build_tools/build_test_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ if [ -d "$llvm_install_dir" ]; then
)
fi

IREE_AIE_HSA_RUNTIME_DIRECT_LINK=${IREE_AIE_HSA_RUNTIME_DIRECT_LINK:-OFF}
if [ "$IREE_AIE_HSA_RUNTIME_DIRECT_LINK" == "ON" ] && [ -d "$hsa_runtime64_DIR" ] && [ -d "$hsakmt_DIR" ]; then
CMAKE_ARGS+=(
-Dhsa-runtime64_DIR="$hsa_runtime64_DIR"
-Dhsakmt_DIR="$hsakmt_DIR"
)
fi

if [[ "$OSTYPE" == "linux"* ]]; then
CMAKE_ARGS+=(
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld"
Expand All @@ -118,7 +110,6 @@ if [[ "$OSTYPE" == "linux"* ]]; then
-DCMAKE_CXX_COMPILER="${CXX}"
-DLLVM_TARGET_ARCH=X86
-DLLVM_TARGETS_TO_BUILD=X86
-DIREE_AIE_HSA_RUNTIME_DIRECT_LINK=${IREE_AIE_HSA_RUNTIME_DIRECT_LINK:-OFF}
-DIREE_EXTERNAL_HAL_DRIVERS=${IREE_EXTERNAL_HAL_DRIVERS:-amd-aie-xrt}
-S
"$iree_dir"
Expand Down
2 changes: 2 additions & 0 deletions cmake/iree_aie_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function(replace_string_in_file _file _match_string _replace_string)
if(NOT (EXISTS ${_file}))
message(FATAL_ERROR "file ${_file} does not exist")
endif()
file(LOCK "${_file}.lock" GUARD FUNCTION)
file(READ "${_file}" _file_contents)
if(_file_contents STREQUAL "")
message(FATAL_ERROR "empty file contents for ${_file}")
Expand All @@ -38,5 +39,6 @@ function(replace_string_in_file _file _match_string _replace_string)
message(FATAL_ERROR "empty replacement contents for ${_file}")
endif()
file(WRITE "${_file}" "${_file_contents}")
file(LOCK "${_file}.lock" RELEASE)
endfunction()

18 changes: 6 additions & 12 deletions runtime/src/iree-amd-aie/driver/hsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ replace_string_in_file(
"${ROCR_RUNTIME_ROOT}/runtime/hsa-runtime/core/inc/amd_gpu_agent.h"
"static const" "const")

if(NOT DEFINED HSA_API_HEADERS_ROOT)
set(HSA_API_HEADERS_ROOT "${ROCR_RUNTIME_ROOT}/runtime/hsa-runtime/inc")
endif()

iree_cc_library(
NAME
dynamic_symbols
Expand All @@ -33,6 +37,8 @@ iree_cc_library(
dynamic_symbols.cc
hsa_headers.h
status_util.cc
INCLUDES
"${HSA_API_HEADERS_ROOT}"
DEPS
iree::base
iree::base::core_headers
Expand Down Expand Up @@ -84,15 +90,3 @@ iree_cc_library(
iree::hal::utils::semaphore_base
PUBLIC
)

option(IREE_AIE_HSA_RUNTIME_DIRECT_LINK "" OFF)
if(IREE_AIE_HSA_RUNTIME_DIRECT_LINK)
find_package(hsa-runtime64 CONFIG REQUIRED NAMES hsa-runtime64 hsa_runtime64)
target_link_libraries(iree-amd-aie_driver_hsa_dynamic_symbols PUBLIC hsa-runtime64::hsa-runtime64)
target_compile_definitions(iree-amd-aie_driver_hsa_dynamic_symbols PUBLIC IREE_AIE_HSA_RUNTIME_DIRECT_LINK)
else()
if(NOT DEFINED HSA_API_HEADERS_ROOT)
set(HSA_API_HEADERS_ROOT "${ROCR_RUNTIME_ROOT}/runtime/hsa-runtime/inc")
endif()
target_include_directories(iree-amd-aie_driver_hsa_dynamic_symbols PUBLIC "${HSA_API_HEADERS_ROOT}")
endif()
15 changes: 2 additions & 13 deletions runtime/src/iree-amd-aie/driver/hsa/dynamic_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "iree/base/api.h"
#include "iree/base/internal/dynamic_library.h"

#ifndef IREE_AIE_HSA_RUNTIME_DIRECT_LINK
constexpr const char* LIBHSA_RUNTIME_PATH_ENV_VAR = "LIBHSA_RUNTIME_PATH";
#if defined(IREE_PLATFORM_WINDOWS)
constexpr char DEFAULT_LIBHSA_RUNTIME_PATH_VAL[] = "libhsa-runtime64.dll";
Expand All @@ -26,23 +25,15 @@ const char* libhsa_runtime_path_val = libhsa_runtime_path_env_var_ptr == nullptr
: libhsa_runtime_path_env_var_ptr;

static const char* iree_hal_hsa_dylib_names[] = {libhsa_runtime_path_val};
#endif

static iree_status_t iree_hal_hsa_dynamic_symbols_resolve_all(
iree_hal_hsa_dynamic_symbols_t* syms) {
#ifdef IREE_AIE_HSA_RUNTIME_DIRECT_LINK
#define IREE_HAL_HSA_REQUIRED_PFN_DECL(hsa_symbol_name, ...) \
{ \
syms->hsa_symbol_name = hsa::hsa_symbol_name; \
}
#else
#define IREE_HAL_HSA_REQUIRED_PFN_DECL(hsa_symbol_name, ...) \
{ \
static const char* name = #hsa_symbol_name; \
IREE_RETURN_IF_ERROR(iree_dynamic_library_lookup_symbol( \
syms->dylib, name, (void**)&syms->hsa_symbol_name)); \
}
#endif

#define IREE_HAL_HSA_REQUIRED_PFN_DECL_RET(_, hsa_symbol_name, ...) \
IREE_HAL_HSA_REQUIRED_PFN_DECL(hsa_symbol_name, __VA_ARGS__)
Expand All @@ -58,7 +49,6 @@ iree_status_t iree_hal_hsa_dynamic_symbols_initialize(
IREE_TRACE_ZONE_BEGIN(z0);

iree_status_t status = iree_ok_status();
#ifndef IREE_AIE_HSA_RUNTIME_DIRECT_LINK
memset(out_syms, 0, sizeof(*out_syms));
status = iree_dynamic_library_load_from_files(
IREE_ARRAYSIZE(iree_hal_hsa_dylib_names), iree_hal_hsa_dylib_names,
Expand All @@ -71,10 +61,11 @@ iree_status_t iree_hal_hsa_dynamic_symbols_initialize(
"available;"
"please ensure installed and in dynamic library search path");
}
#endif

if (iree_status_is_ok(status)) {
status = iree_hal_hsa_dynamic_symbols_resolve_all(out_syms);
}

if (!iree_status_is_ok(status)) {
iree_hal_hsa_dynamic_symbols_deinitialize(out_syms);
}
Expand All @@ -87,9 +78,7 @@ void iree_hal_hsa_dynamic_symbols_deinitialize(
iree_hal_hsa_dynamic_symbols_t* syms) {
IREE_TRACE_ZONE_BEGIN(z0);

#ifndef IREE_AIE_HSA_RUNTIME_DIRECT_LINK
iree_dynamic_library_release(syms->dylib);
#endif
memset(syms, 0, sizeof(*syms));

IREE_TRACE_ZONE_END(z0);
Expand Down
5 changes: 4 additions & 1 deletion runtime/src/iree-amd-aie/driver/hsa/hsa_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ static void iree_hal_hsa_driver_destroy(iree_hal_driver_t* base_driver) {
iree_allocator_t host_allocator = driver->host_allocator;
IREE_TRACE_ZONE_BEGIN(z0);

// iree_hal_hsa_dynamic_symbols_deinitialize(&driver->hsa_symbols);
// TODO(max): hsa doesn't free kfd and drm file descriptors at shutdown
// so in some configuration (eg during cts_driver_test) you get a HSA_OUT_OF_RESOURCES_ERROR
// if you deinit here. Note, the hip HAL also doesn't deinit...
// iree_hal_hsa_dynamic_symbols_deinitialize(&driver->hsa_symbols);
iree_allocator_free(host_allocator, driver);

IREE_TRACE_ZONE_END(z0);
Expand Down
5 changes: 0 additions & 5 deletions runtime/src/iree-amd-aie/driver/hsa/hsa_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
#endif // defined(IREE_PTR_SIZE_32)

namespace hsa {
#ifdef IREE_AIE_HSA_RUNTIME_DIRECT_LINK
#include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h"
#else
#include "hsa.h"
#include "hsa_ext_amd.h"
#endif
} // namespace hsa

#endif // IREE_AMD_AIE_DRIVER_HSA_HSA_HEADERS_H_

0 comments on commit fec213a

Please sign in to comment.