c++ - TensorFlow CPU 和 CUDA 代码共享

标签 c++ machine-learning tensorflow cuda deep-learning

我正在为具有共享自定义函数代码的 TensorFlow 使用 C++ 和 CUDA 编写一个 Op。通常当 CPU 和 CUDA 实现之间的代码共享时,如果为 CUDA 编译,人们会定义一个宏来将 __device__ 说明符插入到函数签名中。在 TensorFlow 中是否有以这种方式共享代码的内置方式?

如何定义可以在 CPU 和 GPU 上运行的实用函数(通常是内联的)?

最佳答案

事实证明,TensorFlow 中的以下宏将执行我描述的操作。

namespace tensorflow{
    EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
    void foo() {
        //
    }
}

关于c++ - TensorFlow CPU 和 CUDA 代码共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45507534/

相关文章:

c++ - glDrawArrays 不绘制

c++ - 如何在 OpenCV 中进行 3D 高斯滤波?

python - 输入 0 与层 conv2d_121 : expected ndim=4, 发现 ndim=5 不兼容

python - tensorflow 对多个图像进行分类

c++ - 如何从c++中的文本文件填充数组

c++ - 如何在没有安装visual studio的另一台机器上使用visual studio生成的dll?

tensorflow - 如何在同一张图片中定位多个物体?

python - 比较在 scikit-learn 中调整超参数的方法

python - 在 TF 2.1 功能 API 中使用 tf.hub.KerasLayer 会引发 ValueError : Python inputs incompatible with input_signature:

python - 将 class_weight 添加到 .fit_generator() 会破坏 to_categorical()