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

Add support of cuda kernels as pullback functions #1114

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

kchristin22
Copy link
Collaborator

No description provided.

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

Attention: Patch coverage is 96.70330% with 3 lines in your changes missing coverage. Please review.

Project coverage is 94.38%. Comparing base (2d08ce1) to head (51ae88f).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
lib/Differentiator/ReverseModeVisitor.cpp 96.10% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1114      +/-   ##
==========================================
+ Coverage   94.36%   94.38%   +0.01%     
==========================================
  Files          50       50              
  Lines        8365     8744     +379     
==========================================
+ Hits         7894     8253     +359     
- Misses        471      491      +20     
Files with missing lines Coverage Δ
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
include/clad/Differentiator/ReverseModeVisitor.h 97.32% <ø> (+0.09%) ⬆️
include/clad/Differentiator/VisitorBase.h 100.00% <ø> (ø)
lib/Differentiator/CladUtils.cpp 94.40% <100.00%> (+0.30%) ⬆️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/VisitorBase.cpp 97.28% <100.00%> (+0.13%) ⬆️
lib/Differentiator/ReverseModeVisitor.cpp 95.51% <96.10%> (+<0.01%) ⬆️

... and 26 files with indirect coverage changes

Files with missing lines Coverage Δ
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
include/clad/Differentiator/ReverseModeVisitor.h 97.32% <ø> (+0.09%) ⬆️
include/clad/Differentiator/VisitorBase.h 100.00% <ø> (ø)
lib/Differentiator/CladUtils.cpp 94.40% <100.00%> (+0.30%) ⬆️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/VisitorBase.cpp 97.28% <100.00%> (+0.13%) ⬆️
lib/Differentiator/ReverseModeVisitor.cpp 95.51% <96.10%> (+<0.01%) ⬆️

... and 26 files with indirect coverage changes

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

include/clad/Differentiator/DiffPlanner.h Outdated Show resolved Hide resolved
include/clad/Differentiator/ReverseModeVisitor.h Outdated Show resolved Hide resolved
include/clad/Differentiator/ReverseModeVisitor.h Outdated Show resolved Hide resolved
lib/Differentiator/ErrorEstimator.cpp Outdated Show resolved Hide resolved
lib/Differentiator/MultiplexExternalRMVSource.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

include/clad/Differentiator/DiffPlanner.h Outdated Show resolved Hide resolved
include/clad/Differentiator/ReverseModeVisitor.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
include/clad/Differentiator/ExternalRMVSource.h Outdated Show resolved Hide resolved
include/clad/Differentiator/DerivativeBuilder.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
test/CUDA/GradientKernels.cu Outdated Show resolved Hide resolved
test/CUDA/GradientKernels.cu Outdated Show resolved Hide resolved
//CHECK-NEXT: cudaMemcpyKind _r1 = static_cast<cudaMemcpyKind>(0U);
//CHECK-NEXT: clad::custom_derivatives::cudaMemcpy_pullback(out_host, out, 10 * sizeof(double), cudaMemcpyDeviceToHost, _d_out_host, _d_out, &_r0, &_r1);
//CHECK-NEXT: }
//CHECK-NEXT: kernel_call_pullback<<<1, 10>>>(out, in, _d_out, _d_in);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we call cudaDeviceSynchronize before cudaFree calls?

Copy link
Collaborator Author

@kchristin22 kchristin22 Oct 21, 2024

Choose a reason for hiding this comment

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

These should be executed in order so no need
Edit: meaning the previous GPU ops will finish before free is executed as they are all executed in the default stream. Maybe it would be worth it to add them in case the user uses another stream for the kernel, as they should also include cudaDeviceSynchronize() in the original kernel. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

meaning the previous GPU ops will finish before free is executed as they are all executed in the default stream.

What if there are no cudaFree calls? Should we call cudaDeviceSynchronize in that case?

Maybe it would be worth it to add them in case the user uses another stream for the kernel, as they should also include cudaDeviceSynchronize() in the original kernel. What do you think?

I believe we should not add additional cudaDeviceSynchronize calls because of multiple streams currently. We can add support for multiple stream by adding extra synchronization calls if the need arises.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are supported for derivative kernel execution though. I can remove the cudaDeviceSynchronize calls from cudaMemcpy_pullback, but I think it doesn't hurt to keep them, as they will be added in the future either way.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

include/clad/Differentiator/BuiltinDerivatives.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
test/CUDA/GradientKernels.cu Outdated Show resolved Hide resolved
test/CUDA/GradientKernels.cu Outdated Show resolved Hide resolved
test/CUDA/GradientKernels.cu Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Differentiator/VisitorBase.cpp Outdated Show resolved Hide resolved
lib/Differentiator/VisitorBase.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Differentiator/ReverseModeVisitor.cpp Show resolved Hide resolved
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

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