# Profiling HIP Code This section describes the tracing and debugging capabilities that HIP provides. - [Tracing and Debug](#tracing-and-debug) * [Tracing HIP APIs](#tracing-hip-apis) + [Color](#color) ## Tracing and Debug ### Tracing HIP APIs The HIP runtime can print the HIP function strings to stderr using HIP_TRACE_API environment variable. The trace prints two messages for each API - one at the beginning of the API call (line starts with "<<") and one at the end of the API call (line ends with ">>"). Here's an example for one API followed by a description for the sections of the trace: ``` <> ``` - `<> info: running on device gfx803 info: allocate host mem ( 7.63 MB) info: allocate device mem ( 7.63 MB) <> <> info: copy Host2Device <> info: launch 'vector_square' kernel 1.5 hipLaunchKernel 'HIP_KERNEL_NAME(vector_square)' gridDim:{512,1,1} groupDim:{256,1,1} sharedMem:+0 stream#0.0 info: copy Device2Host <> info: check result PASSED! ``` HIP_TRACE_API supports multiple levels of debug information: - 0x1 = print all HIP APIs. This is the most verbose setting; the flags below allow selecting a subset. - 0x2 = print HIP APIs which initiate GPU kernel commands. Includes hipLaunchKernel, hipLaunchModuleKernel - 0x4 = print HIP APIs which initiate GPU memory commands. Includes hipMemcpy*, hipMemset*. - 0x8 = print HIP APIs which allocate or free memory. Includes hipMalloc, hipHostMalloc, hipFree, hipHostFree. These can be combined. For example, HIP_TRACE_API=6 shows a concise view of the HIP commands (both kernel and memory) that are sent to the GPU. #### Color Note this trace mode uses colors. "less -r" can handle raw control characters and will display the debug output in proper colors. You can change the color used for the trace mode with the HIP_TRACE_API_COLOR environment variable. Possible values are None/Red/Green/Yellow/Blue/Magenta/Cyan/White. None will disable use of color control codes for both the opening and closing and may be useful when saving the trace file or when a pure text trace is desired.