From fec213af58e8693e931406b24058a9bb291034cf Mon Sep 17 00:00:00 2001 From: makslevental Date: Tue, 24 Sep 2024 16:50:36 -0400 Subject: [PATCH] remove direct link --- build_tools/build_test_cpp.sh | 9 --------- cmake/iree_aie_utils.cmake | 2 ++ .../src/iree-amd-aie/driver/hsa/CMakeLists.txt | 18 ++++++------------ .../iree-amd-aie/driver/hsa/dynamic_symbols.cc | 15 ++------------- .../src/iree-amd-aie/driver/hsa/hsa_driver.cc | 5 ++++- .../src/iree-amd-aie/driver/hsa/hsa_headers.h | 5 ----- 6 files changed, 14 insertions(+), 40 deletions(-) diff --git a/build_tools/build_test_cpp.sh b/build_tools/build_test_cpp.sh index 9ac2c07b60..e3c4c80898 100644 --- a/build_tools/build_test_cpp.sh +++ b/build_tools/build_test_cpp.sh @@ -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" @@ -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" diff --git a/cmake/iree_aie_utils.cmake b/cmake/iree_aie_utils.cmake index 2e0911dfa7..e1ca2db2b1 100644 --- a/cmake/iree_aie_utils.cmake +++ b/cmake/iree_aie_utils.cmake @@ -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}") @@ -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() diff --git a/runtime/src/iree-amd-aie/driver/hsa/CMakeLists.txt b/runtime/src/iree-amd-aie/driver/hsa/CMakeLists.txt index 348379f109..01525dcd41 100644 --- a/runtime/src/iree-amd-aie/driver/hsa/CMakeLists.txt +++ b/runtime/src/iree-amd-aie/driver/hsa/CMakeLists.txt @@ -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 @@ -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 @@ -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() \ No newline at end of file diff --git a/runtime/src/iree-amd-aie/driver/hsa/dynamic_symbols.cc b/runtime/src/iree-amd-aie/driver/hsa/dynamic_symbols.cc index 372b4a4cc8..47b9edd8e5 100644 --- a/runtime/src/iree-amd-aie/driver/hsa/dynamic_symbols.cc +++ b/runtime/src/iree-amd-aie/driver/hsa/dynamic_symbols.cc @@ -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"; @@ -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__) @@ -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, @@ -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); } @@ -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); diff --git a/runtime/src/iree-amd-aie/driver/hsa/hsa_driver.cc b/runtime/src/iree-amd-aie/driver/hsa/hsa_driver.cc index 875f06ed2a..e5b6164ca0 100644 --- a/runtime/src/iree-amd-aie/driver/hsa/hsa_driver.cc +++ b/runtime/src/iree-amd-aie/driver/hsa/hsa_driver.cc @@ -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); diff --git a/runtime/src/iree-amd-aie/driver/hsa/hsa_headers.h b/runtime/src/iree-amd-aie/driver/hsa/hsa_headers.h index 5a276db258..6afc9055c8 100644 --- a/runtime/src/iree-amd-aie/driver/hsa/hsa_headers.h +++ b/runtime/src/iree-amd-aie/driver/hsa/hsa_headers.h @@ -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_