使用不带.cu扩展名的Clang编译Cuda

时间:2018-07-31 13:41:56

标签: cuda clang

第一个命令直接来自手册,但第二个命令似乎没有将.cc文件识别为cuda,即使我具有-xcuda标志。

clang ++ apxy.cu --cuda-gpu-arch = sm_61 -L / usr / local / cuda / lib64 -lcudart_static -ldl -lrt -pthread

clang ++ apxy.cc -xcuda --cuda-gpu-arch = sm_61 -L / usr / local / cuda / lib64 -lcudart_static -ldl -lrt -pthread

apxy.cc:3:1: error: unknown type name '__global__'__global__ void axpy(float a, float* x, float* y) {                                                                                                            │        at io.iohk.ethereum.mallet.main.Shell.<init>(Shell.scala:18)
^                                                                                                                                                              │        at io.iohk.ethereum.mallet.main.Mallet$.delayedEndpoint$io$iohk$ethereum$mallet$main$Mallet$1(Mallet.scala:20)
apxy.cc:3:12: error: expected unqualified-id                                                                                                                   │        at io.iohk.ethereum.mallet.main.Mallet$delayedInit$body.apply(Mallet.scala:13)
__global__ void axpy(float a, float* x, float* y) {                                                                                                            │        at scala.Function0.apply$mcV$sp(Function0.scala:34)
           ^                                                                                                                                                   │        at scala.Function0.apply$mcV$sp$(Function0.scala:34)
apxy.cc:17:3: error: use of undeclared identifier 'cudaMalloc'                                                                                                 │        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
  cudaMalloc(&device_x, kDataLen * sizeof(float));

2 个答案:

答案 0 :(得分:2)

我的问题是我需要-xcuda放在文件名之前。这是使用Bazel的示例。

WORKSPACE

new_local_repository(
    name = "cuda",
    path = "/usr/local/cuda",
    build_file_content = """
cc_library(
    name = "cuda",
    hdrs = glob(["**/*.h", "**/*.hpp", ]),
    includes = ["include/"],
    linkopts = ["-L/usr/local/cuda/lib64 -lcudart_static -ldl -lrt -pthread"],
    visibility = ["//visibility:public"],
)
    """
)

已构建

cc_binary(
    name = "example",
    srcs = ["example.cu.cc"],
    copts = ["-xcuda --cuda-gpu-arch=sm_61"],
    deps = ["@cuda"],
)

答案 1 :(得分:0)

seems应该使用--std=cuda来解决问题。警告:我自己还没有尝试过。