1*da0073e9SAndroid Build Coastguard Worker""" 2*da0073e9SAndroid Build Coastguard Worker Macros for selecting with / without various GPU libraries. Most of these are meant to be used 3*da0073e9SAndroid Build Coastguard Worker directly by tensorflow in place of their build's own configure.py + bazel-gen system. 4*da0073e9SAndroid Build Coastguard Worker""" 5*da0073e9SAndroid Build Coastguard Worker 6*da0073e9SAndroid Build Coastguard Workerload("@bazel_skylib//lib:selects.bzl", "selects") 7*da0073e9SAndroid Build Coastguard Worker 8*da0073e9SAndroid Build Coastguard Workerdef if_cuda(if_true, if_false = []): 9*da0073e9SAndroid Build Coastguard Worker """Helper for selecting based on the whether CUDA is configured. """ 10*da0073e9SAndroid Build Coastguard Worker return selects.with_or({ 11*da0073e9SAndroid Build Coastguard Worker "@//tools/config:cuda_enabled_and_capable": if_true, 12*da0073e9SAndroid Build Coastguard Worker "//conditions:default": if_false, 13*da0073e9SAndroid Build Coastguard Worker }) 14*da0073e9SAndroid Build Coastguard Worker 15*da0073e9SAndroid Build Coastguard Workerdef if_tensorrt(if_true, if_false = []): 16*da0073e9SAndroid Build Coastguard Worker """Helper for selecting based on the whether TensorRT is configured. """ 17*da0073e9SAndroid Build Coastguard Worker return select({ 18*da0073e9SAndroid Build Coastguard Worker "//conditions:default": if_false, 19*da0073e9SAndroid Build Coastguard Worker }) 20*da0073e9SAndroid Build Coastguard Worker 21*da0073e9SAndroid Build Coastguard Workerdef if_rocm(if_true, if_false = []): 22*da0073e9SAndroid Build Coastguard Worker """Helper for selecting based on the whether ROCM is configured. """ 23*da0073e9SAndroid Build Coastguard Worker return select({ 24*da0073e9SAndroid Build Coastguard Worker "//conditions:default": if_false, 25*da0073e9SAndroid Build Coastguard Worker }) 26*da0073e9SAndroid Build Coastguard Worker 27*da0073e9SAndroid Build Coastguard Workerdef if_sycl(if_true, if_false = []): 28*da0073e9SAndroid Build Coastguard Worker """Helper for selecting based on the whether SYCL/ComputeCPP is configured.""" 29*da0073e9SAndroid Build Coastguard Worker 30*da0073e9SAndroid Build Coastguard Worker # NOTE: Tensorflow expects some stange behavior (see their if_sycl) if we 31*da0073e9SAndroid Build Coastguard Worker # actually plan on supporting this at some point. 32*da0073e9SAndroid Build Coastguard Worker return select({ 33*da0073e9SAndroid Build Coastguard Worker "//conditions:default": if_false, 34*da0073e9SAndroid Build Coastguard Worker }) 35*da0073e9SAndroid Build Coastguard Worker 36*da0073e9SAndroid Build Coastguard Workerdef if_ccpp(if_true, if_false = []): 37*da0073e9SAndroid Build Coastguard Worker """Helper for selecting based on the whether ComputeCPP is configured. """ 38*da0073e9SAndroid Build Coastguard Worker return select({ 39*da0073e9SAndroid Build Coastguard Worker "//conditions:default": if_false, 40*da0073e9SAndroid Build Coastguard Worker }) 41*da0073e9SAndroid Build Coastguard Worker 42*da0073e9SAndroid Build Coastguard Workerdef cuda_default_copts(): 43*da0073e9SAndroid Build Coastguard Worker return if_cuda(["-DGOOGLE_CUDA=1"]) 44*da0073e9SAndroid Build Coastguard Worker 45*da0073e9SAndroid Build Coastguard Workerdef cuda_default_features(): 46*da0073e9SAndroid Build Coastguard Worker return if_cuda(["-per_object_debug_info", "-use_header_modules", "cuda_clang"]) 47*da0073e9SAndroid Build Coastguard Worker 48*da0073e9SAndroid Build Coastguard Workerdef rocm_default_copts(): 49*da0073e9SAndroid Build Coastguard Worker return if_rocm(["-x", "rocm"]) 50*da0073e9SAndroid Build Coastguard Worker 51*da0073e9SAndroid Build Coastguard Workerdef rocm_copts(opts = []): 52*da0073e9SAndroid Build Coastguard Worker return rocm_default_copts() + if_rocm(opts) 53*da0073e9SAndroid Build Coastguard Worker 54*da0073e9SAndroid Build Coastguard Workerdef cuda_is_configured(): 55*da0073e9SAndroid Build Coastguard Worker # FIXME(dcollins): currently only used by tensorflow's xla stuff, which we aren't building. However bazel 56*da0073e9SAndroid Build Coastguard Worker # query hits it so this needs to be defined. Because bazel doesn't actually resolve config at macro expansion 57*da0073e9SAndroid Build Coastguard Worker # time, `select` can't be used here (since xla expects lists of strings and not lists of select objects). 58*da0073e9SAndroid Build Coastguard Worker # Instead, the xla build rules must be rewritten to use `if_cuda_is_configured` 59*da0073e9SAndroid Build Coastguard Worker return False 60*da0073e9SAndroid Build Coastguard Worker 61*da0073e9SAndroid Build Coastguard Workerdef if_cuda_is_configured(x): 62*da0073e9SAndroid Build Coastguard Worker return if_cuda(x, []) 63*da0073e9SAndroid Build Coastguard Worker 64*da0073e9SAndroid Build Coastguard Workerdef if_rocm_is_configured(x): 65*da0073e9SAndroid Build Coastguard Worker return if_rocm(x, []) 66