Skip to content
Merged
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
12 changes: 10 additions & 2 deletions projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#define HIP_API_TABLE_STEP_VERSION 0
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
#define HIP_TOOLS_API_TABLE_STEP_VERSION 0
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 20
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 21

// HIP API interface
// HIP compiler dispatch functions
Expand Down Expand Up @@ -1113,6 +1113,9 @@ typedef hipError_t (*t_hipKernelGetLibrary)(hipLibrary_t* library, hipKernel_t k
typedef hipError_t (*t_hipKernelGetName)(const char** name, hipKernel_t kernel);
typedef hipError_t (*t_hipGetProcAddress_spt)(const char* symbol, void** pfn, int hipVersion, uint64_t flags,
hipDriverProcAddressQueryResult* symbolStatus);
typedef hipError_t (*t_hipExtDisableLogging)();
typedef hipError_t (*t_hipExtEnableLogging)();
typedef hipError_t (*t_hipExtSetLoggingParams)(size_t log_level, size_t log_size, size_t log_mask);

typedef hipError_t (*t_hipKernelGetParamInfo)(hipKernel_t kernel, size_t paramIndex,
size_t* paramOffset, size_t* paramSize);
Expand Down Expand Up @@ -1707,8 +1710,13 @@ struct HipDispatchTable {
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 20
t_hipKernelGetParamInfo hipKernelGetParamInfo_fn;

// DO NOT EDIT ABOVE!
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 21
t_hipExtDisableLogging hipExtDisableLogging_fn;
t_hipExtEnableLogging hipExtEnableLogging_fn;
t_hipExtSetLoggingParams hipExtSetLoggingParams_fn;

// DO NOT EDIT ABOVE!
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 22

// ******************************************************************************************* //
//
Expand Down
52 changes: 51 additions & 1 deletion projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ enum hip_api_id_t {
HIP_API_ID_hipKernelGetName = 448,
HIP_API_ID_hipOccupancyAvailableDynamicSMemPerBlock = 449,
HIP_API_ID_hipKernelGetParamInfo = 450,
HIP_API_ID_LAST = 450,
HIP_API_ID_hipExtDisableLogging = 451,
HIP_API_ID_hipExtEnableLogging = 452,
HIP_API_ID_hipExtSetLoggingParams = 453,
HIP_API_ID_LAST = 453,

HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
Expand Down Expand Up @@ -590,12 +593,15 @@ static inline const char* hip_api_name(const uint32_t id) {
case HIP_API_ID_hipEventRecord: return "hipEventRecord";
case HIP_API_ID_hipEventRecordWithFlags: return "hipEventRecordWithFlags";
case HIP_API_ID_hipEventSynchronize: return "hipEventSynchronize";
case HIP_API_ID_hipExtDisableLogging: return "hipExtDisableLogging";
case HIP_API_ID_hipExtEnableLogging: return "hipExtEnableLogging";
case HIP_API_ID_hipExtGetLastError: return "hipExtGetLastError";
case HIP_API_ID_hipExtGetLinkTypeAndHopCount: return "hipExtGetLinkTypeAndHopCount";
case HIP_API_ID_hipExtLaunchKernel: return "hipExtLaunchKernel";
case HIP_API_ID_hipExtLaunchMultiKernelMultiDevice: return "hipExtLaunchMultiKernelMultiDevice";
case HIP_API_ID_hipExtMallocWithFlags: return "hipExtMallocWithFlags";
case HIP_API_ID_hipExtModuleLaunchKernel: return "hipExtModuleLaunchKernel";
case HIP_API_ID_hipExtSetLoggingParams: return "hipExtSetLoggingParams";
case HIP_API_ID_hipExtStreamCreateWithCUMask: return "hipExtStreamCreateWithCUMask";
case HIP_API_ID_hipExtStreamGetCUMask: return "hipExtStreamGetCUMask";
case HIP_API_ID_hipExternalMemoryGetMappedBuffer: return "hipExternalMemoryGetMappedBuffer";
Expand Down Expand Up @@ -1034,12 +1040,15 @@ static inline uint32_t hipApiIdByName(const char* name) {
if (strcmp("hipEventRecord", name) == 0) return HIP_API_ID_hipEventRecord;
if (strcmp("hipEventRecordWithFlags", name) == 0) return HIP_API_ID_hipEventRecordWithFlags;
if (strcmp("hipEventSynchronize", name) == 0) return HIP_API_ID_hipEventSynchronize;
if (strcmp("hipExtDisableLogging", name) == 0) return HIP_API_ID_hipExtDisableLogging;
if (strcmp("hipExtEnableLogging", name) == 0) return HIP_API_ID_hipExtEnableLogging;
if (strcmp("hipExtGetLastError", name) == 0) return HIP_API_ID_hipExtGetLastError;
if (strcmp("hipExtGetLinkTypeAndHopCount", name) == 0) return HIP_API_ID_hipExtGetLinkTypeAndHopCount;
if (strcmp("hipExtLaunchKernel", name) == 0) return HIP_API_ID_hipExtLaunchKernel;
if (strcmp("hipExtLaunchMultiKernelMultiDevice", name) == 0) return HIP_API_ID_hipExtLaunchMultiKernelMultiDevice;
if (strcmp("hipExtMallocWithFlags", name) == 0) return HIP_API_ID_hipExtMallocWithFlags;
if (strcmp("hipExtModuleLaunchKernel", name) == 0) return HIP_API_ID_hipExtModuleLaunchKernel;
if (strcmp("hipExtSetLoggingParams", name) == 0) return HIP_API_ID_hipExtSetLoggingParams;
if (strcmp("hipExtStreamCreateWithCUMask", name) == 0) return HIP_API_ID_hipExtStreamCreateWithCUMask;
if (strcmp("hipExtStreamGetCUMask", name) == 0) return HIP_API_ID_hipExtStreamGetCUMask;
if (strcmp("hipExternalMemoryGetMappedBuffer", name) == 0) return HIP_API_ID_hipExternalMemoryGetMappedBuffer;
Expand Down Expand Up @@ -1851,6 +1860,11 @@ typedef struct hip_api_data_s {
hipEvent_t stopEvent;
unsigned int flags;
} hipExtModuleLaunchKernel;
struct {
size_t log_level;
size_t log_size;
size_t log_mask;
} hipExtSetLoggingParams;
struct {
hipStream_t* stream;
hipStream_t stream__val;
Expand Down Expand Up @@ -4484,6 +4498,12 @@ typedef struct hip_api_data_s {
#define INIT_hipEventSynchronize_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipEventSynchronize.event = (hipEvent_t)event; \
};
// hipExtDisableLogging[]
#define INIT_hipExtDisableLogging_CB_ARGS_DATA(cb_data) { \
};
// hipExtEnableLogging[]
#define INIT_hipExtEnableLogging_CB_ARGS_DATA(cb_data) { \
};
// hipExtGetLastError[]
#define INIT_hipExtGetLastError_CB_ARGS_DATA(cb_data) { \
};
Expand Down Expand Up @@ -4535,6 +4555,12 @@ typedef struct hip_api_data_s {
cb_data.args.hipExtModuleLaunchKernel.stopEvent = (hipEvent_t)stopEvent; \
cb_data.args.hipExtModuleLaunchKernel.flags = (unsigned int)flags; \
};
// hipExtSetLoggingParams[('size_t', 'log_level'), ('size_t', 'log_size'), ('size_t', 'log_mask')]
#define INIT_hipExtSetLoggingParams_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipExtSetLoggingParams.log_level = (size_t)log_level; \
cb_data.args.hipExtSetLoggingParams.log_size = (size_t)log_size; \
cb_data.args.hipExtSetLoggingParams.log_mask = (size_t)log_mask; \
};
// hipExtStreamCreateWithCUMask[('hipStream_t*', 'stream'), ('unsigned int', 'cuMaskSize'), ('const unsigned int*', 'cuMask')]
#define INIT_hipExtStreamCreateWithCUMask_CB_ARGS_DATA(cb_data) { \
cb_data.args.hipExtStreamCreateWithCUMask.stream = (hipStream_t*)stream; \
Expand Down Expand Up @@ -7125,6 +7151,12 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
// hipEventSynchronize[('hipEvent_t', 'event')]
case HIP_API_ID_hipEventSynchronize:
break;
// hipExtDisableLogging[]
case HIP_API_ID_hipExtDisableLogging:
break;
// hipExtEnableLogging[]
case HIP_API_ID_hipExtEnableLogging:
break;
// hipExtGetLastError[]
case HIP_API_ID_hipExtGetLastError:
break;
Expand All @@ -7150,6 +7182,9 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
if (data->args.hipExtModuleLaunchKernel.kernelParams) data->args.hipExtModuleLaunchKernel.kernelParams__val = *(data->args.hipExtModuleLaunchKernel.kernelParams);
if (data->args.hipExtModuleLaunchKernel.extra) data->args.hipExtModuleLaunchKernel.extra__val = *(data->args.hipExtModuleLaunchKernel.extra);
break;
// hipExtSetLoggingParams[('size_t', 'log_level'), ('size_t', 'log_size'), ('size_t', 'log_mask')]
case HIP_API_ID_hipExtSetLoggingParams:
break;
// hipExtStreamCreateWithCUMask[('hipStream_t*', 'stream'), ('unsigned int', 'cuMaskSize'), ('const unsigned int*', 'cuMask')]
case HIP_API_ID_hipExtStreamCreateWithCUMask:
if (data->args.hipExtStreamCreateWithCUMask.stream) data->args.hipExtStreamCreateWithCUMask.stream__val = *(data->args.hipExtStreamCreateWithCUMask.stream);
Expand Down Expand Up @@ -9124,6 +9159,14 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
oss << "event="; roctracer::hip_support::detail::operator<<(oss, data->args.hipEventSynchronize.event);
oss << ")";
break;
case HIP_API_ID_hipExtDisableLogging:
oss << "hipExtDisableLogging(";
oss << ")";
break;
case HIP_API_ID_hipExtEnableLogging:
oss << "hipExtEnableLogging(";
oss << ")";
break;
case HIP_API_ID_hipExtGetLastError:
oss << "hipExtGetLastError(";
oss << ")";
Expand Down Expand Up @@ -9188,6 +9231,13 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
oss << ", flags="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtModuleLaunchKernel.flags);
oss << ")";
break;
case HIP_API_ID_hipExtSetLoggingParams:
oss << "hipExtSetLoggingParams(";
oss << "log_level="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtSetLoggingParams.log_level);
oss << ", log_size="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtSetLoggingParams.log_size);
oss << ", log_mask="; roctracer::hip_support::detail::operator<<(oss, data->args.hipExtSetLoggingParams.log_mask);
oss << ")";
break;
case HIP_API_ID_hipExtStreamCreateWithCUMask:
oss << "hipExtStreamCreateWithCUMask(";
if (data->args.hipExtStreamCreateWithCUMask.stream == NULL) oss << "stream=NULL";
Expand Down
1 change: 1 addition & 0 deletions projects/clr/hipamd/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ target_sources(amdhip64 PRIVATE
hip_graph.cpp
hip_hmm.cpp
hip_intercept.cpp
hip_log.cpp
hip_memory.cpp
hip_mempool.cpp
hip_mempool_impl.cpp
Expand Down
3 changes: 3 additions & 0 deletions projects/clr/hipamd/src/amdhip.def
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,6 @@ hipKernelGetName
hipOccupancyAvailableDynamicSMemPerBlock
hipGetProcAddress_spt
hipKernelGetParamInfo
hipExtDisableLogging
hipExtEnableLogging
hipExtSetLoggingParams
14 changes: 12 additions & 2 deletions projects/clr/hipamd/src/hip_api_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ hipError_t hipOccupancyAvailableDynamicSMemPerBlock(size_t* dynamicSmemSize, con
int numBlocks, int blockSize);
hipError_t hipKernelGetParamInfo(hipKernel_t kernel, size_t paramIndex, size_t* paramOffset,
size_t* paramSize);
hipError_t hipExtDisableLogging();
hipError_t hipExtEnableLogging();
hipError_t hipExtSetLoggingParams(size_t log_level, size_t log_size, size_t log_mask);
} // namespace hip

namespace hip {
Expand Down Expand Up @@ -1432,6 +1435,9 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
ptrDispatchTable->hipKernelGetName_fn = hip::hipKernelGetName;
ptrDispatchTable->hipOccupancyAvailableDynamicSMemPerBlock_fn = hip::hipOccupancyAvailableDynamicSMemPerBlock;
ptrDispatchTable->hipKernelGetParamInfo_fn = hip::hipKernelGetParamInfo;
ptrDispatchTable->hipExtDisableLogging_fn = hip::hipExtDisableLogging;
ptrDispatchTable->hipExtEnableLogging_fn = hip::hipExtEnableLogging;
ptrDispatchTable->hipExtSetLoggingParams_fn = hip::hipExtSetLoggingParams;
}

#if HIP_ROCPROFILER_REGISTER > 0
Expand Down Expand Up @@ -2114,15 +2120,19 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipOccupancyAvailableDynamicSMemPerBlock_fn, 5
HIP_ENFORCE_ABI(HipDispatchTable, hipGetProcAddress_spt_fn, 506);
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 20
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetParamInfo_fn, 507);
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 21
HIP_ENFORCE_ABI(HipDispatchTable, hipExtDisableLogging_fn, 508);
HIP_ENFORCE_ABI(HipDispatchTable, hipExtEnableLogging_fn, 509);
HIP_ENFORCE_ABI(HipDispatchTable, hipExtSetLoggingParams_fn, 510);
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
//
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
//
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 508)
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 511)

