Skip to content
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

Reorder Jacobian calculation #707

Merged
merged 13 commits into from
Feb 11, 2025
Merged

Reorder Jacobian calculation #707

merged 13 commits into from
Feb 11, 2025

Conversation

mattldawson
Copy link
Collaborator

@mattldawson mattldawson commented Jan 9, 2025

Reorders the Jacobian calculation to be column-wise instead of random.

A few minor changes were made to tolerances in the analytical tests. Also, some of the tutorial examples were taking a long time, so I modified the rate constant parameters

closes #720

@sjsprecious
Copy link
Collaborator

The computational benefit of using this PR is around 10% for some functions and we decide not to pursue it further since the failing tests are unclear to us and the benefit is not a lot.

@sjsprecious
Copy link
Collaborator

@mattldawson sorry I am wrong here. This PR is crucial to achieving the impressing performance from nvhpc and gcc compilers. I would like to see if we can resolve the failed integration tests and merge in this PR later.

@sjsprecious sjsprecious reopened this Jan 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 98.51852% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.48%. Comparing base (b342305) to head (aead53e).

Files with missing lines Patch % Lines
include/micm/process/process_set.hpp 97.67% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #707      +/-   ##
==========================================
- Coverage   94.50%   94.48%   -0.02%     
==========================================
  Files          64       64              
  Lines        4384     4406      +22     
==========================================
+ Hits         4143     4163      +20     
- Misses        241      243       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattldawson mattldawson marked this pull request as ready for review February 6, 2025 21:49
cudaMallocAsync(
&(devstruct.jacobian_process_info_),
jacobian_process_info_bytes,
micm::cuda::CudaStreamSingleton::GetInstance().GetCudaStream(0)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we save micm::cuda::CudaStreamSingleton::GetInstance().GetCudaStream(0) to a local variable and simplify the interface here?

@@ -266,12 +325,26 @@ namespace micm
if (devstruct.yields_ != nullptr)
CHECK_CUDA_ERROR(
cudaFreeAsync(devstruct.yields_, micm::cuda::CudaStreamSingleton::GetInstance().GetCudaStream(0)), "cudaFree");
if (devstruct.jacobian_process_info_ != nullptr)
CHECK_CUDA_ERROR(
cudaFreeAsync(devstruct.jacobian_process_info_, micm::cuda::CudaStreamSingleton::GetInstance().GetCudaStream(0)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we save micm::cuda::CudaStreamSingleton::GetInstance().GetCudaStream(0) to a local variable and simplify the interface here?

Copy link
Collaborator

@sjsprecious sjsprecious left a comment

Choose a reason for hiding this comment

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

Thanks @mattldawson for working on this PR. I could confirm that with your recent fix, the CUDA performance is the same as the main branch now.

Somehow the nvhpc performance drops a lot due to this PR on Derecho, but we may investigate it separately unless you see another obvious improvement quickly.

Only have a minor comment about the iterator.

const std::size_t idx_state_variables = offset_state + (react_id[i_react] * L);
auto v_state_variables_it = v_state_variables.begin() + idx_state_variables;
for (std::size_t i_cell = 0; i_cell < L; ++i_cell)
d_rate_d_ind[i_cell] *= *(v_state_variables_it++);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use iterator for d_rate_d_ind?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

{
auto v_jacobian_it = v_jacobian.begin() + offset_jacobian + *flat_id;
for (std::size_t i_cell = 0; i_cell < L; ++i_cell)
*(v_jacobian_it++) += d_rate_d_ind[i_cell];
Copy link
Collaborator

Choose a reason for hiding this comment

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

use iterator for d_rate_d_ind?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

auto v_jacobian_it = v_jacobian.begin() + offset_jacobian + *flat_id;
auto yield_value = yield[i_dep];
for (std::size_t i_cell = 0; i_cell < L; ++i_cell)
*(v_jacobian_it++) -= yield_value * d_rate_d_ind[i_cell];
Copy link
Collaborator

Choose a reason for hiding this comment

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

use iterator for d_rate_d_ind?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

@mattldawson mattldawson merged commit cbdc7bf into main Feb 11, 2025
27 checks passed
@mattldawson mattldawson deleted the develop-reorder-jacobian branch February 11, 2025 15:57
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.

Reorder Jacobian calculations
3 participants