### `test.hip.cc` ```c++ // C++ standard headers #include <iostream> #include <sstream> #include <stdexcept> #include <string> #include <string_view> // ROCm headers #include <hip/hip_runtime.h> [[noreturn]] inline void abortOnError(const char* file, int line, const char* cmd, const char* error, const char* message, std::string_view description = std::string_view()) { std::ostringstream out; out << "\n"; out << file << ", line " << line << ":\n"; out << "HIP_CHECK(" << cmd << ");\n"; out << error << ": " << message << "\n"; if (!description.empty()) out << description << "\n"; throw std::runtime_error(out.str()); } inline bool hipCheck_(const char* file, int line, const char* cmd, hipError_t result, std::string_view description = std::string_view()) { if (result == hipSuccess) return true; const char* error = hipGetErrorName(result); const char* message = hipGetErrorString(result); abortOnError(file, line, cmd, error, message, description); return false; } #define HIP_CHECK(ARG, ...) (hipCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__)) void callback(hipStream_t stream, hipError_t status, void *data) { std::cerr << "callback on stream " << stream << '\n'; } int main() { int numberOfDevices = 0; HIP_CHECK(hipGetDeviceCount(&numberOfDevices)); for (int i = 0; i < numberOfDevices; ++i) { hipDeviceProp_t properties; HIP_CHECK(hipGetDeviceProperties(&properties, i)); std::cout << "ROCm device " << i << ": " << properties.name << '\n'; hipStream_t queue; HIP_CHECK(hipStreamCreate(&queue)); HIP_CHECK(hipStreamAddCallback(queue, callback, nullptr, 0)); HIP_CHECK(hipStreamSynchronize(queue)); HIP_CHECK(hipStreamDestroy(queue)); } } ``` --- Building and running with ROCm 5.2.x does not show any problems (well, it shows some small leaks, but I’m ignoring them): ``` $ /opt/rocm-5.2.5/bin/hipcc -std=c++17 -x hip -g -O2 test.hip.cc -fsanitize=address -o test $ LD_LIBRARY_PATH=/opt/rocm-5.2.5/lib ./test ROCm device 0: Radeon Pro WX 9100 callback on stream 0x6120000010c0 ``` --- Building and running with ROCm 5.7.0 complains about a memory problem: ``` $ /opt/rocm-5.7.0/bin/hipcc -std=c++17 -x hip -g -O2 x.cc -fsanitize=address -o test $ LD_LIBRARY_PATH=/opt/rocm-5.7.0/lib ./test ROCm device 0: Radeon Pro WX 9100 callback on stream 0x618000000880 ================================================================= ==2225925==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x6030002b9810 in thread T1: object passed to delete has wrong type: size of the allocated type: 32 bytes; size of the deallocated type: 16 bytes. #0 0x390bd8 (/afs/cern.ch/user/f/fwyzard/test/rocm_invalid_memory/test+0x390bd8) #1 0x7f36974eca70 (/opt/rocm-5.7.0/lib/libamdhip64.so.5+0x282a70) (BuildId: de18d06e27b1b52f72be669b86916c49c8cfaead) #2 0x7f36974ecddf (/opt/rocm-5.7.0/lib/libamdhip64.so.5+0x282ddf) (BuildId: de18d06e27b1b52f72be669b86916c49c8cfaead) #3 0x7f369751319e (/opt/rocm-5.7.0/lib/libamdhip64.so.5+0x2a919e) (BuildId: de18d06e27b1b52f72be669b86916c49c8cfaead) #4 0x7f3697513327 (/opt/rocm-5.7.0/lib/libamdhip64.so.5+0x2a9327) (BuildId: de18d06e27b1b52f72be669b86916c49c8cfaead) #5 0x7f368d33d3d3 (/opt/rocm-5.7.0/lib/libhsa-runtime64.so.1+0x673d3) (BuildId: 0d455dc6250ceafa3809537ea17a8bbf2f727af5) #6 0x7f368d2f9f06 (/opt/rocm-5.7.0/lib/libhsa-runtime64.so.1+0x23f06) (BuildId: 0d455dc6250ceafa3809537ea17a8bbf2f727af5) #7 0x7f369693b1c9 (/lib64/libpthread.so.0+0x81c9) (BuildId: 8ff3b7d14abcc882a7201334e28be9bc785cd741) #8 0x7f3695d6be72 (/lib64/libc.so.6+0x39e72) (BuildId: 31f2a86084da882dfe4ecc1fe2a9eca8ce9416fd) 0x6030002b9810 is located 0 bytes inside of 32-byte region [0x6030002b9810,0x6030002b9830) allocated by thread T0 here: #0 0x38fd58 (/afs/cern.ch/user/f/fwyzard/test/rocm_invalid_memory/test+0x38fd58) #1 0x7f3697461d2f (/opt/rocm-5.7.0/lib/libamdhip64.so.5+0x1f7d2f) (BuildId: de18d06e27b1b52f72be669b86916c49c8cfaead) Thread T1 created by T0 here: #0 0x278c6f (/afs/cern.ch/user/f/fwyzard/test/rocm_invalid_memory/test+0x278c6f) #1 0x7f368d2fa23c (/opt/rocm-5.7.0/lib/libhsa-runtime64.so.1+0x2423c) (BuildId: 0d455dc6250ceafa3809537ea17a8bbf2f727af5) SUMMARY: AddressSanitizer: new-delete-type-mismatch (/afs/cern.ch/user/f/fwyzard/test/rocm_invalid_memory/test+0x390bd8) ==2225925==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0 ==2225925==ABORTING ```
{}