diff --git a/openmp/libomptarget/plugins/amdgpu/impl/atmi.cpp b/openmp/libomptarget/plugins/amdgpu/impl/atmi.cpp --- a/openmp/libomptarget/plugins/amdgpu/impl/atmi.cpp +++ b/openmp/libomptarget/plugins/amdgpu/impl/atmi.cpp @@ -10,13 +10,6 @@ #include #include -/* - * Initialize/Finalize - */ -atmi_status_t atmi_init() { return core::Runtime::Initialize(); } - -atmi_status_t atmi_finalize() { return core::Runtime::Finalize(); } - /* * Machine Info */ diff --git a/openmp/libomptarget/plugins/amdgpu/impl/atmi_interop_hsa.cpp b/openmp/libomptarget/plugins/amdgpu/impl/atmi_interop_hsa.cpp --- a/openmp/libomptarget/plugins/amdgpu/impl/atmi_interop_hsa.cpp +++ b/openmp/libomptarget/plugins/amdgpu/impl/atmi_interop_hsa.cpp @@ -5,8 +5,6 @@ *===------------------------------------------------------------------------*/ #include "internal.h" -using core::atl_is_atmi_initialized; - atmi_status_t atmi_interop_hsa_get_symbol_info( std::map &SymbolInfoTable, atmi_mem_place_t place, const char *symbol, void **var_addr, @@ -20,8 +18,6 @@ atmi_memcpy(signal, host_add, var_addr, var_size); */ - if (!atl_is_atmi_initialized()) - return ATMI_STATUS_ERROR; atmi_machine_t *machine = atmi_machine_get_info(); if (!symbol || !var_addr || !var_size || !machine) return ATMI_STATUS_ERROR; @@ -55,8 +51,6 @@ &val); */ - if (!atl_is_atmi_initialized()) - return ATMI_STATUS_ERROR; atmi_machine_t *machine = atmi_machine_get_info(); if (!kernel_name || !value || !machine) return ATMI_STATUS_ERROR; diff --git a/openmp/libomptarget/plugins/amdgpu/impl/machine.cpp b/openmp/libomptarget/plugins/amdgpu/impl/machine.cpp --- a/openmp/libomptarget/plugins/amdgpu/impl/machine.cpp +++ b/openmp/libomptarget/plugins/amdgpu/impl/machine.cpp @@ -13,8 +13,6 @@ #include #include -extern ATLMachine g_atl_machine; - void ATLProcessor::addMemory(const ATLMemory &mem) { for (auto &mem_obj : memories_) { // if the memory already exists, then just return diff --git a/openmp/libomptarget/plugins/amdgpu/impl/rt.h b/openmp/libomptarget/plugins/amdgpu/impl/rt.h --- a/openmp/libomptarget/plugins/amdgpu/impl/rt.h +++ b/openmp/libomptarget/plugins/amdgpu/impl/rt.h @@ -49,17 +49,8 @@ return instance; } - // init/finalize - static atmi_status_t Initialize(); - static atmi_status_t Finalize(); // machine info static atmi_machine_t *GetMachineInfo(); - // modules - static atmi_status_t RegisterModuleFromMemory( - void *, size_t, atmi_place_t, - atmi_status_t (*on_deserialized_data)(void *data, size_t size, - void *cb_state), - void *cb_state, std::vector &HSAExecutables); // data static atmi_status_t Memcpy(hsa_signal_t, void *, const void *, size_t); diff --git a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp --- a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp +++ b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp @@ -132,7 +132,6 @@ std::vector atl_gpu_kernarg_pools; -bool g_atmi_initialized = false; bool g_atmi_hostcall_required = false; /* @@ -150,18 +149,6 @@ return &g_atmi_machine; } -static void atl_set_atmi_initialized() { - // FIXME: thread safe? locks? - g_atmi_initialized = true; -} - -static void atl_reset_atmi_initialized() { - // FIXME: thread safe? locks? - g_atmi_initialized = false; -} - -bool atl_is_atmi_initialized() { return g_atmi_initialized; } - void allow_access_to_all_gpu_agents(void *ptr) { hsa_status_t err; std::vector &gpu_procs = @@ -178,37 +165,6 @@ } } -atmi_status_t Runtime::Initialize() { - atmi_devtype_t devtype = ATMI_DEVTYPE_GPU; - if (atl_is_atmi_initialized()) - return ATMI_STATUS_SUCCESS; - - if (devtype == ATMI_DEVTYPE_ALL || devtype & ATMI_DEVTYPE_GPU) { - if (atl_init_gpu_context() != ATMI_STATUS_SUCCESS) { - printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__, "GPU context init", - get_atmi_error_string(atl_init_gpu_context())); - exit(1); - } - } - - atl_set_atmi_initialized(); - return ATMI_STATUS_SUCCESS; -} - -atmi_status_t Runtime::Finalize() { - hsa_status_t err; - - atl_reset_atmi_initialized(); - err = hsa_shut_down(); - if (err != HSA_STATUS_SUCCESS) { - printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__, "Shutting down HSA", - get_error_string(err)); - exit(1); - } - - return ATMI_STATUS_SUCCESS; -} - static void atmi_init_context_structs() { atlc.struct_initialized = true; /* This only gets called one time */ atlc.g_hsa_initialized = false; diff --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp --- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp +++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp @@ -465,11 +465,12 @@ print_kernel_trace = 0; DP("Start initializing HSA-ATMI\n"); - atmi_status_t err = atmi_init(); + atmi_status_t err = core::atl_init_gpu_context(); if (err != ATMI_STATUS_SUCCESS) { DP("Error when initializing HSA-ATMI\n"); return; } + // Init hostcall soon after initializing ATMI hostrpc_init(); @@ -592,7 +593,12 @@ hostrpc_terminate(); DestroyHSAExecutables(); - atmi_finalize(); + hsa_status_t Err = hsa_shut_down(); + if (Err != HSA_STATUS_SUCCESS) { + printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__, "Shutting down HSA", + get_error_string(Err)); + return; + } } };