Skip to content

Commit

Permalink
Merge pull request #451 from CrossR/alpaka_second_example
Browse files Browse the repository at this point in the history
Alpaka: Seed Finding
  • Loading branch information
beomki-yeo committed Mar 5, 2024
2 parents 8d13bd8 + 0de5a16 commit 1bde8d9
Show file tree
Hide file tree
Showing 20 changed files with 1,118 additions and 192 deletions.
69 changes: 69 additions & 0 deletions cmake/traccc-alpaka-functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# TRACCC library, part of the ACTS project (R&D line)
#
# (c) 2024 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

cmake_minimum_required( VERSION 3.16 )

# Guard against multiple includes.
include_guard( GLOBAL )

# Function for declaring the libraries of the project.
# This version calls the alpaka_add_library() function to create the library,
# which is setup to use the correct compiler flags depending on the build type.
#
# Usage: traccc_add_alpaka_library( traccc_core core
# [TYPE SHARED/INTERFACE/STATIC]
# include/source1.hpp source2.cpp )
#
function( traccc_add_alpaka_library fullname basename )

# Parse the function's options.
cmake_parse_arguments( ARG "" "TYPE" "" ${ARGN} )

# Decide what sources to give to the library.
set( _sources ${ARG_UNPARSED_ARGUMENTS} )
if( "${ARG_TYPE}" STREQUAL "INTERFACE" )
set( _sources )
endif()

# Create the library.
alpaka_add_library( ${fullname} ${ARG_TYPE} ${_sources} )

# Set up how clients should find its headers.
if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" )
set( _depType PUBLIC )
if( "${ARG_TYPE}" STREQUAL "INTERFACE" )
set( _depType INTERFACE )
endif()
target_include_directories( ${fullname} ${_depType}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
unset( _depType )
endif()

# Make sure that the library is available as "traccc::${basename}" in every
# situation.
set_target_properties( ${fullname} PROPERTIES EXPORT_NAME ${basename} )
add_library( traccc::${basename} ALIAS ${fullname} )

# Specify the (SO)VERSION of the library.
if( NOT "${ARG_TYPE}" STREQUAL "INTERFACE" )
set_target_properties( ${fullname} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR} )
endif()

