Add 'projects/rocprofiler/' from commit '16ae2e90c6157e98e846d2bccbaaf533ca5e662a'
git-subtree-dir: projects/rocprofiler git-subtree-mainline:2a52e3974dgit-subtree-split:16ae2e90c6
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
---
|
||||
If:
|
||||
PathMatch: common/common.h
|
||||
|
||||
CompileFlags:
|
||||
Add: ['-x', 'hip']
|
||||
|
||||
# Local Variables:
|
||||
# mode: yaml
|
||||
# End:
|
||||
@@ -0,0 +1,194 @@
|
||||
include(CheckCSourceCompiles)
|
||||
# ########################################################################################
|
||||
# ########################################################################################
|
||||
# General Requirements
|
||||
# ########################################################################################
|
||||
# ########################################################################################
|
||||
get_property(
|
||||
HSA_RUNTIME_INCLUDE_DIRECTORIES
|
||||
TARGET hsa-runtime64::hsa-runtime64
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
find_file(
|
||||
HSA_H hsa.h
|
||||
PATHS ${HSA_RUNTIME_INCLUDE_DIRECTORIES}
|
||||
PATH_SUFFIXES hsa
|
||||
NO_DEFAULT_PATH REQUIRED)
|
||||
get_filename_component(HSA_RUNTIME_INC_PATH ${HSA_H} DIRECTORY)
|
||||
include_directories(${HSA_RUNTIME_INC_PATH})
|
||||
|
||||
# Set the HIP language runtime link flags as FindHIP does not set them.
|
||||
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG})
|
||||
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP})
|
||||
set(CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG})
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROCM_PATH}/lib/cmake/hip")
|
||||
set(CMAKE_HIP_ARCHITECTURES OFF)
|
||||
if(DEFINED ROCM_PATH)
|
||||
set(HIP_ROOT_DIR "${ROCM_PATH}/bin")
|
||||
endif()
|
||||
find_package(HIP REQUIRED MODULE)
|
||||
|
||||
find_package(
|
||||
Clang REQUIRED CONFIG
|
||||
PATHS "${ROCM_PATH}"
|
||||
PATH_SUFFIXES "llvm/lib/cmake/clang")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules"
|
||||
"${ROCM_PATH}/lib/cmake/hip")
|
||||
find_package(LibElf REQUIRED)
|
||||
find_package(LibDw REQUIRED)
|
||||
|
||||
# Add a custom targets to build and run all the tests
|
||||
add_custom_target(samples ALL)
|
||||
add_dependencies(samples rocprofiler-v2)
|
||||
add_custom_target(
|
||||
run-samples
|
||||
COMMAND ${PROJECT_BINARY_DIR}/samples/run_samples.sh
|
||||
DEPENDS samples)
|
||||
|
||||
file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp)
|
||||
# ########################################################################################
|
||||
|
||||
function(rocprofiler_sample_add_test _TARGET _ARGS)
|
||||
if(TARGET ${_TARGET})
|
||||
if(NOT TEST ${_TARGET})
|
||||
add_test(
|
||||
NAME ${_TARGET}
|
||||
COMMAND $<TARGET_FILE:${_TARGET}> ${_ARGS}
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
endif()
|
||||
set_tests_properties(
|
||||
${_TARGET}
|
||||
PROPERTIES
|
||||
LABELS
|
||||
"samples"
|
||||
ENVIRONMENT
|
||||
"ROCPROFILER_METRICS_PATH=${PROJECT_BINARY_DIR}/libexec/rocprofiler/counters/derived_counters.xml;${ROCPROFILER_MEMCHECK_PRELOAD_ENV}"
|
||||
RUN_SERIAL
|
||||
TRUE
|
||||
${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(rocprofiler_sample_add_executable _TARGET)
|
||||
hip_add_executable(${_TARGET} ${ARGN})
|
||||
rocprofiler_sample_add_test(${_TARGET} "")
|
||||
endfunction()
|
||||
|
||||
# ########################################################################################
|
||||
# ########################################################################################
|
||||
# Samples Build & Run Script
|
||||
# ########################################################################################
|
||||
# ########################################################################################
|
||||
|
||||
# ########################################################################################
|
||||
# Profiler Samples
|
||||
# ########################################################################################
|
||||
|
||||
# Build Kernel No Replay Sample
|
||||
set_source_files_properties(profiler/kernel_profiling_no_replay_sample.cpp
|
||||
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
rocprofiler_sample_add_executable(
|
||||
profiler_kernel_no_replay profiler/kernel_profiling_no_replay_sample.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(
|
||||
profiler_kernel_no_replay PRIVATE ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(profiler_kernel_no_replay PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(profiler_kernel_no_replay PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples profiler_kernel_no_replay)
|
||||
install(TARGETS profiler_kernel_no_replay
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
|
||||
# Build Device Profiling Sample
|
||||
set_source_files_properties(profiler/device_profiling_sample.cpp
|
||||
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
rocprofiler_sample_add_executable(
|
||||
profiler_device_profiling profiler/device_profiling_sample.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(
|
||||
profiler_device_profiling PRIVATE ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(profiler_device_profiling PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(profiler_device_profiling PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples profiler_device_profiling)
|
||||
install(TARGETS profiler_device_profiling
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
set_tests_properties(profiler_device_profiling PROPERTIES DISABLED TRUE)
|
||||
|
||||
# Build Counters Sampling example
|
||||
set_source_files_properties(counters_sampler/pcie_counters_example.cpp
|
||||
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
rocprofiler_sample_add_executable(
|
||||
pcie_counters_sampler counters_sampler/pcie_counters_example.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(
|
||||
pcie_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(pcie_counters_sampler PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(pcie_counters_sampler PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples pcie_counters_sampler)
|
||||
install(TARGETS pcie_counters_sampler
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
|
||||
# Build XGMI Counters Sampling example
|
||||
set_source_files_properties(counters_sampler/xgmi_counters_sampler_example.cpp
|
||||
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
rocprofiler_sample_add_executable(
|
||||
xgmi_counters_sampler counters_sampler/xgmi_counters_sampler_example.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(
|
||||
xgmi_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(xgmi_counters_sampler PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(xgmi_counters_sampler PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples xgmi_counters_sampler)
|
||||
install(TARGETS xgmi_counters_sampler
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
set_tests_properties(xgmi_counters_sampler PROPERTIES DISABLED TRUE)
|
||||
|
||||
# ########################################################################################
|
||||
|
||||
# ########################################################################################
|
||||
# Tracer Samples
|
||||
# ########################################################################################
|
||||
|
||||
# Build HIP/HSA Trace Sample
|
||||
set_source_files_properties(tracer/sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
rocprofiler_sample_add_executable(tracer_hip_hsa tracer/sample.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(tracer_hip_hsa PRIVATE ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(tracer_hip_hsa PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(tracer_hip_hsa PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples tracer_hip_hsa)
|
||||
install(TARGETS tracer_hip_hsa
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
|
||||
# Build HIP/HSA Trace with async output api trace data Sample
|
||||
set_source_files_properties(tracer/sample_async.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT
|
||||
1)
|
||||
rocprofiler_sample_add_executable(tracer_hip_hsa_async tracer/sample_async.cpp
|
||||
${ROCPROFILER_UTIL_SRC_FILES})
|
||||
target_include_directories(
|
||||
tracer_hip_hsa_async PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
target_link_libraries(tracer_hip_hsa_async PRIVATE rocprofiler-v2 amd_comgr)
|
||||
target_link_options(tracer_hip_hsa_async PRIVATE "-Wl,--build-id=md5")
|
||||
add_dependencies(samples tracer_hip_hsa_async)
|
||||
install(TARGETS tracer_hip_hsa_async
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples
|
||||
COMPONENT samples)
|
||||
|
||||
# ########################################################################################
|
||||
# Scripts to run samples
|
||||
# ########################################################################################
|
||||
|
||||
# Copy run_samples script to samples folder
|
||||
configure_file(run_samples.sh ${PROJECT_BINARY_DIR}/samples COPYONLY)
|
||||
|
||||
# ########################################################################################
|
||||
@@ -0,0 +1,59 @@
|
||||
ROCM_PATH ?=/opt/rocm
|
||||
ROCPROFILER_LIBS_PATH ?=$(ROCM_PATH)/lib
|
||||
ROCM_INCLUDES=-I$(ROCM_PATH)/include
|
||||
ROCPROFILER_INCLUDES=-I$(ROCPROFILER_LIBS_PATH)/../include/rocprofiler/
|
||||
|
||||
LIBS=-L$(ROCPROFILER_LIBS_PATH) -lamd_comgr -lrocprofiler64v2
|
||||
|
||||
ifndef ROCPROFILER_LIBS_PATH
|
||||
$(warning You may need to set ROCPROFILER_LIBS_PATH to the path of the rocprofiler source)
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
all: profiler_kernel_no_replay profiler_device_profiling profiler_kernel_replay profiler_application_replay profiler_user_replay tracer_hip_hsa tracer_hip_hsa_async pcie_counters_sampler xgmi_counters_sampler pc_sampler
|
||||
|
||||
CXX=$(ROCM_PATH)/bin/hipcc -std=c++17 -Wall
|
||||
|
||||
DEBUG=1
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS =-DDEBUG -g
|
||||
else
|
||||
CFLAGS=-DNDEBUG
|
||||
endif
|
||||
|
||||
profiler_kernel_no_replay: profiler/kernel_profiling_no_replay_sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
profiler_device_profiling: profiler/device_profiling_sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
profiler_kernel_replay: profiler/kernel_replay_sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
profiler_application_replay: profiler/application_replay_sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
profiler_user_replay: profiler/user_replay_sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
tracer_hip_hsa: tracer/sample.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
tracer_hip_hsa_async: tracer/sample_async.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
pcie_counters_sampler: counters_sampler/pcie_counters_example.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
xgmi_counters_sampler: counters_sampler/xgmi_counters_sampler_example.cpp common/helper.cpp
|
||||
$(CXX) $^ $(LDFLAGS) -o $@ $(LIBS) $(ROCPROFILER_INCLUDES) $(ROCM_INCLUDES) $(CFLAGS)
|
||||
|
||||
pc_sampler :
|
||||
cd pcsampler/code_printing_sample && $(MAKE)
|
||||
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
$(RM) -rf xgmi_counters_sampler pcie_counters_sampler tracer_hip_hsa_async tracer_hip_hsa profiler_user_replay profiler_application_replay profiler_kernel_replay profiler_device_profiling profiler_kernel_no_replay && cd pcsampler/code_printing_sample && $(MAKE) clean
|
||||
@@ -0,0 +1,92 @@
|
||||
## DISCLAIMER
|
||||
|
||||
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes.THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies.
|
||||
|
||||
© 2023 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
|
||||
|
||||
## ROCProfiler API Concepts
|
||||
- Session
|
||||
- Filter
|
||||
- Buffer
|
||||
|
||||
|
||||
## API Philosophy
|
||||
|
||||
The APIs provide a common interface to the users for different
|
||||
features such as profiling, tracing.
|
||||
|
||||
In order to make use of any functionality of rocprofv2, one needs to create
|
||||
a "Session" object. This session could be a profiling session/tracing/pc-sampling session etc.
|
||||
|
||||
In order to set user inputs, one needs to provide a "Filter" to a session object.
|
||||
This filter could be for counters/traces/pc-samples etc.
|
||||
|
||||
Now that the input is taken care of, one also needs to provide a "Buffer" which
|
||||
will store the output results generated during a session. This buffer will contain
|
||||
different records corresponding to the filter type chosen. A flush function can also
|
||||
be specified for the buffer, which will be used to flush the buffer records.
|
||||
A filter and buffer are associated together.
|
||||
|
||||
Once a Session, Buffer, Filter have all been created, the session can be started.
|
||||
One can control when the session can be started, stopped and destroyed.
|
||||
|
||||
## Descriptions of Code Samples
|
||||
### kernel_profiling_sample.cpp
|
||||
This code sample demonstrates how to use the APIs to collect performance counters and metrics for every kernel dispatch.
|
||||
|
||||
### tracer_sample.cpp
|
||||
This code sample demonstrates how to use the APIs to collect different API and activity traces:
|
||||
- HIP API
|
||||
- HIP OPS
|
||||
- HSA API
|
||||
- HSA OPS
|
||||
- ROCTX
|
||||
|
||||
### device_profiling_sample.cpp
|
||||
This code sample demonstrates how to use the APIs to collect counters and metrics from the GPU via user defined sampling, instead of per-kernel dipatch measurements.
|
||||
|
||||
|
||||
## How to compile
|
||||
In order to get the samples to compile, make sure to copy rocprofiler binaries into /opt/rocm/lib
|
||||
Running 'make install' inside the rocprofiler/build folder will copy the binaries to /opt/rocm/lib
|
||||
|
||||
Alternately, change the 'ROCPROFILER_LIBS_PATH' variable in the Makefile to point to the rocprofiler/build folder.
|
||||
After modifications to Makefile are done, run:
|
||||
|
||||
```bash
|
||||
# compile all samples
|
||||
make
|
||||
```
|
||||
|
||||
```bash
|
||||
# compile kernel_profiling_no_replay_sample.cpp
|
||||
make kernel_profiling_no_replay_sample
|
||||
```
|
||||
|
||||
### How to run
|
||||
Before running, ROCPROFILER_METRICS_PATH needs to be set to point to 'derived_counters.xml'
|
||||
If the rocprofiler binaries are present in the rocm installation path /opt/rocm
|
||||
then below command will work:
|
||||
```bash
|
||||
export ROCPROFILER_METRICS_PATH=/opt/rocm/libexec/rocprofiler/counters/derived_counters.xml
|
||||
```
|
||||
|
||||
Otherwise, make it point to rocprofiler/build/libexec/rocprofiler/counters/derived_counters.xml like below:
|
||||
```bash
|
||||
export ROCPROFILER_METRICS_PATH=<path_to_rocprofiler>/rocprofiler/build/libexec/rocprofiler/counters/derived_counters.xml
|
||||
```
|
||||
|
||||
Finally, run a sample:
|
||||
```bash
|
||||
./kernel_profiling_no_replay_sample
|
||||
```
|
||||
|
||||
## PC-Sampler
|
||||
The ROCProfiler library includes an API to enable periodic sampling of the GPU
|
||||
program counter during kernel execution. An example program is included that demonstrates the PC
|
||||
sampling API, with additional code to illustrate a typical non-trivial use case:
|
||||
correlation of sampled PC addresses with their disassembled machine code, as
|
||||
well as source code and symbolic debugging information if available.
|
||||
|
||||
See [PC-Sampler README](pcsampler/code_printing_sample/README.md)
|
||||
@@ -0,0 +1 @@
|
||||
att: TARGET_CU=1
|
||||
@@ -0,0 +1,305 @@
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <rocprofiler/v2/rocprofiler.h>
|
||||
|
||||
#include <cxxabi.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
// Custom assert to print error messages
|
||||
#define ASSERTM(exp, msg) assert(((void)msg, exp))
|
||||
|
||||
// Macro to check HIP calls status
|
||||
#define HIP_CALL(call) \
|
||||
do { \
|
||||
hipError_t err = call; \
|
||||
if (err != hipSuccess) { \
|
||||
fprintf(stderr, "%s\n", hipGetErrorString(err)); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Macro to check ROCPROFILER calls status
|
||||
#define CHECK_ROCPROFILER(call) \
|
||||
do { \
|
||||
if ((call) != ROCPROFILER_STATUS_SUCCESS) \
|
||||
rocprofiler::fatal("Error: ROCProfiler API Call Error!"); \
|
||||
} while (false)
|
||||
|
||||
// Device (Kernel) functions, it must be void
|
||||
__global__ void kernelA() { printf("\nKernel A\n"); }
|
||||
__global__ void kernelB() { printf("\nKernel B\n"); }
|
||||
__global__ void kernelC() { printf("\nKernel C\n"); }
|
||||
__global__ void kernelD() { printf("\nKernel D\n"); }
|
||||
__global__ void kernelE() { printf("\nKernel E\n"); }
|
||||
__global__ void kernelF() { printf("\nKernel F\n"); }
|
||||
|
||||
[[maybe_unused]] uint32_t GetPid() {
|
||||
static uint32_t pid = syscall(__NR_getpid);
|
||||
return pid;
|
||||
}
|
||||
|
||||
[[maybe_unused]] uint64_t GetMachineID() { return gethostid(); }
|
||||
|
||||
std::ofstream output_file;
|
||||
|
||||
void prepare() {
|
||||
output_file.copyfmt(std::cout);
|
||||
output_file.clear(std::cout.rdstate());
|
||||
output_file.basic_ios<char>::rdbuf(std::cout.rdbuf());
|
||||
}
|
||||
|
||||
std::mutex writing_lock;
|
||||
|
||||
const char* GetDomainName(rocprofiler_tracer_activity_domain_t domain) {
|
||||
switch (domain) {
|
||||
case ACTIVITY_DOMAIN_ROCTX:
|
||||
return "ROCTX_DOMAIN";
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HIP_API:
|
||||
return "HIP_API_DOMAIN";
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HIP_OPS:
|
||||
return "HIP_OPS_DOMAIN";
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_API:
|
||||
return "HSA_API_DOMAIN";
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_OPS:
|
||||
return "HSA_OPS_DOMAIN";
|
||||
break;
|
||||
case ACTIVITY_DOMAIN_HSA_EVT:
|
||||
return "HSA_EVT_DOMAIN";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Flush function needs to be provided by the user to be used in three cases by
|
||||
// the user buffer:
|
||||
// 1- Application is finished
|
||||
// 2- Buffer is full
|
||||
// 3- Flush Interval specified by the user
|
||||
void FlushTracerRecord(rocprofiler_record_tracer_t tracer_record,
|
||||
rocprofiler_session_id_t session_id,
|
||||
rocprofiler_buffer_id_t buffer_id = rocprofiler_buffer_id_t{0}) {
|
||||
std::lock_guard<std::mutex> lock(writing_lock);
|
||||
std::string function_name;
|
||||
|
||||
if (tracer_record.domain == ACTIVITY_DOMAIN_HSA_API || ACTIVITY_DOMAIN_HIP_API) {
|
||||
const char* function_name_c = nullptr;
|
||||
CHECK_ROCPROFILER(rocprofiler_query_tracer_operation_name(
|
||||
tracer_record.domain, tracer_record.operation_id, &function_name_c));
|
||||
function_name = function_name_c ? function_name_c : "";
|
||||
}
|
||||
|
||||
output_file << "Record [" << tracer_record.header.id.handle << "], Domain("
|
||||
<< GetDomainName(tracer_record.domain);
|
||||
if (tracer_record.phase == ROCPROFILER_PHASE_ENTER) {
|
||||
rocprofiler_timestamp_t timestamp;
|
||||
rocprofiler_get_timestamp(×tamp);
|
||||
output_file << "), Begin(" << timestamp.value;
|
||||
} else if (tracer_record.phase == ROCPROFILER_PHASE_EXIT) {
|
||||
rocprofiler_timestamp_t timestamp;
|
||||
rocprofiler_get_timestamp(×tamp);
|
||||
output_file << "), End(" << timestamp.value;
|
||||
} else {
|
||||
output_file << "), Begin(" << tracer_record.timestamps.begin.value << "), End("
|
||||
<< tracer_record.timestamps.end.value;
|
||||
}
|
||||
output_file << "), Correlation ID(" << tracer_record.correlation_id.value << ")";
|
||||
if (tracer_record.domain == ACTIVITY_DOMAIN_ROCTX && tracer_record.operation_id.id >= 0)
|
||||
output_file << ", ROCTX ID(" << tracer_record.operation_id.id << ")";
|
||||
if (tracer_record.domain == ACTIVITY_DOMAIN_ROCTX && tracer_record.name)
|
||||
output_file << ", ROCTX Message(" << tracer_record.name << ")";
|
||||
if (function_name.size() > 1) output_file << ", Function(" << function_name << ")";
|
||||
if (tracer_record.domain == ACTIVITY_DOMAIN_HIP_OPS && tracer_record.name)
|
||||
output_file << ", Kernel Name(" << rocprofiler::cxx_demangle(tracer_record.name) << ")";
|
||||
output_file << std::endl;
|
||||
}
|
||||
|
||||
void FlushProfilerRecord(const rocprofiler_record_profiler_t* profiler_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
std::lock_guard<std::mutex> lock(writing_lock);
|
||||
size_t name_length = 0;
|
||||
CHECK_ROCPROFILER(rocprofiler_query_kernel_info_size(ROCPROFILER_KERNEL_NAME,
|
||||
profiler_record->kernel_id, &name_length));
|
||||
// Taken from rocprofiler: The size hasn't changed in recent past
|
||||
static const uint32_t lds_block_size = 128 * 4;
|
||||
const char* kernel_name_c = "";
|
||||
if (name_length > 1) {
|
||||
kernel_name_c = static_cast<const char*>(malloc(name_length * sizeof(char)));
|
||||
CHECK_ROCPROFILER(rocprofiler_query_kernel_info(ROCPROFILER_KERNEL_NAME,
|
||||
profiler_record->kernel_id, &kernel_name_c));
|
||||
}
|
||||
output_file << std::string("dispatch[") << std::to_string(profiler_record->header.id.handle)
|
||||
<< "], " << std::string("gpu_id(") << std::to_string(profiler_record->gpu_id.handle)
|
||||
<< "), " << std::string("queue_id(")
|
||||
<< std::to_string(profiler_record->queue_id.handle) << "), "
|
||||
<< std::string("queue_index(") << std::to_string(profiler_record->queue_idx.value)
|
||||
<< "), " << std::string("pid(") << std::to_string(GetPid()) << "), "
|
||||
<< std::string("tid(") << std::to_string(profiler_record->thread_id.value) << ")";
|
||||
output_file << ", " << std::string("grd(")
|
||||
<< std::to_string(profiler_record->kernel_properties.grid_size) << "), "
|
||||
<< std::string("wgr(")
|
||||
<< std::to_string(profiler_record->kernel_properties.workgroup_size) << "), "
|
||||
<< std::string("lds(")
|
||||
<< std::to_string(
|
||||
((profiler_record->kernel_properties.lds_size + (lds_block_size - 1)) &
|
||||
~(lds_block_size - 1)))
|
||||
<< "), " << std::string("scr(")
|
||||
<< std::to_string(profiler_record->kernel_properties.scratch_size) << "), "
|
||||
<< std::string("arch_vgpr(")
|
||||
<< std::to_string(profiler_record->kernel_properties.arch_vgpr_count) << "), "
|
||||
<< std::string("accum_vgpr(")
|
||||
<< std::to_string(profiler_record->kernel_properties.accum_vgpr_count) << "), "
|
||||
<< std::string("sgpr(")
|
||||
<< std::to_string(profiler_record->kernel_properties.sgpr_count) << "), "
|
||||
<< std::string("wave_size(")
|
||||
<< std::to_string(profiler_record->kernel_properties.wave_size) << "), "
|
||||
<< std::string("sig(")
|
||||
<< std::to_string(profiler_record->kernel_properties.signal_handle);
|
||||
std::string kernel_name = rocprofiler::cxx_demangle(kernel_name_c);
|
||||
output_file << "), " << std::string("obj(") << std::to_string(profiler_record->kernel_id.handle)
|
||||
<< "), " << std::string("kernel-name(\"") << kernel_name << "\")"
|
||||
<< std::string(", time(") << std::to_string(profiler_record->timestamps.begin.value)
|
||||
<< ") ";
|
||||
|
||||
// For Counters
|
||||
output_file << std::endl;
|
||||
if (profiler_record->counters) {
|
||||
for (uint64_t i = 0; i < profiler_record->counters_count.value; i++) {
|
||||
if (profiler_record->counters[i].counter_handler.handle > 0) {
|
||||
size_t counter_name_length = 0;
|
||||
CHECK_ROCPROFILER(rocprofiler_query_counter_info_size(
|
||||
session_id, ROCPROFILER_COUNTER_NAME, profiler_record->counters[i].counter_handler,
|
||||
&counter_name_length));
|
||||
if (counter_name_length > 1) {
|
||||
const char* name_c = static_cast<const char*>(malloc(name_length * sizeof(char)));
|
||||
CHECK_ROCPROFILER(rocprofiler_query_counter_info(
|
||||
session_id, ROCPROFILER_COUNTER_NAME, profiler_record->counters[i].counter_handler,
|
||||
&name_c));
|
||||
output_file << ", " << name_c << " ("
|
||||
<< std::to_string(profiler_record->counters[i].value.value) << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FlushPCSamplingRecord(const rocprofiler_record_pc_sample_t* pc_sampling_record) {
|
||||
const auto& sample = pc_sampling_record->pc_sample;
|
||||
output_file << "dispatch[" << sample.dispatch_id.value << "], "
|
||||
<< "timestamp(" << sample.timestamp.value << "), "
|
||||
<< "gpu_id(" << sample.gpu_id.handle << "), "
|
||||
<< "pc-sample(" << std::hex << std::showbase << sample.pc << "), "
|
||||
<< "se(" << sample.se << ')' << std::endl;
|
||||
}
|
||||
|
||||
void FlushCountersSamplerRecord(
|
||||
const rocprofiler_record_counters_sampler_t* counters_sampler_record) {
|
||||
for (uint32_t i = 0; i < counters_sampler_record->num_counters; i++) {
|
||||
output_file << ",Counter_" << i << "("
|
||||
<< std::to_string(counters_sampler_record->counters[i].value.value) << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
output_file << std::endl;
|
||||
}
|
||||
|
||||
int WriteBufferRecords(const rocprofiler_record_header_t* begin,
|
||||
const rocprofiler_record_header_t* end, rocprofiler_session_id_t session_id,
|
||||
rocprofiler_buffer_id_t buffer_id) {
|
||||
while (begin < end) {
|
||||
if (!begin) return 0;
|
||||
switch (begin->kind) {
|
||||
case ROCPROFILER_PROFILER_RECORD: {
|
||||
const rocprofiler_record_profiler_t* profiler_record =
|
||||
reinterpret_cast<const rocprofiler_record_profiler_t*>(begin);
|
||||
FlushProfilerRecord(profiler_record, session_id, buffer_id);
|
||||
break;
|
||||
}
|
||||
case ROCPROFILER_TRACER_RECORD: {
|
||||
rocprofiler_record_tracer_t* tracer_record = const_cast<rocprofiler_record_tracer_t*>(
|
||||
reinterpret_cast<const rocprofiler_record_tracer_t*>(begin));
|
||||
FlushTracerRecord(*tracer_record, session_id, buffer_id);
|
||||
break;
|
||||
}
|
||||
case ROCPROFILER_PC_SAMPLING_RECORD: {
|
||||
[[deprecated("PC Sampling is deprecated")]]
|
||||
const rocprofiler_record_pc_sample_t* pc_sampling_record =
|
||||
reinterpret_cast<const rocprofiler_record_pc_sample_t*>(begin);
|
||||
FlushPCSamplingRecord(pc_sampling_record);
|
||||
break;
|
||||
}
|
||||
case ROCPROFILER_COUNTERS_SAMPLER_RECORD: {
|
||||
const rocprofiler_record_counters_sampler_t* counters_sampler_record =
|
||||
reinterpret_cast<const rocprofiler_record_counters_sampler_t*>(begin);
|
||||
FlushCountersSamplerRecord(counters_sampler_record);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
std::cout << "unknown record\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
rocprofiler_next_record(begin, &begin, session_id, buffer_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kernelCalls(char c) {
|
||||
switch (c) {
|
||||
case 'A': {
|
||||
hipLaunchKernelGGL(kernelA, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
case 'B': {
|
||||
hipLaunchKernelGGL(kernelB, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
case 'C': {
|
||||
hipLaunchKernelGGL(kernelC, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
case 'D': {
|
||||
hipLaunchKernelGGL(kernelD, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
case 'E': {
|
||||
hipLaunchKernelGGL(kernelE, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
case 'F': {
|
||||
hipLaunchKernelGGL(kernelF, dim3(1), dim3(1), 0, 0);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
fprintf(stderr, "Error: Wrong Kernel character (%c) Given for kernelCalls!\n", c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE. */
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <amd_comgr/amd_comgr.h>
|
||||
|
||||
#define amd_comgr_(call) \
|
||||
do { \
|
||||
if (amd_comgr_status_t status = amd_comgr_##call; status != AMD_COMGR_STATUS_SUCCESS) { \
|
||||
const char* reason = ""; \
|
||||
amd_comgr_status_string(status, &reason); \
|
||||
fatal(#call " failed: %s", reason); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
namespace rocprofiler {
|
||||
|
||||
std::string string_vprintf(const char* format, va_list va) {
|
||||
va_list copy;
|
||||
|
||||
va_copy(copy, va);
|
||||
size_t size = vsnprintf(NULL, 0, format, copy);
|
||||
va_end(copy);
|
||||
|
||||
std::string str(size, '\0');
|
||||
vsprintf(&str[0], format, va);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string string_printf(const char* format, ...) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
std::string str(string_vprintf(format, va));
|
||||
va_end(va);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
[[maybe_unused]] void warning(const char* format, ...) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vfprintf(stderr, format, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
[[maybe_unused]] void fatal [[noreturn]] (const char* format, ...) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
std::string message = string_vprintf(format, va);
|
||||
va_end(va);
|
||||
|
||||
#if defined(ENABLE_BACKTRACE)
|
||||
BackTraceInfo info;
|
||||
|
||||
info.sstream << std::endl << "Backtrace:";
|
||||
info.state = ::backtrace_create_state("/proc/self/exe", 0, errorCallback, &info);
|
||||
::backtrace_full(info.state, 1, fullCallback, errorCallback, &info);
|
||||
|
||||
message += info.sstream.str();
|
||||
#endif /* defined (ENABLE_BACKTRACE) */
|
||||
|
||||
std::string errmsg("ROCProfiler: fatal error: " + message);
|
||||
fputs(errmsg.c_str(), stderr);
|
||||
|
||||
// throw(errmsg);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* The function extracts the kernel name from
|
||||
input string. By using the iterators it finds the
|
||||
window in the string which contains only the kernel name.
|
||||
For example 'Foo<int, float>::foo(a[], int (int))' -> 'foo'*/
|
||||
std::string truncate_name(const std::string& name) {
|
||||
auto rit = name.rbegin();
|
||||
auto rend = name.rend();
|
||||
uint32_t counter = 0;
|
||||
char open_token = 0;
|
||||
char close_token = 0;
|
||||
while (rit != rend) {
|
||||
if (counter == 0) {
|
||||
switch (*rit) {
|
||||
case ')':
|
||||
counter = 1;
|
||||
open_token = ')';
|
||||
close_token = '(';
|
||||
break;
|
||||
case '>':
|
||||
counter = 1;
|
||||
open_token = '>';
|
||||
close_token = '<';
|
||||
break;
|
||||
case ']':
|
||||
counter = 1;
|
||||
open_token = ']';
|
||||
close_token = '[';
|
||||
break;
|
||||
case ' ':
|
||||
++rit;
|
||||
continue;
|
||||
}
|
||||
if (counter == 0) break;
|
||||
} else {
|
||||
if (*rit == open_token) counter++;
|
||||
if (*rit == close_token) counter--;
|
||||
}
|
||||
++rit;
|
||||
}
|
||||
auto rbeg = rit;
|
||||
while ((rit != rend) && (*rit != ' ') && (*rit != ':')) rit++;
|
||||
return name.substr(rend - rit, rit - rbeg);
|
||||
}
|
||||
|
||||
// C++ symbol demangle
|
||||
std::string cxx_demangle(const std::string& symbol) {
|
||||
amd_comgr_data_t mangled_data;
|
||||
amd_comgr_(create_data(AMD_COMGR_DATA_KIND_BYTES, &mangled_data));
|
||||
amd_comgr_(set_data(mangled_data, symbol.size(), symbol.data()));
|
||||
|
||||
amd_comgr_data_t demangled_data;
|
||||
amd_comgr_(demangle_symbol_name(mangled_data, &demangled_data));
|
||||
|
||||
size_t demangled_size = 0;
|
||||
amd_comgr_(get_data(demangled_data, &demangled_size, nullptr));
|
||||
|
||||
std::string demangled_str;
|
||||
demangled_str.resize(demangled_size);
|
||||
// amd_comgr_(get_data(demangled_data, &demangled_size, demangled_str.data())); // TODO: uncomment
|
||||
|
||||
amd_comgr_(release_data(mangled_data));
|
||||
amd_comgr_(release_data(demangled_data));
|
||||
return demangled_str;
|
||||
}
|
||||
|
||||
// check if string has special char
|
||||
bool has_special_char(std::string const& str) {
|
||||
return std::find_if(str.begin(), str.end(), [](unsigned char ch) {
|
||||
return !(isalnum(ch) || ch == '_' || ch == ':' || ch == ' ');
|
||||
}) != str.end();
|
||||
}
|
||||
|
||||
// check if string has correct counter format
|
||||
bool has_counter_format(std::string const& str) {
|
||||
return std::find_if(str.begin(), str.end(), [](unsigned char ch) {
|
||||
return (isalnum(ch) || ch == '_' || ch != ':');
|
||||
}) != str.end();
|
||||
}
|
||||
|
||||
// trims the begining of the line for spaces
|
||||
std::string left_trim(const std::string& s) {
|
||||
const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = s.find_first_not_of(WHITESPACE);
|
||||
return (start == std::string::npos) ? "" : s.substr(start);
|
||||
}
|
||||
|
||||
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cxxabi.h>
|
||||
// #include "exception.h"
|
||||
|
||||
namespace rocprofiler {
|
||||
|
||||
std::string string_vprintf(const char* format, va_list va);
|
||||
|
||||
std::string string_printf(const char* format, ...);
|
||||
|
||||
[[maybe_unused]] void warning(const char* format, ...)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((format(printf, 1, 2)))
|
||||
#endif /* defined (__GNUC__) */
|
||||
;
|
||||
[[maybe_unused]] void fatal [[noreturn]] (const char* format, ...)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((format(printf, 1, 2)))
|
||||
#endif /* defined (__GNUC__) */
|
||||
;
|
||||
|
||||
[[maybe_unused]] void warning(const char* format, ...);
|
||||
|
||||
[[maybe_unused]] void fatal [[noreturn]] (const char* format, ...);
|
||||
|
||||
/* The function extracts the kernel name from
|
||||
input string. By using the iterators it finds the
|
||||
window in the string which contains only the kernel name.
|
||||
For example 'Foo<int, float>::foo(a[], int (int))' -> 'foo'*/
|
||||
std::string truncate_name(const std::string& name);
|
||||
|
||||
// C++ symbol demangle
|
||||
std::string cxx_demangle(const std::string& symbol);
|
||||
|
||||
// check if string has special char
|
||||
bool has_special_char(std::string const& str);
|
||||
|
||||
// check if string has correct counter format
|
||||
bool has_counter_format(std::string const& str);
|
||||
|
||||
// trims the begining of the line for spaces
|
||||
std::string left_trim(const std::string& s);
|
||||
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int* gpuMem;
|
||||
int counter_option = 0;
|
||||
|
||||
std::vector<std::string> pcie_counters = {
|
||||
"CI_PERF_slv_MemRd_Bandwidth0", "CI_PERF_slv_MemWr_Bandwidth0", "CI_PERF_slv_totalMemRdTx",
|
||||
"CI_PERF_slv_totalMemWrTx", "CI_PERF_slv_totalTx"};
|
||||
|
||||
if (argc > 1) {
|
||||
counter_option = atoi(argv[1]);
|
||||
} else {
|
||||
std::cout << "Please provide one of the counter index options as argument:\n";
|
||||
for (int i = 0; i < pcie_counters.size(); i++) {
|
||||
std::cout << "[" << i << "]: " << pcie_counters[i] << std::endl;
|
||||
}
|
||||
std::cout << "Example:\n ./pcie_counters_sampler 1\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
prepare();
|
||||
// Initialize the tools
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
|
||||
// Creating the session with given replay mode
|
||||
rocprofiler_session_id_t session_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_session(ROCPROFILER_NONE_REPLAY_MODE, &session_id));
|
||||
|
||||
// Creating Output Buffer for the data
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_buffer(
|
||||
session_id,
|
||||
[](const rocprofiler_record_header_t* record, const rocprofiler_record_header_t* end_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
WriteBufferRecords(record, end_record, session_id, buffer_id);
|
||||
},
|
||||
0x999999, &buffer_id));
|
||||
|
||||
// Counters Sampler Filter
|
||||
rocprofiler_filter_id_t filter_id;
|
||||
[[maybe_unused]] rocprofiler_filter_property_t property = {};
|
||||
|
||||
|
||||
rocprofiler_counters_sampler_counter_input_t counters_input[2] = {
|
||||
{.name = const_cast<char*>(pcie_counters[counter_option].c_str()),
|
||||
.type = ROCPROFILER_COUNTERS_SAMPLER_PCIE_COUNTERS}};
|
||||
|
||||
uint32_t rate = 1000;
|
||||
uint32_t duration = 5000;
|
||||
|
||||
rocprofiler_counters_sampler_parameters_t cs_parameters = {.counters = counters_input,
|
||||
.counters_num = 1,
|
||||
.sampling_rate = rate,
|
||||
.sampling_duration = duration,
|
||||
.gpu_agent_index = 0};
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_COUNTERS_SAMPLER,
|
||||
rocprofiler_filter_data_t{.counters_sampler_parameters = cs_parameters}, 0, &filter_id,
|
||||
property));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, filter_id, buffer_id));
|
||||
|
||||
// Normal HIP Calls
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMem, 1 * sizeof(int)));
|
||||
|
||||
// KernelA and KernelB won't be profiled
|
||||
kernelCalls('A');
|
||||
kernelCalls('B');
|
||||
|
||||
std::cout << "Collecting samples for: " << pcie_counters[counter_option]
|
||||
<< " ; sampling rate: " << rate << " ms; duration: " << duration << " ms" << std::endl;
|
||||
// Activating the session
|
||||
CHECK_ROCPROFILER(rocprofiler_start_session(session_id));
|
||||
|
||||
// KernelC, KernelD, KernelE and KernelF to be profiled as part of the session
|
||||
kernelCalls('C');
|
||||
kernelCalls('D');
|
||||
kernelCalls('E');
|
||||
kernelCalls('F');
|
||||
// Normal HIP Calls
|
||||
HIP_CALL(hipFree(gpuMem));
|
||||
|
||||
// allow sampler to run for 10 secs
|
||||
sleep(6);
|
||||
|
||||
// Deactivating session
|
||||
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
|
||||
|
||||
// Manual Flush user buffer request
|
||||
CHECK_ROCPROFILER(rocprofiler_flush_data(session_id, buffer_id));
|
||||
|
||||
// Destroy sessions
|
||||
CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
|
||||
|
||||
// Destroy all profiling related objects(User buffer, sessions, filters,
|
||||
// etc..)
|
||||
CHECK_ROCPROFILER(rocprofiler_finalize());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int* gpuMem;
|
||||
int counter_option = 0;
|
||||
if (argc > 1) counter_option = atoi(argv[1]);
|
||||
|
||||
prepare();
|
||||
// Initialize the tools
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
|
||||
// Creating the session with given replay mode
|
||||
rocprofiler_session_id_t session_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_session(ROCPROFILER_NONE_REPLAY_MODE, &session_id));
|
||||
|
||||
// Creating Output Buffer for the data
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_buffer(
|
||||
session_id,
|
||||
[](const rocprofiler_record_header_t* record, const rocprofiler_record_header_t* end_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
WriteBufferRecords(record, end_record, session_id, buffer_id);
|
||||
},
|
||||
0x999999, &buffer_id));
|
||||
|
||||
// Counters Sampler Filter
|
||||
rocprofiler_filter_id_t filter_id;
|
||||
[[maybe_unused]] rocprofiler_filter_property_t property = {};
|
||||
|
||||
std::vector<std::string> xgmi_counters = {"xgmi_link0_data_outbound", "xgmi_link1_data_outbound",
|
||||
"xgmi_link2_data_outbound", "xgmi_link3_data_outbound",
|
||||
"xgmi_link4_data_outbound", "xgmi_link5_data_outbound",
|
||||
"xgmi_link5_data_outbound", "xgmi_link6_data_outbound"};
|
||||
|
||||
rocprofiler_counters_sampler_counter_input_t counters_input[2] = {
|
||||
{.name = const_cast<char*>(xgmi_counters[counter_option].c_str()),
|
||||
.type = ROCPROFILER_COUNTERS_SAMPLER_XGMI_COUNTERS}};
|
||||
|
||||
uint32_t rate = 1000;
|
||||
uint32_t duration = 5000;
|
||||
|
||||
rocprofiler_counters_sampler_parameters_t cs_parameters = {.counters = counters_input,
|
||||
.counters_num = 1,
|
||||
.sampling_rate = rate,
|
||||
.sampling_duration = duration,
|
||||
.gpu_agent_index = 0};
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_COUNTERS_SAMPLER,
|
||||
rocprofiler_filter_data_t{.counters_sampler_parameters = cs_parameters}, 0, &filter_id,
|
||||
property));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, filter_id, buffer_id));
|
||||
|
||||
// Normal HIP Calls
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMem, 1 * sizeof(int)));
|
||||
|
||||
// KernelA and KernelB won't be profiled
|
||||
kernelCalls('A');
|
||||
kernelCalls('B');
|
||||
|
||||
std::cout << "Collecting samples for: " << xgmi_counters[counter_option]
|
||||
<< " ; sampling rate: " << rate << " ms; duration: " << duration << " ms" << std::endl;
|
||||
// Activating the session
|
||||
CHECK_ROCPROFILER(rocprofiler_start_session(session_id));
|
||||
|
||||
// KernelC, KernelD, KernelE and KernelF to be profiled as part of the session
|
||||
kernelCalls('C');
|
||||
kernelCalls('D');
|
||||
kernelCalls('E');
|
||||
kernelCalls('F');
|
||||
// Normal HIP Calls
|
||||
HIP_CALL(hipFree(gpuMem));
|
||||
|
||||
// allow sampler to run for 10 secs
|
||||
sleep(6);
|
||||
|
||||
// Deactivating session
|
||||
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
|
||||
|
||||
// Manual Flush user buffer request
|
||||
CHECK_ROCPROFILER(rocprofiler_flush_data(session_id, buffer_id));
|
||||
|
||||
// Destroy sessions
|
||||
CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
|
||||
|
||||
// Destroy all profiling related objects(User buffer, sessions, filters,
|
||||
// etc..)
|
||||
CHECK_ROCPROFILER(rocprofiler_finalize());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pmc: SQ_WAVES GRBM_COUNT GRBM_GUI_ACTIVE SQ_INSTS_VALU FETCH_SIZE
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "../common/common.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#include <rocprofiler/v2/rocprofiler.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int poll_duration = 5;
|
||||
if (argc > 1) poll_duration = atoi(argv[1]);
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
printf("initialize\n");
|
||||
|
||||
rocprofiler_session_id_t dp_session_id;
|
||||
std::vector<const char*> counters;
|
||||
counters.emplace_back("GRBM_COUNT");
|
||||
|
||||
printf("session create\n");
|
||||
|
||||
int gpu_agent = 0;
|
||||
int cpu_agent = 0;
|
||||
CHECK_ROCPROFILER(rocprofiler_device_profiling_session_create(
|
||||
&counters[0], counters.size(), &dp_session_id, cpu_agent, gpu_agent));
|
||||
|
||||
printf("session start \n");
|
||||
// start GPU device profiling
|
||||
CHECK_ROCPROFILER(rocprofiler_device_profiling_session_start(dp_session_id));
|
||||
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
auto t1 = high_resolution_clock::now();
|
||||
|
||||
do {
|
||||
printf("polling\n");
|
||||
std::vector<rocprofiler_device_profile_metric_t> data(counters.size());
|
||||
// Poll metrics
|
||||
CHECK_ROCPROFILER(rocprofiler_device_profiling_session_poll(dp_session_id, &data[0]));
|
||||
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
std::cout << data[i].metric_name << ": " << data[i].value.value << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
// break;
|
||||
} while (--poll_duration > 0);
|
||||
|
||||
auto t2 = high_resolution_clock::now();
|
||||
/* Getting number of milliseconds as an integer. */
|
||||
auto ms_int = duration_cast<milliseconds>(t2 - t1);
|
||||
|
||||
std::cout << ms_int.count() << "ms\n";
|
||||
|
||||
// Stop session
|
||||
CHECK_ROCPROFILER(rocprofiler_device_profiling_session_stop(dp_session_id));
|
||||
|
||||
// Destroy session
|
||||
CHECK_ROCPROFILER(rocprofiler_device_profiling_session_destroy(dp_session_id));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int* gpuMem;
|
||||
prepare();
|
||||
// Initialize the tools
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
|
||||
// Creating the session with given replay mode
|
||||
rocprofiler_session_id_t session_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_session(ROCPROFILER_NONE_REPLAY_MODE, &session_id));
|
||||
|
||||
// Creating Output Buffer for the data
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_buffer(
|
||||
session_id,
|
||||
[](const rocprofiler_record_header_t* record, const rocprofiler_record_header_t* end_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
WriteBufferRecords(record, end_record, session_id, buffer_id);
|
||||
},
|
||||
0x9999, &buffer_id));
|
||||
|
||||
// Counter Collection Filter
|
||||
std::vector<const char*> counters;
|
||||
counters.emplace_back("GRBM_COUNT");
|
||||
rocprofiler_filter_id_t filter_id;
|
||||
[[maybe_unused]] rocprofiler_filter_property_t property = {};
|
||||
CHECK_ROCPROFILER(
|
||||
rocprofiler_create_filter(session_id, ROCPROFILER_COUNTERS_COLLECTION,
|
||||
rocprofiler_filter_data_t{.counters_names = &counters[0]},
|
||||
counters.size(), &filter_id, property));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, filter_id, buffer_id));
|
||||
|
||||
// Normal HIP Calls
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMem, 1 * sizeof(int)));
|
||||
|
||||
// KernelA and KernelB won't be profiled
|
||||
kernelCalls('A');
|
||||
kernelCalls('B');
|
||||
|
||||
// Activating Profiling Session to profile whatever kernel launches occurs up
|
||||
// till the next terminate session
|
||||
CHECK_ROCPROFILER(rocprofiler_start_session(session_id));
|
||||
|
||||
// KernelC, KernelD, KernelE and KernelF to be profiled as part of the session
|
||||
kernelCalls('C');
|
||||
kernelCalls('D');
|
||||
kernelCalls('E');
|
||||
kernelCalls('F');
|
||||
// Normal HIP Calls
|
||||
HIP_CALL(hipFree(gpuMem));
|
||||
|
||||
// Deactivating session
|
||||
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
|
||||
|
||||
// Manual Flush user buffer request
|
||||
CHECK_ROCPROFILER(rocprofiler_flush_data(session_id, buffer_id));
|
||||
|
||||
// Destroy sessions
|
||||
CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
|
||||
|
||||
// Destroy all profiling related objects(User buffer, sessions, filters,
|
||||
// etc..)
|
||||
CHECK_ROCPROFILER(rocprofiler_finalize());
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
CURRENT_DIR=$(dirname -- $(realpath ${BASH_SOURCE[0]}));
|
||||
ROCM_PATH="${ROCM_PATH:=/opt/rocm}"
|
||||
|
||||
|
||||
echo -e "Running Samples"
|
||||
|
||||
export ROCPROFILER_METRICS_PATH=${ROCM_PATH}/libexec/rocprofiler/counters/derived_counters.xml
|
||||
|
||||
echo -e "\tProfiler Samples:"
|
||||
|
||||
echo -e "\t\tKernel Replay Sample:"
|
||||
eval ${CURRENT_DIR}/profiler_kernel_replay
|
||||
|
||||
|
||||
echo -e "\t\tDevice Profiling Sample:"
|
||||
eval ${CURRENT_DIR}/profiler_device_profiling
|
||||
|
||||
|
||||
echo -e "\tTracer Samples:"
|
||||
|
||||
echo -e "\t\tHIP/HSA Trace Synchronous Sample:"
|
||||
eval ${CURRENT_DIR}/tracer_hip_hsa
|
||||
|
||||
echo -e "\t\tHIP/HSA Trace ASynchronous Sample:"
|
||||
eval ${CURRENT_DIR}/tracer_hip_hsa_async
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int* gpuMem;
|
||||
prepare();
|
||||
// Initialize the tools
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
|
||||
// Creating the session with given replay mode
|
||||
rocprofiler_session_id_t session_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_session(ROCPROFILER_NONE_REPLAY_MODE, &session_id));
|
||||
|
||||
// Creating Output Buffer for the data
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_buffer(
|
||||
session_id,
|
||||
[](const rocprofiler_record_header_t* record, const rocprofiler_record_header_t* end_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
WriteBufferRecords(record, end_record, session_id, buffer_id);
|
||||
},
|
||||
0x9999, &buffer_id));
|
||||
|
||||
// Tracing Filter
|
||||
std::vector<rocprofiler_tracer_activity_domain_t> apis_requested;
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HIP_API);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HIP_OPS);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HSA_API);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HSA_OPS);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_ROCTX);
|
||||
rocprofiler_filter_id_t api_tracing_filter_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_API_TRACE, rocprofiler_filter_data_t{&apis_requested[0]},
|
||||
apis_requested.size(), &api_tracing_filter_id, rocprofiler_filter_property_t{}));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, api_tracing_filter_id, buffer_id));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_api_trace_sync_callback(
|
||||
session_id, api_tracing_filter_id,
|
||||
[](rocprofiler_record_tracer_t record, rocprofiler_session_id_t session_id) {
|
||||
FlushTracerRecord(record, session_id);
|
||||
}));
|
||||
|
||||
// Kernel Tracing
|
||||
rocprofiler_filter_id_t kernel_tracing_filter_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_DISPATCH_TIMESTAMPS_COLLECTION, rocprofiler_filter_data_t{}, 0,
|
||||
&kernel_tracing_filter_id, rocprofiler_filter_property_t{}));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, kernel_tracing_filter_id, buffer_id));
|
||||
|
||||
// Normal HIP Calls won't be traced
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMem, 1 * sizeof(int)));
|
||||
// KernelA and KernelB won't be traced
|
||||
kernelCalls('A');
|
||||
kernelCalls('B');
|
||||
|
||||
// Activating Profiling Session to profile whatever kernel launches occurs up
|
||||
// till the next terminate session
|
||||
CHECK_ROCPROFILER(rocprofiler_start_session(session_id));
|
||||
|
||||
// KernelC, KernelD, KernelE and KernelF to be traced as part of the session
|
||||
kernelCalls('C');
|
||||
kernelCalls('D');
|
||||
kernelCalls('E');
|
||||
kernelCalls('F');
|
||||
// Normal HIP Calls that will be traced
|
||||
HIP_CALL(hipFree(gpuMem));
|
||||
|
||||
// Deactivating session
|
||||
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
|
||||
|
||||
// Manual Flush user buffer request
|
||||
CHECK_ROCPROFILER(rocprofiler_flush_data(session_id, buffer_id));
|
||||
|
||||
// Destroy sessions
|
||||
CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
|
||||
|
||||
// Destroy all profiling related objects(User buffer, sessions, filters,
|
||||
// etc..)
|
||||
CHECK_ROCPROFILER(rocprofiler_finalize());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int* gpuMem;
|
||||
prepare();
|
||||
// Initialize the tools
|
||||
CHECK_ROCPROFILER(rocprofiler_initialize());
|
||||
|
||||
// Creating the session with given replay mode
|
||||
rocprofiler_session_id_t session_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_session(ROCPROFILER_NONE_REPLAY_MODE, &session_id));
|
||||
|
||||
// Creating Output Buffer for the data
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_buffer(
|
||||
session_id,
|
||||
[](const rocprofiler_record_header_t* record, const rocprofiler_record_header_t* end_record,
|
||||
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
|
||||
WriteBufferRecords(record, end_record, session_id, buffer_id);
|
||||
},
|
||||
0x9999, &buffer_id));
|
||||
|
||||
// Tracing Filter
|
||||
std::vector<rocprofiler_tracer_activity_domain_t> apis_requested;
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HIP_API);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HIP_OPS);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HSA_API);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_HSA_OPS);
|
||||
apis_requested.emplace_back(ACTIVITY_DOMAIN_ROCTX);
|
||||
rocprofiler_filter_id_t api_tracing_filter_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_API_TRACE, rocprofiler_filter_data_t{&apis_requested[0]},
|
||||
apis_requested.size(), &api_tracing_filter_id, rocprofiler_filter_property_t{}));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, api_tracing_filter_id, buffer_id));
|
||||
|
||||
// Kernel Tracing
|
||||
rocprofiler_filter_id_t kernel_tracing_filter_id;
|
||||
CHECK_ROCPROFILER(rocprofiler_create_filter(
|
||||
session_id, ROCPROFILER_DISPATCH_TIMESTAMPS_COLLECTION, rocprofiler_filter_data_t{}, 0,
|
||||
&kernel_tracing_filter_id, rocprofiler_filter_property_t{}));
|
||||
CHECK_ROCPROFILER(rocprofiler_set_filter_buffer(session_id, kernel_tracing_filter_id, buffer_id));
|
||||
|
||||
// Normal HIP Calls won't be traced
|
||||
hipDeviceProp_t devProp;
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMem, 1 * sizeof(int)));
|
||||
// KernelA and KernelB won't be traced
|
||||
kernelCalls('A');
|
||||
kernelCalls('B');
|
||||
|
||||
// Activating Profiling Session to profile whatever kernel launches occurs up
|
||||
// till the next terminate session
|
||||
CHECK_ROCPROFILER(rocprofiler_start_session(session_id));
|
||||
|
||||
// KernelC, KernelD, KernelE and KernelF to be traced as part of the session
|
||||
kernelCalls('C');
|
||||
kernelCalls('D');
|
||||
kernelCalls('E');
|
||||
kernelCalls('F');
|
||||
// Normal HIP Calls that will be traced
|
||||
HIP_CALL(hipFree(gpuMem));
|
||||
|
||||
// Deactivating session
|
||||
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
|
||||
|
||||
// Manual Flush user buffer request
|
||||
CHECK_ROCPROFILER(rocprofiler_flush_data(session_id, buffer_id));
|
||||
|
||||
// Destroy sessions
|
||||
CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
|
||||
|
||||
// Destroy all profiling related objects(User buffer, sessions, filters,
|
||||
// etc..)
|
||||
CHECK_ROCPROFILER(rocprofiler_finalize());
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user