[SWDEV-513658] Force HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG value to be used with HSA calls (#192)
* Force HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG value to be used with HSA calls Fix for CI * More tweaks * Increase reproducible-runtime kernel sleep granularity * Fix data race in synchronous device counter collection sample * Update device counting service - add get_active_context function --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
@@ -139,19 +139,8 @@ set_profiler_active_on_queue(hsa_amd_memory_pool_t pool,
|
||||
const size_t mask = 0x1000 - 1;
|
||||
auto size = (profile.command_buffer.size + mask) & ~mask;
|
||||
|
||||
#define HSA_AMD_INTERFACE_VERSION \
|
||||
ROCPROFILER_COMPUTE_VERSION(HSA_AMD_INTERFACE_VERSION_MAJOR, HSA_AMD_INTERFACE_VERSION_MINOR, 0)
|
||||
|
||||
#if HSA_AMD_INTERFACE_VERSION >= 10700
|
||||
constexpr auto hsa_amd_memory_pool_executable_flag = HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG;
|
||||
#elif HSA_AMD_INTERFACE_VERSION == 10600
|
||||
constexpr auto hsa_amd_memory_pool_executable_flag = (1 << 2);
|
||||
#else
|
||||
constexpr auto hsa_amd_memory_pool_executable_flag = 0;
|
||||
#endif
|
||||
|
||||
if(hsa::get_amd_ext_table()->hsa_amd_memory_pool_allocate_fn(
|
||||
pool, size, hsa_amd_memory_pool_executable_flag, &profile.command_buffer.ptr) !=
|
||||
pool, size, hsa::hsa_amd_memory_pool_executable_flag, &profile.command_buffer.ptr) !=
|
||||
HSA_STATUS_SUCCESS)
|
||||
{
|
||||
ROCP_WARNING << "Failed to allocate memory to enable profile command on agent, some "
|
||||
|
||||
@@ -172,6 +172,20 @@ get_active_contexts(context_filter_t filter)
|
||||
return data;
|
||||
}
|
||||
|
||||
const context*
|
||||
get_active_context(rocprofiler_context_id_t id)
|
||||
{
|
||||
if(get_num_active_contexts().load(std::memory_order_acquire) > 0)
|
||||
{
|
||||
for(auto& itr : get_active_contexts_impl())
|
||||
{
|
||||
const auto* ctx = itr.load(std::memory_order_acquire);
|
||||
if(ctx && ctx->context_idx == id.handle) return ctx;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// set the client index needs to be called before allocate_context()
|
||||
void
|
||||
push_client(uint32_t value)
|
||||
|
||||
@@ -199,6 +199,9 @@ get_active_contexts(context_array_t& data, context_filter_t filter = default_con
|
||||
context_array_t
|
||||
get_active_contexts(context_filter_t filter = default_context_filter);
|
||||
|
||||
const context*
|
||||
get_active_context(rocprofiler_context_id_t id);
|
||||
|
||||
/// \brief disable the contexturation.
|
||||
rocprofiler_status_t
|
||||
stop_client_contexts(rocprofiler_client_id_t id);
|
||||
|
||||
@@ -25,10 +25,16 @@
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/core.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/device_counting.hpp"
|
||||
#include "lib/rocprofiler-sdk/registration.hpp"
|
||||
#include "rocprofiler-sdk/fwd.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto rocprofiler_context_none = ROCPROFILER_CONTEXT_NONE;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
rocprofiler_status_t
|
||||
rocprofiler_configure_device_counting_service(rocprofiler_context_id_t context_id,
|
||||
@@ -48,14 +54,26 @@ rocprofiler_sample_device_counting_service(rocprofiler_context_id_t context
|
||||
rocprofiler_record_counter_t* output_records,
|
||||
size_t* rec_count)
|
||||
{
|
||||
if(context_id == rocprofiler_context_none) return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND;
|
||||
|
||||
// if finalized or finalizing, ignore request
|
||||
if(rocprofiler::registration::get_fini_status() != 0) return ROCPROFILER_STATUS_ERROR_FINALIZED;
|
||||
|
||||
// capture the active context status now
|
||||
const auto* ctx = rocprofiler::context::get_active_context(context_id);
|
||||
|
||||
// do not proceed if context has not been started
|
||||
if(!ctx) return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_STARTED;
|
||||
|
||||
if(output_records != nullptr)
|
||||
{
|
||||
if((flags & ROCPROFILER_COUNTER_FLAG_ASYNC) != 0)
|
||||
if(!rec_count || (flags & ROCPROFILER_COUNTER_FLAG_ASYNC) != 0)
|
||||
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
CHECK(rec_count);
|
||||
|
||||
if(*rec_count == 0) return ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES;
|
||||
|
||||
auto recs = std::vector<rocprofiler_record_counter_t>{};
|
||||
auto status = rocprofiler::counters::read_agent_ctx(
|
||||
rocprofiler::context::get_registered_context(context_id), user_data, flags, &recs);
|
||||
auto status = rocprofiler::counters::read_agent_ctx(ctx, user_data, flags, &recs);
|
||||
if(status == ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
if(recs.size() > *rec_count)
|
||||
@@ -70,7 +88,6 @@ rocprofiler_sample_device_counting_service(rocprofiler_context_id_t context
|
||||
return status;
|
||||
}
|
||||
|
||||
return rocprofiler::counters::read_agent_ctx(
|
||||
rocprofiler::context::get_registered_context(context_id), user_data, flags, nullptr);
|
||||
return rocprofiler::counters::read_agent_ctx(ctx, user_data, flags, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,11 +57,16 @@ CounterAQLPacket::CounterMemoryPool::Alloc(void** ptr, size_t size, desc_t flags
|
||||
|
||||
hsa_status_t status;
|
||||
if(!pool.bIgnoreKernArg && flags.memory_hint == AQLPROFILE_MEMORY_HINT_DEVICE_UNCACHED)
|
||||
status = pool.allocate_fn(pool.kernarg_pool_, size, 0, ptr);
|
||||
status =
|
||||
pool.allocate_fn(pool.kernarg_pool_, size, hsa_amd_memory_pool_executable_flag, ptr);
|
||||
else
|
||||
status = pool.allocate_fn(pool.cpu_pool_, size, 0, ptr);
|
||||
status = pool.allocate_fn(pool.cpu_pool_, size, hsa_amd_memory_pool_executable_flag, ptr);
|
||||
|
||||
if(status != HSA_STATUS_SUCCESS) return status;
|
||||
if(status != HSA_STATUS_SUCCESS)
|
||||
{
|
||||
ROCP_FATAL << "Could not allocate memory";
|
||||
return status;
|
||||
}
|
||||
|
||||
status = pool.fill_fn(*ptr, 0u, size / sizeof(uint32_t));
|
||||
if(status != HSA_STATUS_SUCCESS) return status;
|
||||
@@ -149,7 +154,7 @@ TraceMemoryPool::Alloc(void** ptr, size_t size, desc_t flags, void* data)
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
if(flags.host_access)
|
||||
{
|
||||
status = pool.allocate_fn(pool.cpu_pool_, size, 0, ptr);
|
||||
status = pool.allocate_fn(pool.cpu_pool_, size, hsa_amd_memory_pool_executable_flag, ptr);
|
||||
|
||||
if(status == HSA_STATUS_SUCCESS)
|
||||
status = pool.allow_access_fn(1, &pool.gpu_agent, nullptr, *ptr);
|
||||
@@ -157,7 +162,8 @@ TraceMemoryPool::Alloc(void** ptr, size_t size, desc_t flags, void* data)
|
||||
else
|
||||
{
|
||||
// Return page aligned data to avoid cache flush overlap
|
||||
status = pool.allocate_fn(pool.gpu_pool_, size + 0x2000, 0, ptr);
|
||||
status = pool.allocate_fn(
|
||||
pool.gpu_pool_, size + 0x2000, hsa_amd_memory_pool_executable_flag, ptr);
|
||||
*ptr = (void*) ((uintptr_t(*ptr) + 0xFFF) & ~0xFFFul); // NOLINT(performance-no-int-to-ptr)
|
||||
}
|
||||
return status;
|
||||
|
||||
@@ -40,6 +40,15 @@ class ThreadTraceAQLPacketFactory;
|
||||
|
||||
namespace hsa
|
||||
{
|
||||
#define HSA_AMD_INTERFACE_VERSION \
|
||||
ROCPROFILER_COMPUTE_VERSION(HSA_AMD_INTERFACE_VERSION_MAJOR, HSA_AMD_INTERFACE_VERSION_MINOR, 0)
|
||||
|
||||
#if HSA_AMD_INTERFACE_VERSION >= 10700
|
||||
constexpr auto hsa_amd_memory_pool_executable_flag = HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG;
|
||||
#else
|
||||
constexpr auto hsa_amd_memory_pool_executable_flag = (1 << 2);
|
||||
#endif
|
||||
|
||||
constexpr hsa_ext_amd_aql_pm4_packet_t null_amd_aql_pm4_packet = {
|
||||
.header = 0,
|
||||
.pm4_command = {0},
|
||||
|
||||
Reference in New Issue
Block a user