static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 20,
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 21,
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
"pointers and then update this check so it is true");
#endif
3 changes: 3 additions & 0 deletions projects/clr/hipamd/src/hip_hcc.map.in
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ global:
hipOccupancyAvailableDynamicSMemPerBlock;
hipGetProcAddress_spt;
hipKernelGetParamInfo;
hipExtDisableLogging;
hipExtEnableLogging;
hipExtSetLoggingParams;
local:
*;
} hip_7.1;
31 changes: 31 additions & 0 deletions projects/clr/hipamd/src/hip_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <hip/hip_runtime.h>
#include "hip_internal.hpp"
#include "hip_platform.hpp"

namespace hip {

hipError_t hipExtEnableLogging() {
HIP_INIT_API(hipExtEnableLogging);
amd::ScopedLock lock(PlatformState::instance().getLogLock());
AMD_LOG_LEVEL = PlatformState::instance().log_level_;
AMD_LOG_MASK = PlatformState::instance().log_mask_;
HIP_RETURN(hipSuccess);
}

hipError_t hipExtDisableLogging() {
HIP_INIT_API(hipExtDisableLogging);
amd::ScopedLock lock(PlatformState::instance().getLogLock());
AMD_LOG_LEVEL = 0;
HIP_RETURN(hipSuccess);
}

hipError_t hipExtSetLoggingParams(size_t log_level, size_t log_size, size_t log_mask) {
HIP_INIT_API(hipExtSetLoggingParams, log_level, log_size, log_mask);
amd::ScopedLock lock(PlatformState::instance().getLogLock());
// Store logging parameters for later activation
PlatformState::instance().log_level_ = log_level;
PlatformState::instance().log_size_ = log_size;
PlatformState::instance().log_mask_ = log_mask;
HIP_RETURN(hipSuccess);
}
} // namespace::hip
18 changes: 17 additions & 1 deletion projects/clr/hipamd/src/hip_platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class PlatformState {
// Unique FD Store Lock
amd::Monitor ufd_lock_{true};

// Lock for logging operations
amd::Monitor lg_lock_{true};

// Singleton object
static PlatformState* platform_;
PlatformState() {}
PlatformState() : log_level_(0), log_size_(0), log_mask_(0) {}
~PlatformState() {}

public:
Expand Down Expand Up @@ -113,6 +116,14 @@ class PlatformState {

size_t UfdMapSize() const { return ufd_map_.size(); }

// Logging lock accessor
amd::Monitor& getLogLock() { return lg_lock_; }

// Friend functions for logging access
friend hipError_t hipExtEnableLogging();
friend hipError_t hipExtDisableLogging();
friend hipError_t hipExtSetLoggingParams(size_t log_level, size_t log_size, size_t log_mask);

inline bool RegisterLibraryFunction(const hipKernel_t f, const hipLibrary_t l) {
amd::ScopedLock lock(lock_);
if (library_functions_.find(f) == library_functions_.end()) {
Expand Down Expand Up @@ -150,5 +161,10 @@ class PlatformState {

void* dynamicLibraryHandle_{nullptr};
std::unordered_map<hipKernel_t, hipLibrary_t> library_functions_;

// Logging state (moved from LoggingInfo singleton)
size_t log_level_;
size_t log_size_;
size_t log_mask_;
};
} // namespace hip
9 changes: 9 additions & 0 deletions projects/clr/hipamd/src/hip_table_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,4 +2067,13 @@ hipError_t hipKernelGetParamInfo(hipKernel_t kernel, size_t paramIndex, size_t*
size_t* paramSize) {
return hip::GetHipDispatchTable()->hipKernelGetParamInfo_fn(kernel, paramIndex, paramOffset,
paramSize);
}
hipError_t hipExtEnableLogging() {
return hip::GetHipDispatchTable()->hipExtEnableLogging_fn();
}
hipError_t hipExtDisableLogging() {
return hip::GetHipDispatchTable()->hipExtDisableLogging_fn();
}
hipError_t hipExtSetLoggingParams(size_t log_level, size_t log_size, size_t log_mask) {
return hip::GetHipDispatchTable()->hipExtSetLoggingParams_fn(log_level, log_size, log_mask);
}
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@
#endif
"=== Following tests disabled as it should be a local perf test",
"Performance_hipExtLaunchKernelGGL_QueryGPUFrequency",
"Unit_hipDynamicLogging_Positive_Basic",
"Unit_hipDynamicLogging_Positive_MultipleEnableDisable",
"End of json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(TEST_SRC
hipDrvGetErrorString.cc
hipGetLastError.cc
hipPeekAtLastError.cc
hipDynamicLogging.cc
)

if(UNIX)
Expand Down
Loading
Loading