# Set up the installation of the library and its headers.
install( TARGETS ${fullname}
EXPORT traccc-exports
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" )
if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" )
install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" )
endif()

endfunction( traccc_add_alpaka_library )
4 changes: 4 additions & 0 deletions cmake/traccc-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set( TRACCC_BUILD_CUDA @TRACCC_BUILD_CUDA@ )
set( TRACCC_BUILD_SYCL @TRACCC_BUILD_SYCL@ )
set( TRACCC_BUILD_FUTHARK @TRACCC_BUILD_FUTHARK@ )
set( TRACCC_BUILD_KOKKOS @TRACCC_BUILD_KOKKOS@ )
set( TRACCC_BUILD_ALPAKA @TRACCC_BUILD_ALPAKA@ )
set( TRACCC_BUILD_EXAMPLES @TRACCC_BUILD_EXAMPLES@ )
set( TRACCC_USE_ROOT @TRACCC_USE_ROOT@ )

Expand All @@ -32,6 +33,9 @@ find_dependency( dfelibs )
if( TRACCC_BUILD_KOKKOS )
find_dependency( Kokkos )
endif()
if( TRACCC_BUILD_ALPAKA )
find_dependency( alpaka )
endif()
if( TRACCC_BUILD_FUTHARK )
find_dependency( Futhark )
endif()
Expand Down
36 changes: 15 additions & 21 deletions device/alpaka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,33 @@
# Mozilla Public License Version 2.0

# Project include(s).
include( traccc-alpaka-functions )
include( traccc-compiler-options-cpp )

set(PUBLIC_LIBRARIES traccc::core detray::core detray::utils vecmem::core covfie::core)
set(PRIVATE_LIBRARIES traccc::device_common alpaka::alpaka)

if(alpaka_ACC_GPU_CUDA_ENABLE)
enable_language(CUDA)
find_package( CUDAToolkit REQUIRED )

include( traccc-compiler-options-cuda )

set_source_files_properties(src/utils/make_prefix_sum_buff.cpp PROPERTIES LANGUAGE CUDA)
set_source_files_properties(src/seeding/spacepoint_binning.cpp PROPERTIES LANGUAGE CUDA)
elseif(alpaka_ACC_GPU_HIP_ENABLE)
enable_language(HIP)

set_source_files_properties(src/utils/make_prefix_sum_buff.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(src/seeding/spacepoint_binning.cpp PROPERTIES LANGUAGE HIP)
list(APPEND PRIVATE_LIBRARIES CUDA::cudart vecmem::cuda)
endif()

traccc_add_library( traccc_alpaka alpaka TYPE SHARED
traccc_add_alpaka_library( traccc_alpaka alpaka TYPE SHARED
# Utility definitions.
"include/traccc/alpaka/utils/definitions.hpp"
"include/traccc/alpaka/utils/make_prefix_sum_buff.hpp"
"src/utils/make_prefix_sum_buff.cpp"
# Seed finding code.
# Seed finding includes
"include/traccc/alpaka/seeding/spacepoint_binning.hpp"
"include/traccc/alpaka/seeding/seed_finding.hpp"
"include/traccc/alpaka/seeding/seeding_algorithm.hpp"
"include/traccc/alpaka/seeding/track_params_estimation.hpp"
# Seeding code
"src/seeding/spacepoint_binning.cpp"
"src/seeding/seed_finding.cpp"
"src/seeding/seeding_algorithm.cpp"
"src/seeding/track_params_estimation.cpp"
)

if(alpaka_ACC_GPU_CUDA_ENABLE)
target_link_libraries( traccc_alpaka
PUBLIC traccc::core vecmem::core
PRIVATE CUDA::cudart traccc::device_common vecmem::cuda alpaka::alpaka)
else()
target_link_libraries( traccc_alpaka
PUBLIC traccc::core vecmem::core
PRIVATE traccc::device_common alpaka::alpaka)
endif()
target_link_libraries(traccc_alpaka PUBLIC ${PUBLIC_LIBRARIES} PRIVATE ${PRIVATE_LIBRARIES})
61 changes: 61 additions & 0 deletions device/alpaka/include/traccc/alpaka/seeding/seed_finding.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "traccc/edm/seed.hpp"
#include "traccc/edm/spacepoint.hpp"
#include "traccc/seeding/detail/seeding_config.hpp"
#include "traccc/seeding/detail/spacepoint_grid.hpp"
#include "traccc/utils/algorithm.hpp"
#include "traccc/utils/memory_resource.hpp"

// VecMem include(s).
#include <vecmem/utils/copy.hpp>

// System include(s).
#include <functional>

namespace traccc::alpaka {

/// Seed finding for alpaka
class seed_finding : public algorithm<seed_collection_types::buffer(
const spacepoint_collection_types::const_view&,
const sp_grid_const_view&)> {

public:
/// Constructor for the alpaka seed finding
///
/// @param config is seed finder configuration parameters
/// @param filter_config is seed filter configuration parameters
/// @param sp_grid spacepoint grid
/// @param mr vecmem memory resource
/// @param copy The copy object to use for copying data between device
/// and host memory blocks
seed_finding(const seedfinder_config& config,
const seedfilter_config& filter_config,
const traccc::memory_resource& mr, vecmem::copy& copy);

/// Callable operator for the seed finding
///
/// @param spacepoints_view is a view of all spacepoints in the event
/// @param g2_view is a view of the spacepoint grid
/// @return a vector buffer of seeds
///
output_type operator()(
const spacepoint_collection_types::const_view& spacepoints_view,
const sp_grid_const_view& g2_view) const override;

private:
seedfinder_config m_seedfinder_config;
seedfilter_config m_seedfilter_config;
traccc::memory_resource m_mr;
vecmem::copy& m_copy;
};

} // namespace traccc::alpaka
60 changes: 60 additions & 0 deletions device/alpaka/include/traccc/alpaka/seeding/seeding_algorithm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Library include(s).
#include "traccc/alpaka/seeding/seed_finding.hpp"
#include "traccc/alpaka/seeding/spacepoint_binning.hpp"

// Project include(s).
#include "traccc/edm/seed.hpp"
#include "traccc/edm/spacepoint.hpp"
#include "traccc/utils/algorithm.hpp"

// VecMem include(s).
#include <vecmem/memory/memory_resource.hpp>

// traccc library include(s).
#include "traccc/utils/memory_resource.hpp"

namespace traccc::alpaka {

/// Main algorithm for performing the track seeding on in alpaka
class seeding_algorithm : public algorithm<seed_collection_types::buffer(
const spacepoint_collection_types::const_view&)> {

public:
/// Constructor for the seed finding algorithm
///
/// @param mr The memory resource to use
/// @param mr The memory resource(s) to use in the algorithm
/// @param copy The copy object to use for copying data between device
/// and host memory blocks
///
seeding_algorithm(const seedfinder_config& finder_config,
const spacepoint_grid_config& grid_config,
const seedfilter_config& filter_config,
const traccc::memory_resource& mr, vecmem::copy& copy);

/// Operator executing the algorithm.
///
/// @param spacepoints_view is a view of all spacepoints in the event
/// @return the buffer of track seeds reconstructed from the spacepoints
///
output_type operator()(const spacepoint_collection_types::const_view&
spacepoints_view) const override;

private:
/// Sub-algorithm performing the spacepoint binning
spacepoint_binning m_spacepoint_binning;
/// Sub-algorithm performing the seed finding
seed_finding m_seed_finding;

}; // class seeding_algorithm

} // namespace traccc::alpaka
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

#pragma once

// Local include(s).
#include "traccc/alpaka/utils/definitions.hpp"

// Project include(s).
#include "traccc/edm/spacepoint.hpp"
#include "traccc/seeding/detail/seeding_config.hpp"
#include "traccc/seeding/detail/spacepoint_grid.hpp"
#include "traccc/utils/algorithm.hpp"
#include "traccc/utils/memory_resource.hpp"

// VecMem include(s).
#include <vecmem/utils/copy.hpp>

// System include(s).
#include <memory>
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "traccc/edm/cell.hpp"
#include "traccc/edm/seed.hpp"
#include "traccc/edm/spacepoint.hpp"
#include "traccc/edm/track_parameters.hpp"
#include "traccc/utils/algorithm.hpp"
#include "traccc/utils/memory_resource.hpp"

// VecMem include(s).
#include <vecmem/utils/copy.hpp>

namespace traccc::alpaka {

/// track parameter estimation for alpaka
struct track_params_estimation
: public algorithm<bound_track_parameters_collection_types::buffer(
const spacepoint_collection_types::const_view&,
const seed_collection_types::const_view&,
const cell_module_collection_types::const_view&, const vector3&,
const std::array<traccc::scalar, traccc::e_bound_size>&)> {

public:
/// Constructor for track_params_estimation
///
/// @param mr is the memory resource
/// @param copy The copy object to use for copying data between device
/// and host memory blocks
track_params_estimation(const traccc::memory_resource& mr,
vecmem::copy& copy);

/// Callable operator for track_params_estimation
///
/// @param spacepoints All spacepoints of the event
/// @param seeds The reconstructed track seeds of the event
/// @param modules Geometry module vector
/// @param bfield (Temporary) Magnetic field vector
/// @param stddev standard deviation for setting the covariance (Default
/// value from arXiv:2112.09470v1)
/// @return A vector of bound track parameters
///
output_type operator()(
const spacepoint_collection_types::const_view& spacepoints_view,
const seed_collection_types::const_view& seeds_view,
const cell_module_collection_types::const_view& modules_view,
const vector3& bfield,
const std::array<traccc::scalar, traccc::e_bound_size>& = {
0.02 * detray::unit<traccc::scalar>::mm,
0.03 * detray::unit<traccc::scalar>::mm,
1. * detray::unit<traccc::scalar>::degree,
1. * detray::unit<traccc::scalar>::degree,
0.01 / detray::unit<traccc::scalar>::GeV,
1 * detray::unit<traccc::scalar>::ns}) const override;

private:
/// Memory resource used by the algorithm
traccc::memory_resource m_mr;
/// Copy object used by the algorithm
vecmem::copy& m_copy;
};

} // namespace traccc::alpaka
25 changes: 0 additions & 25 deletions device/alpaka/include/traccc/alpaka/utils/definitions.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ namespace traccc::alpaka {
/// @param copy A "copy object" capable of dealing with the view
/// @return A vector buffer of prefix_sum element
///
template <typename Acc, typename Queue, typename BufAcc>
vecmem::data::vector_buffer<device::prefix_sum_element_t> make_prefix_sum_buff(
const std::vector<device::prefix_sum_size_t>& sizes, vecmem::copy& copy,
const traccc::memory_resource& mr, Queue& queue, BufAcc& bufAcc);
const traccc::memory_resource& mr, Queue& queue);

} // namespace traccc::alpaka
Loading

0 comments on commit 1bde8d9

Please sign in to comment.