-
Notifications
You must be signed in to change notification settings - Fork 4.7k
PyTorchAlpaka: Batched inference with TensorCollections, eval and frozen model, FP16 convsersion support #50498
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
Closed
EmanueleCoradin
wants to merge
1
commit into
cms-sw:master
from
EmanueleCoradin:batched-inference-PR
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #ifndef FPX_h | ||
| #define FPX_h | ||
|
|
||
| #include <limits> | ||
|
|
||
| #if defined ALPAKA_ACC_GPU_CUDA_ENABLED | ||
| #include <cuda_fp16.h> | ||
| #endif | ||
|
|
||
| /* | ||
| * Portable floating-point precision abstraction for CPU/GPU execution. | ||
| * | ||
| * This header defines a unified floating-point type `FPX` that maps to: | ||
| * - `__half` (FP16) when compiled with CUDA GPU support | ||
| * - `float` (FP32) otherwise | ||
| * | ||
| * It is designed to exploit half-precision acceleration on GPUs. | ||
| */ | ||
|
|
||
| #if defined ALPAKA_ACC_GPU_CUDA_ENABLED | ||
| /* | ||
| * GPU (CUDA) implementation: | ||
| * Uses native IEEE-754 half precision (`__half`) type. | ||
| * Provides explicit conversion helpers between float and half. | ||
| */ | ||
| #define __F2H __float2half | ||
| #define __H2F __half2float | ||
| typedef __half FPX; | ||
|
|
||
| __host__ __device__ inline FPX makeNaN() { return __float2half(std::numeric_limits<float>::quiet_NaN()); } | ||
|
|
||
| #else | ||
| /* | ||
| * CPU fallback implementation: | ||
| * Uses standard 32-bit floating point arithmetic. | ||
| */ | ||
| #define __F2H | ||
| #define __H2F | ||
| typedef float FPX; | ||
|
|
||
| inline FPX makeNaN() { return std::numeric_limits<FPX>::quiet_NaN(); } | ||
|
|
||
| #endif | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,16 @@ | |
| #include <Eigen/Dense> | ||
|
|
||
| #include "DataFormats/Common/interface/StdArray.h" | ||
| #include "DataFormats/Common/interface/FPX.h" | ||
| #include "DataFormats/SoATemplate/interface/SoACommon.h" | ||
| #include "DataFormats/SoATemplate/interface/SoALayout.h" | ||
|
|
||
| namespace portabletest { | ||
|
|
||
| GENERATE_SOA_LAYOUT(ParticleLayout, SOA_COLUMN(float, pt), SOA_COLUMN(float, eta), SOA_COLUMN(float, phi)) | ||
| using ParticleSoA = ParticleLayout<>; | ||
| GENERATE_SOA_LAYOUT(ParticleLayoutFPX, SOA_COLUMN(FPX, pt), SOA_COLUMN(FPX, eta), SOA_COLUMN(FPX, phi)) | ||
| using ParticleSoAFPX = ParticleLayoutFPX<>; | ||
|
Comment on lines
+16
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of The code compiled with |
||
|
|
||
| } // namespace portabletest | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef PhysicsTools_PyTorch_interface_PyTorchFPXBridge_h | ||
| #define PhysicsTools_PyTorch_interface_PyTorchFPXBridge_h | ||
|
|
||
| #if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) | ||
|
|
||
| #include <cuda_fp16.h> | ||
| #include <c10/core/ScalarType.h> | ||
|
|
||
| namespace c10 { | ||
|
|
||
| /* | ||
| * Map CUDA half precision type to PyTorch scalar type. | ||
| */ | ||
| template <> | ||
| struct CppTypeToScalarType<__half> { | ||
| static constexpr ScalarType value = ScalarType::Half; | ||
| }; | ||
|
|
||
| } // namespace c10 | ||
|
|
||
| #endif // ALPAKA_ACC_GPU_CUDA_ENABLED | ||
|
|
||
| #endif // PhysicsTools_PyTorch_interface_PyTorchFPXBridge_h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
DataFormats/Math(orHeterogeneousCore/AlpakaMath) would be a better place for this code.