Skip to content

Commit

Permalink
Add HIPIFIED tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mconcas committed Feb 11, 2024
1 parent 4486909 commit f5c4b65
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 10 deletions.
14 changes: 13 additions & 1 deletion GPU/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2")
PUBLIC_LINK_LIBRARIES O2::${MODULE}
COMPONENT_NAME GPU
LABELS gpu)
o2_add_test(GPUSMatrixImp NAME test_GPUSMatrixImpCUDA
SOURCES test/testGPUSMatrixImp.cu
PUBLIC_LINK_LIBRARIES O2::${MODULE}
COMPONENT_NAME GPU
LABELS gpu)
endif()
if (HIP_ENABLED)
o2_add_test(GPUSMatrixImpHIP NAME test_GPUSMatrixImpHIP
SOURCES test/testGPUSMatrixImp.cu
HIPIFIED test
PUBLIC_LINK_LIBRARIES O2::${MODULE}
COMPONENT_NAME GPU
LABELS gpu)
endif()

install(FILES ${HDRS_INSTALL} DESTINATION include/GPU)
endif()

Expand Down
1 change: 1 addition & 0 deletions GPU/Common/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.hip
75 changes: 75 additions & 0 deletions GPU/Common/test/testGPUSMatrixImp.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file testGPUSMatrixImp.cu
/// \author Matteo Concas

#define BOOST_TEST_MODULE Test GPUSMatrixImpl
#ifdef __HIPCC__
#define GPUPLATFORM "HIP"
#include "hip/hip_runtime.h"
#else
#define GPUPLATFORM "CUDA"
#endif

#include <boost/test/unit_test.hpp>
#include <iostream>

cudaError_t gpuCheckError(cudaError_t gpuErrorCode)
{
if (gpuErrorCode != cudaSuccess) {
std::cerr << "ErrorCode " << gpuErrorCode << " " << cudaGetErrorName(gpuErrorCode) << ": " << cudaGetErrorString(gpuErrorCode) << std::endl;
exit(-1);
}
return gpuErrorCode;
}

__global__ void kernel()
{
printf("Hello world from device\n");
}

struct GPUSMatrixImplFixture {
GPUSMatrixImplFixture()
{
std::cout << "GPUSMatrixImplFixture" << std::endl;
// Get the number of GPU devices
int deviceCount;
cudaGetDeviceCount(&deviceCount);

if (deviceCount == 0) {
std::cerr << "No " << GPUPLATFORM << " devices found" << std::endl;
}

for (int iDevice = 0; iDevice < deviceCount; ++iDevice) {
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, iDevice);

std::cout << GPUPLATFORM << " Device " << iDevice << ": " << deviceProp.name << std::endl;
}

kernel<<<1, 1>>>();
gpuCheckError(cudaDeviceSynchronize());
i = 3;
}

~GPUSMatrixImplFixture()
{
std::cout << "~GPUSMatrixImplFixture" << std::endl;
}

int i;
};

BOOST_FIXTURE_TEST_CASE(DummyFixtureUsage, GPUSMatrixImplFixture)
{
BOOST_TEST(i == 3);
}
5 changes: 3 additions & 2 deletions cmake/O2AddHipifiedExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ include(O2AddExecutable)

function(o2_add_hipified_executable baseTargetName)
# Parse arguments in the same way o2_add_executable does
# DEST_SRC_REL_PATH is the relative destination path for converted src files
cmake_parse_arguments(PARSE_ARGV
1
A
"IS_TEST;NO_INSTALL;IS_BENCHMARK"
"COMPONENT_NAME;TARGETVARNAME"
"COMPONENT_NAME;TARGETVARNAME;DEST_SRC_REL_PATH"
"SOURCES;PUBLIC_LINK_LIBRARIES;JOB_POOL")

# Process each .cu file to generate a .hip file
Expand All @@ -32,7 +33,7 @@ function(o2_add_hipified_executable baseTargetName)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${file})
get_filename_component(CUDA_SOURCE ${file} NAME)
string(REPLACE ".cu" ".hip" HIP_SOURCE ${CUDA_SOURCE})
set(OUTPUT_HIP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${HIP_SOURCE}")
set(OUTPUT_HIP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${A_DEST_SRC_REL_PATH}/${HIP_SOURCE}")
list(APPEND HIP_SOURCES ${OUTPUT_HIP_FILE})

add_custom_command(
Expand Down
22 changes: 15 additions & 7 deletions cmake/O2AddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function(o2_add_test)
1
A
"INSTALL;NO_BOOST_TEST"
"COMPONENT_NAME;TIMEOUT;WORKING_DIRECTORY;NAME;TARGETVARNAME"
"COMPONENT_NAME;TIMEOUT;WORKING_DIRECTORY;NAME;TARGETVARNAME;HIPIFIED"
"SOURCES;PUBLIC_LINK_LIBRARIES;COMMAND_LINE_ARGS;LABELS;CONFIGURATIONS;ENVIRONMENT"
)

Expand Down Expand Up @@ -103,12 +103,20 @@ function(o2_add_test)
endif()

# create the executable
o2_add_executable(${testName}
SOURCES ${A_SOURCES}
PUBLIC_LINK_LIBRARIES ${linkLibraries}
COMPONENT_NAME ${A_COMPONENT_NAME}
IS_TEST ${noInstall} TARGETVARNAME targetName)

if (NOT A_HIPIFIED)
o2_add_executable(${testName}
SOURCES ${A_SOURCES}
PUBLIC_LINK_LIBRARIES ${linkLibraries}
COMPONENT_NAME ${A_COMPONENT_NAME}
IS_TEST ${noInstall} TARGETVARNAME targetName)
else()
o2_add_hipified_executable(${testName}
SOURCES ${A_SOURCES}
DEST_SRC_REL_PATH ${A_HIPIFIED}
PUBLIC_LINK_LIBRARIES ${linkLibraries}
COMPONENT_NAME ${A_COMPONENT_NAME}
IS_TEST ${noInstall} TARGETVARNAME targetName)
endif()

if(A_TARGETVARNAME)
set(${A_TARGETVARNAME} ${targetName} PARENT_SCOPE)
Expand Down

0 comments on commit f5c4b65

Please sign in to comment.