Skip to content

Instantly share code, notes, and snippets.

@bstriner
Created July 25, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bstriner/a7fb0a8da1f830900fa932652439ed44 to your computer and use it in GitHub Desktop.
Save bstriner/a7fb0a8da1f830900fa932652439ed44 to your computer and use it in GitHub Desktop.
Patch for eigen3 to build for tensorflow
--- Eigen/src/Core/arch/CUDA/Half.h 2018-06-22 18:09:44.000000000 -0400
+++ Eigen/src/Core/arch/CUDA/Half.h 2018-07-25 01:19:55.462313100 -0400
@@ -209,7 +209,7 @@
// conversion steps back and forth.
EIGEN_STRONG_INLINE __device__ half operator + (const half& a, const half& b) {
- return __hadd(a, b);
+ return __hadd(::__half(a), ::__half(b));
}
EIGEN_STRONG_INLINE __device__ half operator * (const half& a, const half& b) {
return __hmul(a, b);
@@ -218,9 +218,7 @@
return __hsub(a, b);
}
EIGEN_STRONG_INLINE __device__ half operator / (const half& a, const half& b) {
- float num = __half2float(a);
- float denom = __half2float(b);
- return __float2half(num / denom);
+ return __hdiv(a, b);
}
EIGEN_STRONG_INLINE __device__ half operator - (const half& a) {
return __hneg(a);
@bstriner
Copy link
Author

Patch file for eigen source currently used by tensorflow build (as of 7/25/2018). Based on patch submitted by Jiandong Ruan at http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1526

To apply this patch using the cmake build, download the gist and add -Deigen_PATCH_FILE=path-to-patch.txt to the cmake command line.

@Zaktara
Copy link

Zaktara commented Jul 25, 2018

I had the same issue and applied the patch and it looks good. Thanks.

@AkshayMathur92
Copy link

How do I add it to bazel ? tried adding this to eigen.cmake but realized that this file is generated.
Then tried to add to eigen.BUILD at cc_library.defines "eigen_PATCH_FILE=eigen-patch.txt". doesn't work either .
Will you please help and let me know what I am doing wrong ?

@neyuru
Copy link

neyuru commented Nov 17, 2018

I am also interested in patching via bazel (building for GPU)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment