Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions codegen/kernel_specialization/gen_kernel_specialization.py

This file was deleted.

146 changes: 38 additions & 108 deletions device/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,115 +111,43 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
"src/fitting/kernels/fit_prelude.cu"
)

set(TRACCC_CUDA_SUPPORTED_BFIELDS "const;inhom_global;inhom_texture")

set(KERNEL_SPECIALIZATION_PY "${PROJECT_SOURCE_DIR}/codegen/kernel_specialization/gen_kernel_specialization.py")

# Generate specializations of find_tracks
foreach(DETECTOR_NAME ${TRACCC_SUPPORTED_DETECTORS})
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/find_tracks_${DETECTOR_NAME}.cu")
set(TEMPLATE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/finding/kernels/specializations/find_tracks.cu.template")
add_custom_command(
OUTPUT "${GENERATED_SOURCE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/"
COMMAND
Python::Interpreter
"${KERNEL_SPECIALIZATION_PY}"
"${TEMPLATE_SOURCE}"
-o "${GENERATED_SOURCE}"
--detector "${DETECTOR_NAME}"
DEPENDS "${KERNEL_SPECIALIZATION_PY}" "${TEMPLATE_SOURCE}"
COMMENT "Generating kernel specialization of `find_tracks` for ${DETECTOR_NAME}"
)
target_sources(traccc_cuda PRIVATE ${GENERATED_SOURCE})
endforeach()

# Generate specializations for apply_interaction
foreach(DETECTOR_NAME ${TRACCC_SUPPORTED_DETECTORS})
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/apply_interaction_${DETECTOR_NAME}.cu")
set(TEMPLATE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/finding/kernels/specializations/apply_interaction.cu.template")
add_custom_command(
OUTPUT "${GENERATED_SOURCE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/"
COMMAND
Python::Interpreter
"${KERNEL_SPECIALIZATION_PY}"
"${TEMPLATE_SOURCE}"
-o "${GENERATED_SOURCE}"
--detector "${DETECTOR_NAME}"
DEPENDS "${KERNEL_SPECIALIZATION_PY}" "${TEMPLATE_SOURCE}"
COMMENT "Generating kernel specialization of `apply_interaction` for ${DETECTOR_NAME}"
)
target_sources(traccc_cuda PRIVATE ${GENERATED_SOURCE})
endforeach()

# Generate specializations for propagate_to_next_surface
foreach(DETECTOR_NAME ${TRACCC_SUPPORTED_DETECTORS})
foreach(BFIELD_NAME ${TRACCC_CUDA_SUPPORTED_BFIELDS})
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/propagate_to_next_surface_${DETECTOR_NAME}_${BFIELD_NAME}.cu")
set(TEMPLATE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/finding/kernels/specializations/propagate_to_next_surface.cu.template")
add_custom_command(
OUTPUT "${GENERATED_SOURCE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/finding/kernels/specializations/"
COMMAND
Python::Interpreter
"${KERNEL_SPECIALIZATION_PY}"
"${TEMPLATE_SOURCE}"
-o "${GENERATED_SOURCE}"
--detector "${DETECTOR_NAME}"
--bfield "${BFIELD_NAME}"
--model cuda
DEPENDS "${KERNEL_SPECIALIZATION_PY}" "${TEMPLATE_SOURCE}"
COMMENT "Generating kernel specialization of `propagate_to_next_surface` for ${DETECTOR_NAME} and ${BFIELD_NAME}"
)
target_sources(traccc_cuda PRIVATE ${GENERATED_SOURCE})
endforeach()
endforeach()

# Generate specializations for fit_forward
foreach(DETECTOR_NAME ${TRACCC_SUPPORTED_DETECTORS})
foreach(BFIELD_NAME ${TRACCC_CUDA_SUPPORTED_BFIELDS})
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/fitting/kernels/specializations/fit_forward_${DETECTOR_NAME}_${BFIELD_NAME}.cu")
set(TEMPLATE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/fitting/kernels/specializations/fit_forward.cu.template")
add_custom_command(
OUTPUT "${GENERATED_SOURCE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fitting/kernels/specializations/"
COMMAND
Python::Interpreter
"${KERNEL_SPECIALIZATION_PY}"
"${TEMPLATE_SOURCE}"
-o "${GENERATED_SOURCE}"
--detector "${DETECTOR_NAME}"
--bfield "${BFIELD_NAME}"
--model cuda
DEPENDS "${KERNEL_SPECIALIZATION_PY}" "${TEMPLATE_SOURCE}"
COMMENT "Generating kernel specialization of `fit_forward` for ${DETECTOR_NAME} and ${BFIELD_NAME}"
)
target_sources(traccc_cuda PRIVATE ${GENERATED_SOURCE})
endforeach()
endforeach()

# Generate specializations for fit_backward
# Create a well formed postfix for the specialized filenames.
function(traccc_make_cuda_fname_postfix FNAME)
set("${FNAME}" "")
if(NOT "${DETECTOR_NAME}" STREQUAL "")
set("${FNAME}" "${${FNAME}}.${DETECTOR_NAME}")
endif()
if(NOT "${BFIELD_NAME}" STREQUAL "")
set("${FNAME}" "${${FNAME}}.${BFIELD_NAME}")
endif()
string(REPLACE "<scalar>" "" "${FNAME}" "${${FNAME}}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CMake string manipulation should go, we need to resolve this all in C++ using template specialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CMake manipulation is here to generate a functional file name. For nothing else. And since the file name is more or less irrelevant (it just needs to be something POSIX compatible), I don't understand why we'd need to do things differently.

set("${FNAME}" "${${FNAME}}" PARENT_SCOPE)
endfunction()

# Helper macro for adding a kernel specialization to the build of traccc::cuda.
function(traccc_add_cuda_specialization TEMPLATE_FILE)
traccc_make_cuda_fname_postfix(FNAME_POSTFIX)
configure_file("${TEMPLATE_FILE}" "${TEMPLATE_FILE}${FNAME_POSTFIX}.cu")
target_sources(traccc_cuda PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/${TEMPLATE_FILE}${FNAME_POSTFIX}.cu")
endfunction()
Comment on lines +114 to +133
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this all relies on implicit variable capture needs to go; the bfield name and detector name need to be actual function arguments here. The target also needs to be a template argument so that we don't need a CUDA specialization for this.


# Generate specializations for the kernels.
foreach(DETECTOR_NAME ${TRACCC_SUPPORTED_DETECTORS})
foreach(BFIELD_NAME ${TRACCC_CUDA_SUPPORTED_BFIELDS})
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/src/fitting/kernels/specializations/fit_backward_${DETECTOR_NAME}_${BFIELD_NAME}.cu")
set(TEMPLATE_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/fitting/kernels/specializations/fit_backward.cu.template")
add_custom_command(
OUTPUT "${GENERATED_SOURCE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fitting/kernels/specializations/"
COMMAND
Python::Interpreter
"${KERNEL_SPECIALIZATION_PY}"
"${TEMPLATE_SOURCE}"
-o "${GENERATED_SOURCE}"
--detector "${DETECTOR_NAME}"
--bfield "${BFIELD_NAME}"
--model cuda
DEPENDS "${KERNEL_SPECIALIZATION_PY}" "${TEMPLATE_SOURCE}"
COMMENT "Generating kernel specialization of `fit_backward` for ${DETECTOR_NAME} and ${BFIELD_NAME}"
)
target_sources(traccc_cuda PRIVATE ${GENERATED_SOURCE})
endforeach()
traccc_add_cuda_specialization(
"src/finding/kernels/specializations/find_tracks.cu.in")
traccc_add_cuda_specialization(
"src/finding/kernels/specializations/apply_interaction.cu.in")
foreach(BFIELD_NAME "const_bfield_backend_t<scalar>"
"inhom_global_bfield_backend_t<scalar>"
"inhom_texture_bfield_backend_t")
Comment on lines +141 to +143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bring back the list variable here, and as mentioned before the <scalar> template argument needs to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inputting C++ types here. 🤔 I don't understand your objection. scalar is a valid replacement in your template files.

traccc_add_cuda_specialization(
"src/finding/kernels/specializations/propagate_to_next_surface.cu.in")
traccc_add_cuda_specialization(
"src/fitting/kernels/specializations/fit_forward.cu.in")
traccc_add_cuda_specialization(
"src/fitting/kernels/specializations/fit_backward.cu.in")
endforeach()
endforeach()

if(TRACCC_ENABLE_NVTX_PROFILING)
Expand Down Expand Up @@ -257,6 +185,8 @@ target_compile_options( traccc_cuda
target_link_libraries( traccc_cuda
PUBLIC traccc::core detray::core vecmem::core
PRIVATE CUDA::cudart traccc::device_common vecmem::cuda covfie::cuda )
target_include_directories( traccc_cuda
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" )

# Set up Thrust specifically for the traccc::cuda library.
thrust_create_target( traccc::cuda_thrust
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Local include(s).
#include "${SOURCE_DIR}/apply_interaction_src.cuh"
#include "src/finding/kernels/specializations/apply_interaction_src.cuh"

// Project include(s).
#include "traccc/geometry/detector.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Local include(s).
#include "${SOURCE_DIR}/find_tracks_src.cuh"
#include "src/finding/kernels/specializations/find_tracks_src.cuh"

// Project include(s).
#include "traccc/geometry/detector.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

// Local include(s).
#include "${SOURCE_DIR}/../../../utils/magnetic_field_types.hpp"
#include "${SOURCE_DIR}/propagate_to_next_surface_src.cuh"
#include "src/utils/magnetic_field_types.hpp"
#include "src/finding/kernels/specializations/propagate_to_next_surface_src.cuh"

// Project include(s).
#include "traccc/finding/details/combinatorial_kalman_filter_types.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

// Local include(s).
#include "${SOURCE_DIR}/../../../utils/magnetic_field_types.hpp"
#include "${SOURCE_DIR}/fit_backward_src.cuh"
#include "src/utils/magnetic_field_types.hpp"
#include "src/fitting/kernels/specializations/fit_backward_src.cuh"

// Project include(s).
#include "traccc/bfield/magnetic_field_types.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

// Local include(s).
#include "${SOURCE_DIR}/../../../utils/magnetic_field_types.hpp"
#include "${SOURCE_DIR}/fit_forward_src.cuh"
#include "src/utils/magnetic_field_types.hpp"
#include "src/fitting/kernels/specializations/fit_forward_src.cuh"

// Project include(s).
#include "traccc/bfield/magnetic_field_types.hpp"
Expand Down
Loading