Skip to content

CUDA headers not found when implementing GPU kernel for user-op #375

Closed

Description

@hannes-brt

I am following the tutorial to implement a user-op. I have three files dna_encode_op.cc, dna_encode_op_gpu.cu.cc, and dna_encode_op.h.

I have configured TensorFlow with GPU support using ./configure. However, during compilation of dna_encode_op_gpu.cu.cc, Bazel doesn't find the CUDA headers:

INFO: From Compiling tensorflow/core/user_ops/dna_encode_op_gpu.cu.cc [for host]:
In file included from ./tensorflow/core/framework/tensor_types.h:4:0,
                 from tensorflow/core/user_ops/dna_encode_op_gpu.cu.cc:8:
./third_party/eigen3/unsupported/Eigen/CXX11/Tensor:55:18: fatal error: cuda.h: No such file or directory
 #include <cuda.h>
                  ^
compilation terminated.
ERROR: /home/hannes/git/DNAflow_internal/tensorflow/core/BUILD:339:1: C++ compilation of rule '//tensorflow/core:user_ops_op_lib' failed: crosstool_wrapper_driver_is_not_gcc failed: error executing command third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -fPIE -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object ... (remaining 50 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.

Building the included ops works well, so I'm wondering whether I have to modify BUILD - however, there is no mention of this in the tutorials.

Activity

  1. hannes-brt commented on Dec 1, 2015

    @hannes-brt
    Author

    Btw, I discovered that when I move my files from user_ops/ to kernels/ they compile fine. So it seems BUILD is using different rules for user_ops/ and kernels/, with the CUDA headers not being included for user ops.

  2. vrv commented on Dec 1, 2015

    @vrv

    Thanks for the report -- we're trying to figure out a better solution to custom ops than the user_ops directory, and in doing so should hopefully address these cuda header issues.

  3. keveman commented on Feb 9, 2016

    @keveman
    Contributor

    I added instructions for building ops and kernels outside of TensorFlow source tree. Please have a look to see if it fits your need.

  4. vrv commented on Feb 19, 2016

    @vrv

    (Reopen if this new feature isn't working as expected)

  5. psycharo-zz commented on Mar 9, 2016

    @psycharo-zz

    The instructions work fine for CPU-only ops, but seem to be insufficient for building an op with a GPU kernel. A slightly modified BUILD works fine though (for GPU-only kernels):

    cc_binary(
        name = "softmax4d_op.so",
        srcs = [
            "softmax4d_op.cc",
            "softmax4d_op.h"
        ],
        copts = [
            "-x", "cuda",
            "-DGOOGLE_CUDA=1"
        ],
        linkopts = [
            "-Wl,-Bsymbolic",
            "-lm",
        ],
        linkshared = 1,
        linkstatic = 1,
        deps = [
            "//tensorflow/core:framework",
            "//tensorflow/core:cuda",
            "//third_party/eigen3"
        ],
    )

    I think it would be great to have a bit more details in the docs, and maybe even have a bazel rule for building custom ops, similar to tf_kernel_library().

  6. added and removed on Feb 9, 2017
  7. stomachacheGE commented on May 29, 2019

    @stomachacheGE

    @hannes-brt hi, I encountered similar issues when I want to add a custom op which is implemented on GPU. You said it works when you copies these files from user_ops to kernels. Did you just copy the .h,.cc,.cu.cc to tensorflow/cores/kernels or did you also add build target in tensorflow/cores/kernels/BUILD?

  8. added a commit that references this issue on Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions