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

Support all fp types in GPU SparseTensorDenseMatMul #47419

Conversation

benbarsdell
Copy link
Contributor

Adds Eigen::half for CPU, and Eigen::half, double, and complex for GPU.

cc @nluehr

@google-ml-butler google-ml-butler bot added the size:S CL Change Size: Small label Feb 26, 2021
@google-cla google-cla bot added the cla: yes label Feb 26, 2021
@benbarsdell
Copy link
Contributor Author

I'm investigating the test failures.

@gbaned gbaned self-assigned this Feb 26, 2021
@gbaned gbaned added the comp:core issues related to core part of tensorflow label Feb 26, 2021
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Feb 26, 2021
@gbaned gbaned requested review from sanjoy and allenlavoie and removed request for sanjoy February 26, 2021 04:01
- Adds GPU registrations for double and complex types.
- Also adds correct conjugation in the GPU kernel.
@benbarsdell benbarsdell force-pushed the gpu-SparseTensorDenseMatMul-all-types branch from d499701 to e377b73 Compare February 26, 2021 12:32
@benbarsdell benbarsdell changed the title Add type registrations for SparseTensorDenseMatMul Support all fp types in GPU SparseTensorDenseMatMul Feb 26, 2021
- This requires accumulating into a temporary buffer of a
  higher-precision type (float) to maintain precision. Implementing
  this required some minor refactoring which inflates the diff a bit.
@benbarsdell benbarsdell force-pushed the gpu-SparseTensorDenseMatMul-all-types branch from e377b73 to ab89002 Compare February 26, 2021 13:23
@benbarsdell
Copy link
Contributor Author

I've fixed the complex type test failures (I just missed #47355) and added support for float32 accumulation for float16 input/output, along with tests for float16.

Copy link
Member

@allenlavoie allenlavoie left a comment

Choose a reason for hiding this comment

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

Ah, the unit tests were soft-placing onto the CPU previously? Looks good.

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Feb 26, 2021
PR Queue automation moved this from Assigned Reviewer to Approved by Reviewer Feb 26, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Feb 26, 2021
@benbarsdell
Copy link
Contributor Author

The tests were running on the GPU, it was just that #47355 changed (fixed) the handling of complex conjugates (on CPU), and my local branch didn't have that commit.

@gbaned gbaned added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Mar 5, 2021
@allenlavoie
Copy link
Member

When we build internally I see a bunch of references to quiet_NaN not being supported for complex and complex:

third_party/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc:104:9: note: in instantiation of function template specialization 'tensorflow::SparseTensorDenseMatMulKernel<std::complex<float>, std::complex<float>, int, false, false>' requested here
        SparseTensorDenseMatMulKernel<T, Tsum, Tindices, ADJ_A, ADJ_B>,
        ^
In file included from third_party/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc:20:
In file included from ./third_party/tensorflow/core/framework/bounds_check.h:21:
In file included from third_party/eigen3/Eigen/Core:155:
./third_party/eigen3/Eigen/src/Core/util/Meta.h:293:84: error: non-void function does not return a value [-Werror,-Wreturn-type]
  static T quiet_NaN() { assert(false && "quiet_NaN not supported for this type"); }
                                                                                   ^
./third_party/eigen3/Eigen/src/Core/NumTraits.h:208:39: note: in instantiation of member function 'Eigen::internal::device::numeric_limits<std::complex<double>>::quiet_NaN' requested here
    return numext::numeric_limits<T>::quiet_NaN();
                                      ^
third_party/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc:104:9: note: in instantiation of function template specialization 'tensorflow::SparseTensorDenseMatMulKernel<std::complex<double>, std::complex<double>, int, false, false>' requested here
        SparseTensorDenseMatMulKernel<T, Tsum, Tindices, ADJ_A, ADJ_B>,
        ^
In file included from third_party/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc:20:
In file included from ./third_party/tensorflow/core/framework/bounds_check.h:21:
In file included from third_party/eigen3/Eigen/Core:163:

I see the float and double specializations there, but nothing for complex types. Do you know where it's supposed to be coming from?

- Eigen::NumTraits<T> is not implemented for std::complex so we need to
  special-case it.
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Mar 6, 2021
@benbarsdell
Copy link
Contributor Author

I didn't realize there was no NumTraits implementation for complex (I guess compiler warning flags are more strict internally?).
I've pushed a fix for it.

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 8, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 8, 2021
@copybara-service copybara-service bot merged commit 124ab03 into tensorflow:master Mar 9, 2021
PR Queue automation moved this from Approved by Reviewer to Merged Mar 9, 2021
copybara-service bot pushed a commit that referenced this pull request Mar 10, 2021
PiperOrigin-RevId: 362105835
Change-Id: I056a02b10f94e5033f940da4e14f630a4ae212b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes comp:core issues related to core part of tensorflow ready to pull PR ready for merge process size:S CL Change Size: Small
Projects
PR Queue
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

4 participants