aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/gpus/cuda/BUILD
blob: 697990330e884deb35f7e20bf178803377a66f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
licenses(["restricted"])  # MPL2, portions GPL v3, LGPL v3, BSD-like

load("//tensorflow:tensorflow.bzl", "if_cuda")
load("//tensorflow/core:platform/default/build_config.bzl",
     "tf_get_cuda_version",
     "tf_get_cudnn_version",
    )

package(default_visibility = ["//visibility:public"])

config_setting(
    name = "cuda_crosstool_condition",
    values = {"define": "using_cuda=true"},
    visibility = ["//visibility:public"],
)

config_setting(
    name = "using_gcudacc",
    values = {
        "define": "using_cuda=true",
        "copt": "--use_gcudacc",
    },
    visibility = ["//visibility:public"],
)

config_setting(
    name = "using_nvcc",
    values = {
        "define": "using_cuda=true",
        "copt": "--use_nvcc",
    },
)

cc_library(
    name = "cuda_headers",
    hdrs = glob([
        "**/*.h",
    ]),
    includes = [".", "include"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "cudart_static",
    srcs = [
        "lib64/libcudart_static.a",
    ],
    includes = ["include/"],
    linkopts = [
        "-ldl",
        "-lrt",
        "-lpthread",
    ],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "cudart",
    srcs = [
        "lib64/libcudart.so" + tf_get_cuda_version(),
    ],
    data = [
        "lib64/libcudart.so" + tf_get_cuda_version(),
    ],
    includes = ["include/"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
)

cc_library(
    name = "cublas",
    srcs = [
        "lib64/libcublas.so" + tf_get_cuda_version(),
    ],
    data = [
        "lib64/libcublas.so" + tf_get_cuda_version(),
    ],
    includes = ["include/"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
)

cc_library(
    name = "cudnn",
    srcs = [
        "lib64/libcudnn.so" + tf_get_cudnn_version(),
    ],
    data = [
        "lib64/libcudnn.so" + tf_get_cudnn_version(),
    ],
    includes = ["include/"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
)

cc_library(
    name = "cufft",
    srcs = [
        "lib64/libcufft.so" + tf_get_cuda_version(),
    ],
    data = [
        "lib64/libcufft.so" + tf_get_cuda_version(),
    ],
    includes = ["include/"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
)

cc_library(
    name = "cuda",
    deps = [
        ":cuda_headers",
        ":cudart",
        ":cublas",
        ":cudnn",
        ":cufft",
    ],
    visibility = ["//visibility:public"],
)

# TODO(opensource): for now, we have to invoke the cuda_config.sh manually in the source tree.
# This rule checks if Cuda libraries in the source tree has been properly configured.
# The output list makes bazel runs this rule first if the Cuda files are missing.
# This gives us an opportunity to check and print a meaningful error message.
# But we will need to create the output file list to make bazel happy in a successfull run.
genrule(
    name = "cuda_check",
    srcs = [
        "cuda.config",
        "cuda_config.sh",
    ],
    outs = [
        "include/cuda.h",
        "include/cublas.h",
        "include/cudnn.h",
        "lib64/libcudart_static.a",
        "lib64/libcublas.so" + tf_get_cuda_version(),
        "lib64/libcudnn.so" + tf_get_cudnn_version(),
        "lib64/libcudart.so" + tf_get_cuda_version(),
        "lib64/libcufft.so" + tf_get_cuda_version(),
    ],
    cmd = if_cuda(
        # Under cuda config, create all the symbolic links to the actual cuda files
        "OUTPUTDIR=`readlink -f $(@D)/../../..`; cd `dirname $(location :cuda_config.sh)`; OUTPUTDIR=$$OUTPUTDIR ./cuda_config.sh --check;",

        # Under non-cuda config, create all dummy files to make the build go through
        ";".join([
          "mkdir -p $(@D)/include",
          "mkdir -p $(@D)/lib64",
          "touch $(@D)/include/cuda.h",
          "touch $(@D)/include/cublas.h",
          "touch $(@D)/include/cudnn.h",
          "touch $(@D)/lib64/libcudart_static.a",
          "touch $(@D)/lib64/libcublas.so" + tf_get_cuda_version(),
          "touch $(@D)/lib64/libcudnn.so" + tf_get_cudnn_version(),
          "touch $(@D)/lib64/libcudart.so" + tf_get_cuda_version(),
          "touch $(@D)/lib64/libcufft.so" + tf_get_cuda_version(),
            ]),
    ),
    local = 1,
)

genrule(
    name = "cuda_config_check",
    outs = [
        "cuda.config",
    ],
    cmd = if_cuda(
        # Under cuda config, create the symbolic link to the actual cuda.config
        "configfile=$(location :cuda.config); ln -sf `readlink -f $${configfile#*/*/*/}` $(@D)/;",

        # Under non-cuda config, create the dummy file
        ";".join([
         "touch $(@D)/cuda.config",
        ]),
    ),
    local = 1,
)