Files
TheRock/rocm-systems/projects/rocprofiler-systems/examples/hpc/jacobi-hip/markers.h
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

145 lines
7.3 KiB
C++

/***************************************************************************
Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved.
***************************************************************************/
#ifndef MARKERS_H
#define MARKERS_H
#include <hip/hip_runtime.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#if defined(__HIP_PLATFORM_HCC__)
// begin HCC
# include <rocprofiler-sdk-roctx/roctx.h>
# define BEGIN_RANGE(name, group) \
do \
{ \
std::stringstream ss; \
ss << (name) << "::" << (group); \
std::string str = ss.str(); \
const char* cstr = str.c_str(); \
roctxRangePush(cstr); \
} while(0) // must terminate with semi-colon
# define END_RANGE() \
do \
{ \
if(roctxRangePop() < 0) \
{ \
std::stringstream ss; \
ss << "rocTX error popping range." << std::endl; \
std::string str = ss.str(); \
throw std::runtime_error(str); \
} \
} while(0)
// embed event recording in class to automatically pop when destroyed
class ScopedRange
{
public:
ScopedRange(const char* name, const char* group)
{
std::stringstream ss;
ss << (name) << "::" << (group);
std::string str = ss.str();
const char* cstr = str.c_str();
roctxRangePush(cstr);
}
~ScopedRange() { roctxRangePop(); }
};
# define SCOPED_RANGE(name, group) \
ScopedRange CONCAT(range, __COUNTER__)((name), (group))
# define MARKER(name, group) \
do \
{ \
std::stringstream ss; \
ss << (name) << "::" << (group); \
std::string str = ss.str(); \
const char* cstr = str.c_str(); \
roctxMark(cstr); \
} while(0) // must terminate with semi-colon
#else // __HIP_PLATFORM_NVCC__
// Begin CUDA
# include <cuda_profiler_api.h>
# include <nvToolsExt.h>
static inline void
initialize_logger()
{
if(cudaProfilerStart() != cudaSuccess)
throw std::runtime_error("CUDA profiler could not be initialized!");
}
static inline void
finalize_logger()
{
if(cudaProfilerStop() != cudaSuccess)
throw std::runtime_error("CUDA profiler could not be stopped!");
}
// start recording an event
# define BEGIN_RANGE(name, group) \
do \
{ \
std::stringstream ss; \
ss << name << "::" << group; \
std::string str = ss.str(); \
const char* cstr = str.c_str(); \
nvtxEventAttributes_t eventAttrib = { 0 }; \
eventAttrib.version = NVTX_VERSION; \
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \
eventAttrib.message.ascii = cstr; \
nvtxRangePushEx(&eventAttrib); \
} while(0) // must terminate with semi-colon
// stop recording an event
// must terminate with semi-colon
# define END_RANGE() \
do \
{ \
nvtxRangePop(); \
} while(0)
// embed event recording in class to automatically pop when destroyed
class ScopedRange
{
public:
ScopedRange(const char* name, const char* group) { BEGIN_RANGE(name, group); }
~ScopedRange() { END_RANGE(); }
};
// call RANGE at beginning of function to push event recording
// destructor is automatically called on return to pop event recording
// must terminate with semi-colon
# define SCOPED_RANGE(name, group) ScopedRange CONCAT(range, __COUNTER__)(name, group)
# define MARKER(name, group) \
do \
{ \
std::stringstream ss; \
ss << name << "::" << group; \
std::string str = ss.str(); \
const char* cstr = str.c_str(); \
nvtxEventAttributes_t eventAttrib = { 0 }; \
eventAttrib.version = NVTX_VERSION; \
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \
eventAttrib.message.ascii = cstr; \
nvtxMarkEx(&eventAttrib); \
} while(0) // must terminate with semi-colon
#endif // __HIP_PLATFORM_NVCC__
#endif // MARKERS_H