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
Use cuTENSOR in cupy.sum
#2939
Use cuTENSOR in cupy.sum
#2939
Changes from 3 commits
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 |
---|---|---|
|
@@ -23,6 +23,13 @@ if not cupy.cuda.runtime.is_hip: | |
else: | ||
cub = None | ||
|
||
if cupy.cuda.cutensor_enabled: | ||
import cupy_backends.cuda.libs.cutensor as cuda_cutensor | ||
from cupy import cutensor | ||
else: | ||
cuda_cutensor = None | ||
cutensor = None | ||
|
||
|
||
# ndarray members | ||
|
||
|
@@ -95,12 +102,17 @@ cdef ndarray _ndarray_prod(ndarray self, axis, dtype, out, keepdims): | |
|
||
cdef ndarray _ndarray_sum(ndarray self, axis, dtype, out, keepdims): | ||
for accelerator in _accelerator._routine_accelerators: | ||
result = None | ||
if accelerator == _accelerator.ACCELERATOR_CUB: | ||
# result will be None if the reduction is not compatible with CUB | ||
result = cub.cub_reduction( | ||
self, cub.CUPY_CUB_SUM, axis, dtype, out, keepdims) | ||
if result is not None: | ||
return result | ||
if accelerator == _accelerator.ACCELERATOR_CUTENSOR: | ||
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. I think you need to check if 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. does _accelerator allows to set 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. I don't want the routines to fallback to CuPy's default reduction silently in such cases. I will fix 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. By "in such cases" did you mean the library is absent but the user still requests to use it? If so, I think the current implementation makes sense! |
||
result = cutensor._try_reduction_routine( | ||
self, axis, dtype, out, keepdims, cuda_cutensor.OP_ADD, 1, 0) | ||
if result is not None: | ||
return result | ||
|
||
if dtype is None: | ||
return _sum_auto_dtype(self, axis, dtype, out, keepdims) | ||
else: | ||
|
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 this needed?
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.
yes, we want to move everything to
cupy_backends
for these libs.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.
Ah OK.