编译CUDA的自定义TensorFlow OP



我正在为张贴文档中的指南开发一个需要GPU支持的自定义OP。在追踪我自己的代码中的错误时,我从文档中返回了示例,并尝试编译引用的代码示例:

#if GOOGLE_CUDA
#define EIGEN_USE_GPU
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
__global__ void AddOneKernel(const int* in, const int N, int* out) {
  for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < N;
       i += blockDim.x * gridDim.x) {
    out[i] = in[i] + 1;
  }
}
void AddOneKernelLauncher(const int* in, const int N, int* out) {
  AddOneKernel<<<32, 256>>>(in, N, out);
}
#endif

使用文档中建议的命令:

nvcc -std=c++11 -c -o cuda_op_kernel.cu.o cuda_op_kernel.cu.cc 
-I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC

$TF_INC正确替换为张力流的路径。不幸的是,这产生了很多错误:

/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1294): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1300): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1306): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1312): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1318): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1324): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1330): error: expression must have arithmetic, unscoped enum, or pointer type
/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h(1336): error: expression must have arithmetic, unscoped enum, or pointer type

以及其他类似的人。

我发现这可能与不支持的NVCC/GCC/OS组合有关。我没有自己设置机器(实际上没有Sudo权利(。我有NVCC版本7.5.17,GCC版本4.9.3在Ubuntu 16.04.2上。Ubuntu 16.04.2未在CUDA 7.5的支持系统中列出。这可能是一个问题,但我发现许多人声称它在16.04上有效。此外,我在这台计算机上成功地用GPU支持编译了TensorFlow。

此外,这些错误与代码中的张量#include有关,并且代码在没有此行的情况下成功编译了代码。如果没有此功能,我没有尝试过演示OP是否可以使用,但是我自己的OP失败了

2017-06-01 09:36:14.679685: E tensorflow/stream_executor/cuda/cuda_driver.cc:1067] could not synchronize on CUDA context: CUDA_ERROR_LAUNCH_FAILED :: No stack trace available
2017-06-01 09:36:14.679777: F tensorflow/core/common_runtime/gpu/gpu_util.cc:370] GPU sync failed

两个问题:

  1. 为什么我需要包含此特征张量标头,尽管演示OP实际上不使用eigen张量?
  2. 错误来自哪里以及如何解决这些错误?您认为这与不支持的系统配置有关吗?

好的,对于那些遇到相同问题的人:您可以使用-ccbin参数设置nvcc的主机编译器,如本答案中所指出的那样。只需将其设置为gcc-4.9

最新更新