8000 Add cuda inhomogeneous bfield type by beomki-yeo · Pull Request #1017 · acts-project/traccc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add cuda inhomogeneous bfield type #1017

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 2 commits into
base: main
Choose a base branch
from

Conversation

beomki-yeo
Copy link
Contributor
@beomki-yeo beomki-yeo commented Jun 14, 2025

This PR currently adds instantiations for (1) Host KF with inhomogeneous field (2) CUDA CKF with inhomogeneous field

To-do list

  • Add CUDA KF with inhomogeneous field - Any help?!
  • Add examples with inhomogeneous field
  • Remove old algorithm classes (This can be done later...)
  • Add tests with inhomogeneous fields (This can be done later....)

@beomki-yeo beomki-yeo marked this pull request as draft June 14, 2025 00:12
@beomki-yeo beomki-yeo force-pushed the inhom-field branch 2 times, most recently from ae89132 to ae8aa4a Compare June 17, 2025 00:43
@beomki-yeo
Copy link
Contributor Author

@krasznaa @stephenswat Could you guys check if this is desirable way to include inhomogeneous bfield?

@beomki-yeo
Copy link
Contributor Author

Also feel free to overwrite the PR as it is quite urgent to get the inhomogeneous bfield

Copy link
Member
@krasznaa krasznaa left a comment

Choose a reason for hiding this comment

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

The formalism for providing the typedefs I like as is already. 😇

The exact covfie types to use are absolutely @stephenswat's to tell us. I'll mainly have input on the code structure of the I/O and device libraries.

template <typename scalar_t>
using inhom_bfield_backend_t = covfie::backend::affine<covfie::backend::linear<
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
covfie::backend::cuda_device_array<
Copy link
Member

Choose a reason for hiding this comment

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

@stephenswat is the one to tell us this, but we should try texture memory right away, right? I assume that's a different type.


/// @brief Function that reads the first 4 bytes of a potential bfield file and
/// checks that it contains data for a covfie field
inline bool check_covfie_file(const std::string& file_name) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that inlining this function is really all that useful. 🤔 This is not performance critical code. Just move it's implementation into a read_bfield.cpp file.

Also, let's do fancy C++20. 😉

Suggested change
inline bool check_covfie_file(const std::string& file_name) {
bool check_covfie_file(std::string_view file_name);

Comment on lines 26 to 27
detray::io::file_handle file{file_name,
std::ios_base::in | std::ios_base::binary};
8000 Copy link
Member

Choose a reason for hiding this comment

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

Well, this now made me aware of detray::io::file_handle. Which itself I have some thoughts about. 🤔

But that code really doesn't help us much here, does it? All it does in this case is to perform an explicit check on whether the file could be opened as much as I can see.

I would much rather just open an std::ifstream here, with a check making sure that the file could be successfully opened. Avoiding the thread-unfriendliness of detray::io::file_handle that we'll need to address in that eventually.

Comment on lines +36 to +35
/// @brief function that reads a covfie field from file
template <typename bfield_t>
inline bfield_t read_bfield(const std::string& file_name) {

if (!check_covfie_file(file_name)) {
throw std::runtime_error("Not a valid covfie file: " + file_name);
}

// Open binary file
detray::io::file_handle file{file_name,
std::ios_base::in | std::ios_base::binary};

return bfield_t(*file);
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this function gives us a whole lot. 🤔 I could've imagined a function with an API similar to what we do for the detectors.

https://github.com/acts-project/traccc/blob/main/io/include/traccc/io/read_detector.hpp

I.e. one where we provide a finite set of function overloads for the magnetic field types that we support reading from a binary file. Getting rid of the templating of the user facing function.

But admittedly I don't know enough about covfie still. 😦 What's the general code structure going to be like? I assume we will read in the inhomogeneous field into a host object first, and will copy this into a CUDA, SYCL, etc. field afterwards. I.e. this read function will not be expected to construct a CUDA field directly... right?

@beomki-yeo beomki-yeo force-pushed the inhom-field branch 2 times, most recently from 202c4d5 to e4822a8 Compare June 18, 2025 01:23
@beomki-yeo beomki-yeo requested a review from krasznaa June 18, 2025 01:25
@beomki-yeo beomki-yeo marked this pull request as ready for review June 18, 2025 01:25
@beomki-yeo
Copy link
Contributor Author
beomki-yeo commented Jun 18, 2025

I have to pause here as I am leaving for vacation from Thursday. I will probably make a couple of tests tomorrow but please feel free to take over the PR any time

It was very difficult to extend to inhomogeneous magnetic field so we need to refactor at some point for better maintenance. Having a single type for detector (i.e. default_detector) and bfield (switchable between const and inhom type) might be good as we can remove annoying template and specialization.

@acts-project acts-project deleted a comment from sonarqubecloud bot Jun 18, 2025
const unsigned int new_link_buffer_capacity = std::max(
2 * link_buffer_capacity, links_size + n_max_candidates);
/*
TRACCC_INFO("Link buffer (capacity "
8000 Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah I also couldn't use logger outside the algorithm class.. any thought?

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0