Skip to content

Keep states ordered by quality in CKF #929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
106 changes: 59 additions & 47 deletions device/alpaka/src/finding/finding_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,57 +250,69 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
links_buffer = std::move(new_links_buffer);
}

Idx blocksPerGrid =
(n_in_params + threadsPerBlock - 1) / threadsPerBlock;
auto workDiv = makeWorkDiv<Acc>(blocksPerGrid, threadsPerBlock);
{
vecmem::data::vector_buffer<candidate_link> tmp_links_buffer(
n_max_candidates, m_mr.main);
m_copy.setup(tmp_links_buffer)->ignore();
bound_track_parameters_collection_types::buffer
tmp_params_buffer(n_max_candidates, m_mr.main);
m_copy.setup(tmp_params_buffer)->ignore();

const unsigned int prev_link_idx =
step == 0 ? 0 : step_to_link_idx_map[step - 1];

assert(links_size == step_to_link_idx_map[step]);

typedef device::find_tracks_payload<std::decay_t<detector_type>>
PayloadType;

auto bufHost_payload =
::alpaka::allocBuf<PayloadType, Idx>(devHost, 1u);
PayloadType* payload = ::alpaka::getPtrNative(bufHost_payload);

new (payload) PayloadType{
.det_data = det_view,
.measurements_view = measurements,
.in_params_view = vecmem::get_data(in_params_buffer),
.in_params_liveness_view =
vecmem::get_data(param_liveness_buffer),
.n_in_params = n_in_params,
.barcodes_view = vecmem::get_data(barcodes_buffer),
.upper_bounds_view = vecmem::get_data(upper_bounds_buffer),
.links_view = vecmem::get_data(links_buffer),
.prev_links_idx = prev_link_idx,
.curr_links_idx = step_to_link_idx_map[step],
.step = step,
.out_params_view = vecmem::get_data(updated_params_buffer),
.out_params_liveness_view =
vecmem::get_data(updated_liveness_buffer)};

auto bufAcc_payload =
::alpaka::allocBuf<PayloadType, Idx>(devAcc, 1u);
::alpaka::memcpy(queue, bufAcc_payload, bufHost_payload);
::alpaka::wait(queue);
Idx blocksPerGrid =
(n_in_params + threadsPerBlock - 1) / threadsPerBlock;
auto workDiv = makeWorkDiv<Acc>(blocksPerGrid, threadsPerBlock);

::alpaka::exec<Acc>(queue, workDiv,
FindTracksKernel<std::decay_t<detector_type>>{},
m_cfg, ::alpaka::getPtrNative(bufAcc_payload));
::alpaka::wait(queue);
const unsigned int prev_link_idx =
step == 0 ? 0 : step_to_link_idx_map[step - 1];

std::swap(in_params_buffer, updated_params_buffer);
std::swap(param_liveness_buffer, updated_liveness_buffer);
assert(links_size == step_to_link_idx_map[step]);

// Create a buffer for links
step_to_link_idx_map[step + 1] = m_copy.get_size(links_buffer);
n_candidates =
step_to_link_idx_map[step + 1] - step_to_link_idx_map[step];
::alpaka::wait(queue);
typedef device::find_tracks_payload<std::decay_t<detector_type>>
PayloadType;

auto bufHost_payload =
::alpaka::allocBuf<PayloadType, Idx>(devHost, 1u);
PayloadType* payload = ::alpaka::getPtrNative(bufHost_payload);

new (payload) PayloadType{
.det_data = det_view,
.measurements_view = measurements,
.in_params_view = vecmem::get_data(in_params_buffer),
.in_params_liveness_view =
vecmem::get_data(param_liveness_buffer),
.n_in_params = n_in_params,
.barcodes_view = vecmem::get_data(barcodes_buffer),
.upper_bounds_view = vecmem::get_data(upper_bounds_buffer),
.links_view = vecmem::get_data(links_buffer),
.prev_links_idx = prev_link_idx,
.curr_links_idx = step_to_link_idx_map[step],
.step = step,
.out_params_view = vecmem::get_data(updated_params_buffer),
.out_params_liveness_view =
vecmem::get_data(updated_liveness_buffer),
.tmp_params_view = tmp_params_buffer,
.tmp_links_view = tmp_links_buffer};

auto bufAcc_payload =
::alpaka::allocBuf<PayloadType, Idx>(devAcc, 1u);
::alpaka::memcpy(queue, bufAcc_payload, bufHost_payload);
::alpaka::wait(queue);

::alpaka::exec<Acc>(
queue, workDiv,
FindTracksKernel<std::decay_t<detector_type>>{}, m_cfg,
::alpaka::getPtrNative(bufAcc_payload));
::alpaka::wait(queue);

std::swap(in_params_buffer, updated_params_buffer);
std::swap(param_liveness_buffer, updated_liveness_buffer);

// Create a buffer for links
step_to_link_idx_map[step + 1] = m_copy.get_size(links_buffer);
n_candidates =
step_to_link_idx_map[step + 1] - step_to_link_idx_map[step];
::alpaka::wait(queue);
}
}

