SWDEV-402381 - Add hipCheckErrors for HIP API calls in samples (#375)
Change-Id: I335d7e780362fc59fd2d90939b4c8b8a7231ffc7
Цей коміт міститься в:
1 джерело
b8fb6f88b9
коміт
7cc53f992f
71 files changed
+460
-448
No files matched your search
@@ -22,6 +22,8 @@ project(hipDispatchLatency)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
include_directories(../../common)
|
||||
|
||||
if (NOT DEFINED ROCM_PATH )
|
||||
set ( ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory." )
|
||||
endif ()
|
||||
|
||||
@@ -26,8 +26,9 @@ ifeq (,$(HIP_PATH))
|
||||
HIP_PATH=../../..
|
||||
endif
|
||||
HIPCC=$(HIP_PATH)/bin/hipcc -std=c++11
|
||||
INCLUDES := -I../../common
|
||||
|
||||
CXXFLAGS = -O3
|
||||
CXXFLAGS = -O3 $(INCLUDES)
|
||||
|
||||
all: test_kernel.code hipDispatchLatency.out hipDispatchEnqueueRateMT.out
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ THE SOFTWARE.
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
#include "hip/hip_ext.h"
|
||||
#endif
|
||||
#include "hip_helper.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
@@ -41,16 +42,6 @@ THE SOFTWARE.
|
||||
#define failed(...) \
|
||||
abort();
|
||||
|
||||
#define HIPCHECK(error) \
|
||||
{ \
|
||||
hipError_t localError = error; \
|
||||
if ((localError != hipSuccess) && (localError != hipErrorPeerAccessAlreadyEnabled)) { \
|
||||
printf("error: '%s'(%d) from %s at %s:%d\n", hipGetErrorString(localError), \
|
||||
localError, #error, __FILE__, __LINE__); \
|
||||
failed("API returned error code."); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
__global__ void EmptyKernel() {}
|
||||
|
||||
@@ -87,12 +78,12 @@ void hipModuleLaunchKernel_enqueue_rate(const std::vector<char>& buffer, std::at
|
||||
{
|
||||
//resources necessary for this thread
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
checkHipErrors(hipStreamCreate(&stream));
|
||||
hipModule_t module;
|
||||
hipFunction_t function;
|
||||
|
||||
HIPCHECK(hipModuleLoadData(&module, &buffer[0]));
|
||||
HIPCHECK(hipModuleGetFunction(&function, module, "test"));
|
||||
checkHipErrors(hipModuleLoadData(&module, &buffer[0]));
|
||||
checkHipErrors(hipModuleGetFunction(&function, module, "test"));
|
||||
|
||||
void* kernel_params = nullptr;
|
||||
std::array<float, TOTAL_RUN_COUNT> results;
|
||||
@@ -103,13 +94,13 @@ void hipModuleLaunchKernel_enqueue_rate(const std::vector<char>& buffer, std::at
|
||||
|
||||
for (auto i = 0; i < TOTAL_RUN_COUNT; ++i) {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
HIPCHECK(hipModuleLaunchKernel(function, 1, 1, 1, 1, 1, 1, 0, stream, &kernel_params, nullptr));
|
||||
checkHipErrors(hipModuleLaunchKernel(function, 1, 1, 1, 1, 1, 1, 0, stream, &kernel_params, nullptr));
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
results[i] = std::chrono::duration<double, std::milli>(stop - start).count();
|
||||
}
|
||||
HIPCHECK(hipModuleUnload(module));
|
||||
checkHipErrors(hipModuleUnload(module));
|
||||
print_timing("Thread ID : " + std::to_string(tid) + " , " + "hipModuleLaunchKernel enqueue rate", results);
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
checkHipErrors(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
// Measure time taken to enqueue a kernel on the GPU using hipLaunchKernelGGL
|
||||
@@ -117,7 +108,7 @@ void hipLaunchKernelGGL_enqueue_rate(const std::vector<char>& buffer, std::atomi
|
||||
{
|
||||
//resources necessary for this thread
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
checkHipErrors(hipStreamCreate(&stream));
|
||||
std::array<float, TOTAL_RUN_COUNT> results;
|
||||
|
||||
//synchronize all threads, before running
|
||||
@@ -131,7 +122,7 @@ void hipLaunchKernelGGL_enqueue_rate(const std::vector<char>& buffer, std::atomi
|
||||
results[i] = std::chrono::duration<double, std::milli>(stop - start).count();
|
||||
}
|
||||
print_timing("Thread ID : " + std::to_string(tid) + " , " + "hipLaunchKernelGGL enqueue rate", results);
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
checkHipErrors(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
// Simple thread pool
|
||||
|
||||
@@ -21,6 +21,7 @@ THE SOFTWARE.
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
#include "hip/hip_ext.h"
|
||||
#endif
|
||||
#include "hip_helper.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
@@ -66,19 +67,19 @@ void print_timing(std::string test, const std::array<float, TOTAL_RUN_COUNT> &re
|
||||
int main() {
|
||||
hipStream_t stream0 = 0;
|
||||
hipDevice_t device;
|
||||
hipDeviceGet(&device, 0);
|
||||
checkHipErrors(hipDeviceGet(&device, 0));
|
||||
hipCtx_t context;
|
||||
hipCtxCreate(&context, 0, device);
|
||||
checkHipErrors(hipCtxCreate(&context, 0, device));
|
||||
hipModule_t module;
|
||||
hipFunction_t function;
|
||||
hipModuleLoad(&module, FILE_NAME);
|
||||
hipModuleGetFunction(&function, module, KERNEL_NAME);
|
||||
checkHipErrors(hipModuleLoad(&module, FILE_NAME));
|
||||
checkHipErrors(hipModuleGetFunction(&function, module, KERNEL_NAME));
|
||||
void* params = nullptr;
|
||||
|
||||
std::array<float, TOTAL_RUN_COUNT> results;
|
||||
hipEvent_t start, stop;
|
||||
hipEventCreate(&start);
|
||||
hipEventCreate(&stop);
|
||||
checkHipErrors(hipEventCreate(&start));
|
||||
checkHipErrors(hipEventCreate(&stop));
|
||||
|
||||
/************************************************************************************/
|
||||
/* HIP kernel launch enqueue rate: */
|
||||
@@ -88,7 +89,7 @@ int main() {
|
||||
// Timing hipModuleLaunchKernel
|
||||
for (auto i = 0; i < TOTAL_RUN_COUNT; ++i) {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
hipModuleLaunchKernel(function, 1, 1, 1, 1, 1, 1, 0, 0, ¶ms, nullptr);
|
||||
checkHipErrors(hipModuleLaunchKernel(function, 1, 1, 1, 1, 1, 1, 0, 0, ¶ms, nullptr));
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
results[i] = std::chrono::duration<float, std::milli>(stop - start).count();
|
||||
}
|
||||
@@ -110,11 +111,11 @@ int main() {
|
||||
|
||||
//Timing around the dispatch
|
||||
for (auto i = 0; i < TOTAL_RUN_COUNT; ++i) {
|
||||
hipEventRecord(start, 0);
|
||||
checkHipErrors(hipEventRecord(start, 0));
|
||||
hipLaunchKernelGGL((EmptyKernel), dim3(NUM_GROUPS), dim3(GROUP_SIZE), 0, stream0);
|
||||
hipEventRecord(stop, 0);
|
||||
hipEventSynchronize(stop);
|
||||
hipEventElapsedTime(&results[i], start, stop);
|
||||
checkHipErrors(hipEventRecord(stop, 0));
|
||||
checkHipErrors(hipEventSynchronize(stop));
|
||||
checkHipErrors(hipEventElapsedTime(&results[i], start, stop));
|
||||
}
|
||||
print_timing("Timing around single dispatch latency", results);
|
||||
|
||||
@@ -124,18 +125,18 @@ int main() {
|
||||
/*********************************************************************************/
|
||||
|
||||
for (auto i = 0; i < TOTAL_RUN_COUNT; ++i) {
|
||||
hipEventRecord(start, 0);
|
||||
checkHipErrors(hipEventRecord(start, 0));
|
||||
for (int j = 0; j < BATCH_SIZE; j++) {
|
||||
hipLaunchKernelGGL((EmptyKernel), dim3(NUM_GROUPS), dim3(GROUP_SIZE), 0, stream0);
|
||||
}
|
||||
hipEventRecord(stop, 0);
|
||||
hipEventSynchronize(stop);
|
||||
hipEventElapsedTime(&results[i], start, stop);
|
||||
checkHipErrors(hipEventRecord(stop, 0));
|
||||
checkHipErrors(hipEventSynchronize(stop));
|
||||
checkHipErrors(hipEventElapsedTime(&results[i], start, stop));
|
||||
}
|
||||
print_timing("Batch dispatch latency", results, BATCH_SIZE);
|
||||
|
||||
hipEventDestroy(start);
|
||||
hipEventDestroy(stop);
|
||||
hipCtxDestroy(context);
|
||||
checkHipErrors(hipEventDestroy(start));
|
||||
checkHipErrors(hipEventDestroy(stop));
|
||||
checkHipErrors(hipCtxDestroy(context));
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ add_executable(hipInfo hipInfo.cpp)
|
||||
# Link with HIP
|
||||
target_link_libraries(hipInfo hip::host)
|
||||
|
||||
target_include_directories(hipInfo PRIVATE ../../common)
|
||||
|
||||
# Used only when make install is called
|
||||
# when hipInfo is built as part of compute project
|
||||
# hipInfo.exe will be installed to install/hip/bin path
|
||||
|
||||
@@ -26,13 +26,14 @@ ifeq (,$(HIP_PATH))
|
||||
HIP_PATH=../../..
|
||||
endif
|
||||
HIPCC=$(HIP_PATH)/bin/hipcc
|
||||
INCLUDES := -I../../common
|
||||
|
||||
EXE=hipInfo
|
||||
|
||||
all: install
|
||||
|
||||
$(EXE): hipInfo.cpp
|
||||
$(HIPCC) hipInfo.cpp -o $@
|
||||
$(HIPCC) hipInfo.cpp $(INCLUDES) -o $@
|
||||
|
||||
install: $(EXE)
|
||||
cp $(EXE) $(HIP_PATH)/bin
|
||||
|
||||
@@ -23,6 +23,7 @@ THE SOFTWARE.
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip_helper.h"
|
||||
|
||||
#define KNRM "\x1B[0m"
|
||||
#define KRED "\x1B[31m"
|
||||
@@ -33,20 +34,6 @@ THE SOFTWARE.
|
||||
#define KCYN "\x1B[36m"
|
||||
#define KWHT "\x1B[37m"
|
||||
|
||||
#define failed(...) \
|
||||
printf("%serror: ", KRED); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
printf("error: TEST FAILED\n%s", KNRM); \
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
#define HIPCHECK(error) \
|
||||
if (error != hipSuccess) { \
|
||||
printf("%serror: '%s'(%d) at %s:%d%s\n", KRED, hipGetErrorString(error), error, __FILE__, \
|
||||
__LINE__, KNRM); \
|
||||
failed("API returned error code."); \
|
||||
}
|
||||
|
||||
void printCompilerInfo() {
|
||||
#ifdef __NVCC__
|
||||
printf("compiler: nvcc\n");
|
||||
@@ -76,7 +63,7 @@ void printDeviceProp(int deviceId) {
|
||||
cout << setw(w1) << "device#" << deviceId << endl;
|
||||
|
||||
hipDeviceProp_t props = {0};
|
||||
HIPCHECK(hipGetDeviceProperties(&props, deviceId));
|
||||
checkHipErrors(hipGetDeviceProperties(&props, deviceId));
|
||||
|
||||
cout << setw(w1) << "Name: " << props.name << endl;
|
||||
cout << setw(w1) << "pciBusID: " << props.pciBusID << endl;
|
||||
@@ -149,11 +136,11 @@ void printDeviceProp(int deviceId) {
|
||||
cout << setw(w1) << "gcnArchName: " << props.gcnArchName << endl;
|
||||
#endif
|
||||
int deviceCnt;
|
||||
hipGetDeviceCount(&deviceCnt);
|
||||
checkHipErrors(hipGetDeviceCount(&deviceCnt));
|
||||
cout << setw(w1) << "peers: ";
|
||||
for (int i = 0; i < deviceCnt; i++) {
|
||||
int isPeer;
|
||||
hipDeviceCanAccessPeer(&isPeer, i, deviceId);
|
||||
checkHipErrors(hipDeviceCanAccessPeer(&isPeer, i, deviceId));
|
||||
if (isPeer) {
|
||||
cout << "device#" << i << " ";
|
||||
}
|
||||
@@ -162,7 +149,7 @@ void printDeviceProp(int deviceId) {
|
||||
cout << setw(w1) << "non-peers: ";
|
||||
for (int i = 0; i < deviceCnt; i++) {
|
||||
int isPeer;
|
||||
hipDeviceCanAccessPeer(&isPeer, i, deviceId);
|
||||
checkHipErrors(hipDeviceCanAccessPeer(&isPeer, i, deviceId));
|
||||
if (!isPeer) {
|
||||
cout << "device#" << i << " ";
|
||||
}
|
||||
@@ -185,7 +172,7 @@ void printDeviceProp(int deviceId) {
|
||||
|
||||
|
||||
size_t free, total;
|
||||
hipMemGetInfo(&free, &total);
|
||||
checkHipErrors(hipMemGetInfo(&free, &total));
|
||||
|
||||
cout << fixed << setprecision(2);
|
||||
cout << setw(w1) << "memInfo.total: " << bytesToGB(total) << " GB" << endl;
|
||||
@@ -202,10 +189,10 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
int deviceCnt;
|
||||
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCnt));
|
||||
checkHipErrors(hipGetDeviceCount(&deviceCnt));
|
||||
|
||||
for (int i = 0; i < deviceCnt; i++) {
|
||||
hipSetDevice(i);
|
||||
checkHipErrors(hipSetDevice(i));
|
||||
printDeviceProp(i);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача