Skip to content

Conversation

@krasznaa
Copy link
Member

It is possible to simplify how the build would create the specialized kernels for CUDA. While making the code follow standard practices a bit more closely.

I removed the Python script that was doing all this, and switched to simply using configure_file(...). The CMake code still needed to be tweaked slightly to associate workable file names to the type names semi-automatically, but much of the logic of the Python script could be removed.

I tweaked the template files a bit so that their include statements would be easier to handle. And while at it, also renamed them to have the .in postfix. As is the convention for these types of files.

Made the code rely on basic CMake constructs, instead of uding a
custom Python script.
@krasznaa krasznaa added build This relates to the build system cuda Changes related to CUDA labels Sep 19, 2025
@sonarqubecloud
Copy link

Copy link
Member

@stephenswat stephenswat left a comment

Choose a reason for hiding this comment

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

What? No. This is replacing a semi-robust solution by a really half-assed solution. If you insist on doing this all via CMake, do the following:

Comment on lines +114 to +133
# 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}}")
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()
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.

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.

Comment on lines +141 to +143
foreach(BFIELD_NAME "const_bfield_backend_t<scalar>"
"inhom_global_bfield_backend_t<scalar>"
"inhom_texture_bfield_backend_t")
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.

@krasznaa
Copy link
Member Author

I can make the local CMake function more complicated if absolutely necessary. Though I don't see the code maintenance goal here. The functions/macros are defined, and then are used right away in the same place. For one very specific thing. The goal is not to introduce general, widely usable code here. Since at best it's only HIP that will also be able to make use of this.

I also really don't understand why you think that this would be anything but more robust than the current code. 😕 The Python code has a lot of special if statements in it. As soon as some new typename will be introduced, the script will very likely have to be updated as well.. While this PR's code only has one specialization for producing a valid file name from characters that are not good to have in file names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build This relates to the build system cuda Changes related to CUDA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants