-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Fix inclusive sum overlfow when applied on int8_t buffer in Compress #9295
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
Changes from 2 commits
bfd3fc9
45819b9
62c931b
c196d33
2efdc58
5b6d7d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,16 +13,31 @@ | |
|
|
||
| #include "core/providers/cuda/tensor/compress_impl.h" | ||
|
|
||
| #include <thrust/scan.h> | ||
| #include <thrust/iterator/transform_iterator.h> | ||
| #include <thrust/functional.h> | ||
|
|
||
| namespace onnxruntime { | ||
| namespace cuda { | ||
|
|
||
| // This cast is for transform iterator. This type affects the accumulator type width | ||
| // in InclusiveSum() and int8_t overflows. | ||
| struct CastToIn32 : public thrust::unary_function<int8_t, int32_t> { | ||
|
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. "CastToIn32" -> "CastToInt32" #Resolved |
||
| __host__ __device__ int32_t operator()(int8_t v) const { | ||
| return static_cast<int32_t>(v); | ||
| } | ||
| }; | ||
|
|
||
| cudaError_t CompressCalcPrefixSumTempStorageBytes(cudaStream_t stream, const int8_t* condition_data, int* condition_cumulative_sum, int length, size_t& temp_storage_bytes) { | ||
| return cub::DeviceScan::InclusiveSum( | ||
| nullptr, temp_storage_bytes, condition_data, condition_cumulative_sum, length, stream); | ||
| auto input_iter = thrust::make_transform_iterator(condition_data, CastToIn32()); | ||
|
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. is it possible for |
||
| return cub::DeviceScan::InclusiveSum( | ||
| nullptr, temp_storage_bytes, input_iter, condition_cumulative_sum, length, stream); | ||
| } | ||
|
|
||
| cudaError_t CompressInclusivePrefixSum(cudaStream_t stream, void* d_temp_storage, size_t temp_storage_bytes, const int8_t* condition_data, int* condition_cumulative_sum, int length) { | ||
| auto input_iter = thrust::make_transform_iterator(condition_data, CastToIn32()); | ||
| return cub::DeviceScan::InclusiveSum( | ||
| d_temp_storage, temp_storage_bytes, condition_data, condition_cumulative_sum, length, stream); | ||
| d_temp_storage, temp_storage_bytes, input_iter, condition_cumulative_sum, length, stream); | ||
| } | ||
|
|
||
| template <typename T> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
is thrust/scan.h needed? #Resolved