Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion projects/rocr-runtime/rocrtst/common/base_rocr_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@
#include "gtest/gtest.h"
#include "hsa/hsa.h"

#if !defined(ROCRTST_ASAN)
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define ROCRTST_ASAN 1
#endif
#endif
#if defined(__SANITIZE_ADDRESS__)
#define ROCRTST_ASAN 1
#endif
#endif

namespace rocrtst {


Expand Down Expand Up @@ -106,16 +117,22 @@ hsa_status_t CommonCleanUp(BaseRocR* test) {
}

test->clear_code_object();

err = hsa_shut_down();
RET_IF_HSA_UTILS_ERR(err);

// Ensure that HSA is actually closed.
#ifndef ROCRTST_ASAN
// Ensure that HSA is actually closed.
hsa_status_t check = hsa_shut_down();
if (check != HSA_STATUS_ERROR_NOT_INITIALIZED) {
EXPECT_EQ(HSA_STATUS_ERROR_NOT_INITIALIZED, check) << "hsa_init reference count was too high.";
return HSA_STATUS_ERROR;
}

#else
// Avoid a second shutdown under ASAN; its device allocator may be unloaded.
#endif

std::string intr_val;

if (test->orig_hsa_enable_interrupt() == nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ void Runtime::RegisterDriver(std::unique_ptr<Driver> driver) {
void Runtime::DestroyAgents() {
agents_by_node_.clear();

// Clear system regions before destroying agents to prevent use-after-free
// when agent destructors access region memory
system_regions_fine_.clear();
system_regions_coarse_.clear();
std::for_each(gpu_agents_.begin(), gpu_agents_.end(), DeleteObject());
gpu_agents_.clear();

Expand All @@ -271,9 +275,6 @@ void Runtime::DestroyAgents() {
aie_agents_.clear();

region_gpu_ = NULL;

system_regions_fine_.clear();
system_regions_coarse_.clear();
}

void Runtime::DestroyDrivers() {
Expand Down
Loading