2022-09-22 12:26:48 -07:00
|
|
|
# Copyright 2021 The JAX Authors.
|
2021-03-31 18:35:15 -07:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2023-11-06 09:05:08 -08:00
|
|
|
import importlib
|
2021-03-31 18:35:15 -07:00
|
|
|
|
|
|
|
from jaxlib import xla_client
|
|
|
|
|
2024-03-25 11:44:40 -07:00
|
|
|
for cuda_module_name in [".cuda", "jax_cuda12_plugin"]:
|
2023-11-06 09:05:08 -08:00
|
|
|
try:
|
|
|
|
_cuda_linalg = importlib.import_module(
|
|
|
|
f"{cuda_module_name}._linalg", package="jaxlib"
|
|
|
|
)
|
|
|
|
except ImportError:
|
|
|
|
_cuda_linalg = None
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2024-06-12 18:45:01 -05:00
|
|
|
for rocm_module_name in [".rocm", "jax_rocm60_plugin"]:
|
|
|
|
try:
|
|
|
|
_hip_linalg = importlib.import_module(
|
|
|
|
f"{rocm_module_name}._linalg", package="jaxlib"
|
|
|
|
)
|
|
|
|
except ImportError:
|
|
|
|
_hip_linalg = None
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2025-02-07 08:47:37 -08:00
|
|
|
if _cuda_linalg:
|
|
|
|
for _name, _value in _cuda_linalg.registrations().items():
|
|
|
|
xla_client.register_custom_call_target(
|
2025-02-27 08:15:45 -08:00
|
|
|
_name, _value, platform="CUDA", api_version=1
|
2025-02-07 08:47:37 -08:00
|
|
|
)
|
2025-02-27 08:15:45 -08:00
|
|
|
xla_client.register_custom_call_as_batch_partitionable(
|
|
|
|
"cu_lu_pivots_to_permutation")
|
2025-02-07 08:47:37 -08:00
|
|
|
|
2024-06-12 18:45:01 -05:00
|
|
|
if _hip_linalg:
|
2022-05-06 09:34:25 -07:00
|
|
|
for _name, _value in _hip_linalg.registrations().items():
|
2024-05-02 08:11:09 -07:00
|
|
|
xla_client.register_custom_call_target(
|
2025-02-27 08:15:45 -08:00
|
|
|
_name, _value, platform="ROCM", api_version=1
|
2024-05-02 08:11:09 -07:00
|
|
|
)
|
2025-02-27 08:15:45 -08:00
|
|
|
xla_client.register_custom_call_as_batch_partitionable(
|
|
|
|
"hip_lu_pivots_to_permutation")
|