编译CUDA的自定义TensorFlow OP
Compile custom tensorflow op for CUDA
我正在为张贴文档中的指南开发一个需要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
两个问题:
- 为什么我需要包含此特征张量标头,尽管演示OP实际上不使用eigen张量?
- 错误来自哪里以及如何解决这些错误?您认为这与不支持的系统配置有关吗?
好的,对于那些遇到相同问题的人:您可以使用-ccbin
参数设置nvcc
的主机编译器,如本答案中所指出的那样。只需将其设置为gcc-4.9
。
相关文章:
- 基于树莓pi的tensorflow lite量化ssd目标检测
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何阻止TensorFlow的多线程
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- Tensorflow对象检测在Python和C++(OpenCV)之间有不同的结果
- 在 c++ 中使用 Tensorflow Lite 在边缘 TPU 上运行"mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite"时出现问题
- Tensorflow Hub in C++
- cmsis_compiler.h:在为 Arduino Due 编译 Arduino Tensorflow lite 库
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- 构建 TensorFlow r1.14 C++文件时缺少文件"tensorflow/core/framework/types.pb.h"
- constexpr 使用 clang 编译 TensorFlow 时出错
- MatMul op 在 tensorflow 中是如何工作的?
- 如何从C++代码运行自定义 GPU tensorflow::op?
- 编译CUDA的自定义TensorFlow OP
- 在Python中编写和注册自定义TensorFlow OP
- 如何在 Tensorflow C++ 中定义变量的自定义有状态 Op 保存值
- 可以在CUDA速度计算中实现TensorFlow自定义OP梯度
- Google Cloud ML引擎中的TensorFlow新OP
- 添加使用malloc()并具有状态的TensorFlow OP
- 理解TensorFlow中的Op注册和内核链接