SWDEV-402381 - Add hipCheckErrors for HIP API calls in samples (#375)
Change-Id: I335d7e780362fc59fd2d90939b4c8b8a7231ffc7
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b8fb6f88b9
Коммит
7cc53f992f
@@ -40,5 +40,7 @@ set(CMAKE_BUILD_TYPE Release)
|
||||
# Create the excutable
|
||||
add_executable(inline_asm inline_asm.cpp)
|
||||
|
||||
target_include_directories(inline_asm PRIVATE ../../common)
|
||||
|
||||
# Link with HIP
|
||||
target_link_libraries(inline_asm hip::host)
|
||||
|
||||
@@ -32,7 +32,7 @@ TARGET=hcc
|
||||
|
||||
SOURCES = inline_asm.cpp
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
INCLUDES := -I../../common
|
||||
EXECUTABLE=./inline_asm
|
||||
|
||||
.PHONY: test
|
||||
@@ -40,7 +40,7 @@ EXECUTABLE=./inline_asm
|
||||
|
||||
all: $(EXECUTABLE) test
|
||||
|
||||
CXXFLAGS =-g
|
||||
CXXFLAGS =-g $(INCLUDES)
|
||||
CXX=$(HIPCC)
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ THE SOFTWARE.
|
||||
|
||||
// hip header file
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip_helper.h"
|
||||
|
||||
#define WIDTH 1024
|
||||
|
||||
@@ -59,13 +60,13 @@ int main() {
|
||||
float* gpuTransposeMatrix;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
checkHipErrors(hipGetDeviceProperties(&devProp, 0));
|
||||
|
||||
std::cout << "Device name " << devProp.name << std::endl;
|
||||
|
||||
hipEvent_t start, stop;
|
||||
hipEventCreate(&start);
|
||||
hipEventCreate(&stop);
|
||||
checkHipErrors(hipEventCreate(&start));
|
||||
checkHipErrors(hipEventCreate(&stop));
|
||||
float eventMs = 1.0f;
|
||||
|
||||
int i;
|
||||
@@ -81,25 +82,25 @@ int main() {
|
||||
}
|
||||
|
||||
// allocate the memory on the device side
|
||||
hipMalloc((void**)&gpuMatrix, NUM * sizeof(float));
|
||||
hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float));
|
||||
checkHipErrors(hipMalloc((void**)&gpuMatrix, NUM * sizeof(float)));
|
||||
checkHipErrors(hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float)));
|
||||
|
||||
// Record the start event
|
||||
hipEventRecord(start, NULL);
|
||||
checkHipErrors(hipEventRecord(start, NULL));
|
||||
|
||||
// Memory transfer from host to device
|
||||
hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice);
|
||||
checkHipErrors(hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice));
|
||||
|
||||
// Record the stop event
|
||||
hipEventRecord(stop, NULL);
|
||||
hipEventSynchronize(stop);
|
||||
checkHipErrors(hipEventRecord(stop, NULL));
|
||||
checkHipErrors(hipEventSynchronize(stop));
|
||||
|
||||
hipEventElapsedTime(&eventMs, start, stop);
|
||||
checkHipErrors(hipEventElapsedTime(&eventMs, start, stop));
|
||||
|
||||
printf("hipMemcpyHostToDevice time taken = %6.3fms\n", eventMs);
|
||||
|
||||
// Record the start event
|
||||
hipEventRecord(start, NULL);
|
||||
checkHipErrors(hipEventRecord(start, NULL));
|
||||
|
||||
// Lauching kernel from host
|
||||
hipLaunchKernelGGL(matrixTranspose, dim3(WIDTH / THREADS_PER_BLOCK_X, WIDTH / THREADS_PER_BLOCK_Y),
|
||||
@@ -107,24 +108,24 @@ int main() {
|
||||
gpuMatrix, WIDTH);
|
||||
|
||||
// Record the stop event
|
||||
hipEventRecord(stop, NULL);
|
||||
hipEventSynchronize(stop);
|
||||
checkHipErrors(hipEventRecord(stop, NULL));
|
||||
checkHipErrors(hipEventSynchronize(stop));
|
||||
|
||||
hipEventElapsedTime(&eventMs, start, stop);
|
||||
checkHipErrors(hipEventElapsedTime(&eventMs, start, stop));
|
||||
|
||||
printf("kernel Execution time = %6.3fms\n", eventMs);
|
||||
|
||||
// Record the start event
|
||||
hipEventRecord(start, NULL);
|
||||
checkHipErrors(hipEventRecord(start, NULL));
|
||||
|
||||
// Memory transfer from device to host
|
||||
hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost);
|
||||
checkHipErrors(hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost));
|
||||
|
||||
// Record the stop event
|
||||
hipEventRecord(stop, NULL);
|
||||
hipEventSynchronize(stop);
|
||||
checkHipErrors(hipEventRecord(stop, NULL));
|
||||
checkHipErrors(hipEventSynchronize(stop));
|
||||
|
||||
hipEventElapsedTime(&eventMs, start, stop);
|
||||
checkHipErrors(hipEventElapsedTime(&eventMs, start, stop));
|
||||
|
||||
printf("hipMemcpyDeviceToHost time taken = %6.3fms\n", eventMs);
|
||||
|
||||
@@ -147,8 +148,8 @@ int main() {
|
||||
}
|
||||
|
||||
// free the resources on device side
|
||||
hipFree(gpuMatrix);
|
||||
hipFree(gpuTransposeMatrix);
|
||||
checkHipErrors(hipFree(gpuMatrix));
|
||||
checkHipErrors(hipFree(gpuTransposeMatrix));
|
||||
|
||||
// free the resources on host side
|
||||
free(Matrix);
|
||||
|
||||
Ссылка в новой задаче
Block a user