Skip to content

Commit

Permalink
GPU: Auto-generate include-list for kernel headers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrohr committed Feb 28, 2024
1 parent 500ed2f commit 8e70f22
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 120 deletions.
25 changes: 2 additions & 23 deletions GPU/GPUTracking/Base/GPUReconstructionCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,13 @@
#include <vector>

#include "GPUGeneralKernels.h"
#include "GPUTPCCreateSliceData.h"
#include "GPUTPCNeighboursFinder.h"
#include "GPUTPCNeighboursCleaner.h"
#include "GPUTPCStartHitsFinder.h"
#include "GPUTPCStartHitsSorter.h"
#include "GPUTPCTrackletConstructor.h"
#include "GPUTPCTrackletSelector.h"
#include "GPUTPCGlobalTracking.h"
#include "GPUTRDTrackerKernels.h"
#include "GPUTPCCreateOccupancyMap.h"
#include "GPUTPCSectorDebugSortKernels.h"
#include "GPUTPCGlobalDebugSortKernels.h"
#ifdef GPUCA_NOCOMPAT
#include "GPUTPCGMMergerGPU.h"
#endif
#ifdef GPUCA_HAVE_O2HEADERS
#include "GPUITSFitterKernels.h"
#include "GPUTPCConvertKernel.h"
#include "GPUTPCCompressionKernels.h"
#include "GPUTPCClusterFinderKernels.h"
#include "GPUTrackingRefitKernel.h"
#include "GPUTPCGMO2Output.h"
#endif
#include "GPUReconstructionKernelIncludes.h"

namespace GPUCA_NAMESPACE
{
namespace gpu
{

class GPUReconstructionCPUBackend : public GPUReconstruction
{
public:
Expand Down
18 changes: 18 additions & 0 deletions GPU/GPUTracking/Base/GPUReconstructionKernelIncludes.template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 GPUReconstructionKernelIncludes.h
/// \author David Rohr

// clang-format off
$<JOIN:$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:REMOVE_DUPLICATES,$<TARGET_PROPERTY:O2_GPU_KERNELS,O2_GPU_KERNEL_INCLUDES>>,APPEND,.h">,PREPEND,#include ">,
>
// clang-format on
4 changes: 4 additions & 0 deletions GPU/GPUTracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ file(GENERATE
OUTPUT include_gpu_onthefly/GPUReconstructionKernels.h
INPUT Base/GPUReconstructionKernels.template.h
)
file(GENERATE
OUTPUT include_gpu_onthefly/GPUReconstructionKernelIncludes.h
INPUT Base/GPUReconstructionKernelIncludes.template.h
)
if(NOT ALIGPU_BUILD_TYPE STREQUAL "O2")
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly)
endif()
Expand Down
12 changes: 7 additions & 5 deletions GPU/GPUTracking/cmake/kernel_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
add_custom_target(O2_GPU_KERNELS)
define_property(TARGET PROPERTY O2_GPU_KERNELS)
define_property(TARGET PROPERTY O2_GPU_KERNEL_NAMES)
define_property(TARGET PROPERTY O2_GPU_KERNEL_INCLUDES)
set(O2_GPU_KERNEL_WRAPPER_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly")
file(MAKE_DIRECTORY ${O2_GPU_KERNEL_WRAPPER_FOLDER})
set(O2_GPU_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}/../")
function(o2_gpu_add_kernel kernel_name kernel_bounds kernel_type)
function(o2_gpu_add_kernel kernel_name kernel_files kernel_bounds kernel_type)
math(EXPR TMP_CHK "${ARGC} & 1")
if(NOT ${TMP_CHK})
if(${TMP_CHK})
message(FATAL_ERROR "Invalid number of arguments to kernel ${TMP_CHK}, must be odd to have pairs of argument type, argument name")
endif()
list(LENGTH ARGV n)
set(OPT1 "")
set(OPT2 "")
if(${n} GREATER 3)
if(${n} GREATER 4)
math(EXPR n "${n} - 1")
foreach(i RANGE 3 ${n} 2)
foreach(i RANGE 4 ${n} 2)
math(EXPR j "${i} + 1")
if(${ARGV${i}} MATCHES "\\*$")
string(APPEND OPT1 ",GPUPtr1(${ARGV${i}},${ARGV${j}})")
Expand All @@ -54,9 +55,10 @@ function(o2_gpu_add_kernel kernel_name kernel_bounds kernel_type)
endif()
set(TMP_KERNEL "GPUCA_KRNL${TMP_BOUNDS}((${kernel_name}), (${kernel_type}), (${OPT1}), (${OPT2}))\n")
set(TMP_KERNEL_IN_HEADER "${TMP_PRE}${TMP_KERNEL}${TMP_POST}")
list(GET kernel_files 0 TMP_KERNEL_CLASS)
set_property(TARGET O2_GPU_KERNELS APPEND PROPERTY O2_GPU_KERNELS "${TMP_KERNEL_IN_HEADER}")
set_property(TARGET O2_GPU_KERNELS APPEND PROPERTY O2_GPU_KERNEL_NAMES "${kernel_name}")

set_property(TARGET O2_GPU_KERNELS APPEND PROPERTY O2_GPU_KERNEL_INCLUDES "${TMP_KERNEL_CLASS}")
# add_custom_command OUTPUT option does not support target-dependend generator expressions, thus this workaround
if(CUDA_ENABLED)
string(REPLACE ", " "_" TMP_FILENAME "${kernel_name}")
Expand Down
Loading

0 comments on commit 8e70f22

Please sign in to comment.