rocm_jax/jaxlib/rocm/BUILD.bazel
Peter Hawkins a852710a09 Merge CUDA and ROCM kernel code in jaxlib.
The code for both CUDA and ROCM is almost identical, so with a small shim library to handle the differences we can share almost everything.

PiperOrigin-RevId: 483666051
2022-10-25 07:23:34 -07:00

293 lines
8.2 KiB
Python

# Copyright 2018 The JAX Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# AMD HIP kernels
load(
"//jaxlib:jax.bzl",
"if_rocm_is_configured",
"pybind_extension",
"rocm_library",
)
licenses(["notice"])
package(default_visibility = ["//:__subpackages__"])
cc_library(
name = "hip_vendor",
hdrs = [
"//jaxlib/gpu:vendor.h",
],
defines = ["JAX_GPU_HIP=1"],
deps = [
"@local_config_rocm//rocm:rocm_headers",
],
)
cc_library(
name = "hip_gpu_kernel_helpers",
srcs = if_rocm_is_configured(["//jaxlib/gpu:gpu_kernel_helpers.cc"]),
hdrs = if_rocm_is_configured(["//jaxlib/gpu:gpu_kernel_helpers.h"]),
copts = [
"-fexceptions",
],
features = ["-use_header_modules"],
deps = [
":hip_vendor",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
] + if_rocm_is_configured([
"@local_config_rocm//rocm:rocm_headers",
]),
)
cc_library(
name = "hipblas_kernels",
srcs = ["//jaxlib/gpu:blas_kernels.cc"],
hdrs = ["//jaxlib/gpu:blas_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
"//jaxlib:handle_pool",
"//jaxlib:kernel_helpers",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@local_config_rocm//rocm:hipblas",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
pybind_extension(
name = "_blas",
srcs = ["//jaxlib/gpu:blas.cc"],
copts = [
"-fexceptions",
"-fno-strict-aliasing",
],
features = ["-use_header_modules"],
module_name = "_blas",
deps = [
":hip_vendor",
":hipblas_kernels",
"//jaxlib:kernel_pybind11_helpers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings:str_format",
"@local_config_rocm//rocm:hipblas",
"@local_config_rocm//rocm:rocm_headers",
"@pybind11",
],
)
cc_library(
name = "hipsolver_kernels",
srcs = ["//jaxlib/gpu:solver_kernels.cc"],
hdrs = ["//jaxlib/gpu:solver_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
"//jaxlib:handle_pool",
"//jaxlib:kernel_helpers",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/synchronization",
"@local_config_rocm//rocm:hipsolver",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
pybind_extension(
name = "_solver",
srcs = ["//jaxlib/gpu:solver.cc"],
copts = [
"-fexceptions",
"-fno-strict-aliasing",
],
features = ["-use_header_modules"],
module_name = "_solver",
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
":hipsolver_kernels",
"//jaxlib:kernel_pybind11_helpers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings:str_format",
"@local_config_rocm//rocm:hipsolver",
"@local_config_rocm//rocm:rocm_headers",
"@pybind11",
],
)
cc_library(
name = "hipsparse_kernels",
srcs = ["//jaxlib/gpu:sparse_kernels.cc"],
hdrs = ["//jaxlib/gpu:sparse_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
"//jaxlib:handle_pool",
"//jaxlib:kernel_helpers",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/synchronization",
"@local_config_rocm//rocm:hipsparse",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
pybind_extension(
name = "_sparse",
srcs = ["//jaxlib/gpu:sparse.cc"],
copts = [
"-fexceptions",
"-fno-strict-aliasing",
],
features = ["-use_header_modules"],
module_name = "_sparse",
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
":hipsparse_kernels",
"//jaxlib:kernel_pybind11_helpers",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@local_config_rocm//rocm:hipsparse",
"@local_config_rocm//rocm:rocm_headers",
"@pybind11",
],
)
cc_library(
name = "hip_lu_pivot_kernels",
srcs = ["//jaxlib/gpu:lu_pivot_kernels.cc"],
hdrs = ["//jaxlib/gpu:lu_pivot_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_lu_pivot_kernels_impl",
":hip_vendor",
"//jaxlib:kernel_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
rocm_library(
name = "hip_lu_pivot_kernels_impl",
srcs = ["//jaxlib/gpu:lu_pivot_kernels.cu.cc"],
hdrs = ["//jaxlib/gpu:lu_pivot_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
"//jaxlib:kernel_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
pybind_extension(
name = "_linalg",
srcs = ["//jaxlib/gpu:linalg.cc"],
copts = [
"-fexceptions",
"-fno-strict-aliasing",
],
features = ["-use_header_modules"],
module_name = "_linalg",
deps = [
":hip_gpu_kernel_helpers",
":hip_lu_pivot_kernels",
":hip_lu_pivot_kernels_impl",
":hip_vendor",
"//jaxlib:kernel_pybind11_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@pybind11",
],
)
cc_library(
name = "hip_prng_kernels",
srcs = ["//jaxlib/gpu:prng_kernels.cc"],
hdrs = ["//jaxlib/gpu:prng_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_prng_kernels_impl",
":hip_vendor",
"//jaxlib:kernel_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
rocm_library(
name = "hip_prng_kernels_impl",
srcs = ["//jaxlib/gpu:prng_kernels.cu.cc"],
hdrs = ["//jaxlib/gpu:prng_kernels.h"],
deps = [
":hip_gpu_kernel_helpers",
":hip_vendor",
"//jaxlib:kernel_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@org_tensorflow//tensorflow/compiler/xla/service:custom_call_status",
],
)
pybind_extension(
name = "_prng",
srcs = ["//jaxlib/gpu:prng.cc"],
copts = [
"-fexceptions",
"-fno-strict-aliasing",
],
features = ["-use_header_modules"],
module_name = "_prng",
deps = [
":hip_gpu_kernel_helpers",
":hip_prng_kernels",
":hip_vendor",
"//jaxlib:kernel_pybind11_helpers",
"@local_config_rocm//rocm:rocm_headers",
"@pybind11",
],
)
py_library(
name = "rocm_gpu_support",
deps = [
":_blas",
":_linalg",
":_prng",
":_solver",
":_sparse",
],
)