if (n_candidates > 0) {
Expand Down
14 changes: 10 additions & 4 deletions device/alpaka/src/finding/kernels/find_tracks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ struct FindTracksKernel {
TAcc const& acc, const finding_config& cfg,
device::find_tracks_payload<detector_t>* payload) const {

auto& shared_num_out_params =
::alpaka::declareSharedVar<unsigned int, __COUNTER__>(acc);
auto& shared_out_offset =
::alpaka::declareSharedVar<unsigned int, __COUNTER__>(acc);
auto& shared_candidates_size =
::alpaka::declareSharedVar<unsigned int, __COUNTER__>(acc);
unsigned int* const s = ::alpaka::getDynSharedMem<unsigned int>(acc);
unsigned int* shared_num_candidates = s;
unsigned long long int* const s =
::alpaka::getDynSharedMem<unsigned long long int>(acc);
unsigned long long int* shared_insertion_mutex = s;

alpaka::barrier<TAcc> barrier(&acc);
details::thread_id1 thread_id(acc);

unsigned int blockDimX = thread_id.getBlockDimX();
std::pair<unsigned int, unsigned int>* shared_candidates =
reinterpret_cast<std::pair<unsigned int, unsigned int>*>(
&shared_num_candidates[blockDimX]);
&shared_insertion_mutex[blockDimX]);

device::find_tracks<detector_t>(
thread_id, barrier, cfg, *payload,
{shared_num_candidates, shared_candidates, shared_candidates_size});
{shared_num_out_params, shared_out_offset, shared_insertion_mutex,
shared_candidates, shared_candidates_size});
}
};

Expand Down
30 changes: 27 additions & 3 deletions device/common/include/traccc/finding/device/find_tracks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <vecmem/containers/data/vector_view.hpp>

// System include(s).
#include <cstdint>
#include <utility>

namespace traccc::device {
Expand Down Expand Up @@ -98,15 +99,38 @@ struct find_tracks_payload {
* @brief View object to the output track parameter liveness vector
*/
vecmem::data::vector_view<unsigned int> out_params_liveness_view;

/**
* @brief View object to the temporary track parameter vector
*/
bound_track_parameters_collection_types::view tmp_params_view;

/**
* @brief View object to the temporary link vector
*/
vecmem::data::vector_view<candidate_link> tmp_links_view;
};

/// (Shared Event Data) Payload for the @c traccc::device::find_tracks function
struct find_tracks_shared_payload {
/**
* @brief Shared-memory vector with the number of measurements found per
* track
* @brief Shared-memory value indicating the final number of track
* parameters to write to permanent storage.
*/
unsigned int& shared_num_out_params;

/**
* @brief Shared-memory value indicating the offset at which the block
* will write its parameters.
*/
unsigned int& shared_out_offset;

/**
* @brief Shared-memory array with mutexes for the insertionof parameters.
*
* @note Length is always exactly the block size.
*/
unsigned int* shared_num_candidates;
unsigned long long int* shared_insertion_mutex;

/**
* @brief Shared-memory vector of measurement candidats with ID and
Expand Down
Loading
Loading