Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix LAMMPS wheel with CUDA wheels #2887

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions deepmd/lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
return ":".join(p for p in paths if p is not None)


def get_library_path(module: str) -> List[str]:
def get_library_path(module: str, filename: str) -> List[str]:

Check warning on line 38 in deepmd/lmp.py

View check run for this annotation

Codecov / codecov/patch

deepmd/lmp.py#L38

Added line #L38 was not covered by tests
"""Get library path from a module.

Parameters
----------
module : str
The module name.
filename : str
The library filename pattern.

Returns
-------
Expand All @@ -53,7 +55,8 @@
except ModuleNotFoundError:
return []
else:
return [str(Path(m.__file__).parent)]
libs = sorted(Path(m.__path__[0]).glob(filename))
return [str(lib) for lib in libs]

Check warning on line 59 in deepmd/lmp.py

View check run for this annotation

Codecov / codecov/patch

deepmd/lmp.py#L58-L59

Added lines #L58 - L59 were not covered by tests


if platform.system() == "Linux":
Expand All @@ -63,6 +66,13 @@
else:
raise RuntimeError("Unsupported platform")

if platform.system() == "Linux":
preload_env = "LD_PRELOAD"
elif platform.system() == "Darwin":
preload_env = "DYLD_INSERT_LIBRARIES"

Check warning on line 72 in deepmd/lmp.py

View check run for this annotation

Codecov / codecov/patch

deepmd/lmp.py#L69-L72

Added lines #L69 - L72 were not covered by tests
else:
raise RuntimeError("Unsupported platform")

Check warning on line 74 in deepmd/lmp.py

View check run for this annotation

Codecov / codecov/patch

deepmd/lmp.py#L74

Added line #L74 was not covered by tests

tf_dir = tf.sysconfig.get_lib()
op_dir = str((Path(__file__).parent / "lib").absolute())

Expand All @@ -71,37 +81,37 @@
if platform.system() == "Linux":
cuda_library_paths.extend(
[
*get_library_path("nvidia.cuda_runtime.lib"),
*get_library_path("nvidia.cublas.lib"),
*get_library_path("nvidia.cublas.lib"),
*get_library_path("nvidia.cufft.lib"),
*get_library_path("nvidia.curand.lib"),
*get_library_path("nvidia.cusolver.lib"),
*get_library_path("nvidia.cusparse.lib"),
*get_library_path("nvidia.cudnn.lib"),
*get_library_path("nvidia.cuda_runtime.lib", "libcudart.so*"),
*get_library_path("nvidia.cublas.lib", "libcublasLt.so*"),
*get_library_path("nvidia.cublas.lib", "libcublas.so*"),
*get_library_path("nvidia.cufft.lib", "libcufft.so*"),
*get_library_path("nvidia.curand.lib", "libcurand.so*"),
*get_library_path("nvidia.cusolver.lib", "libcusolver.so*"),
*get_library_path("nvidia.cusparse.lib", "libcusparse.so*"),
*get_library_path("nvidia.cudnn.lib", "libcudnn.so*"),
]
)

os.environ[preload_env] = get_env(

Check warning on line 95 in deepmd/lmp.py

View check run for this annotation

Codecov / codecov/patch

deepmd/lmp.py#L95

Added line #L95 was not covered by tests
[
os.environ.get(preload_env),
*cuda_library_paths,
]
)

# set LD_LIBRARY_PATH
os.environ[lib_env] = get_env(
[
os.environ.get(lib_env),
tf_dir,
os.path.join(tf_dir, "python"),
op_dir,
*cuda_library_paths,
]
)

# preload python library, only for TF<2.12
if find_libpython is not None:
libpython = find_libpython()
if platform.system() == "Linux":
preload_env = "LD_PRELOAD"
elif platform.system() == "Darwin":
preload_env = "DYLD_INSERT_LIBRARIES"
else:
raise RuntimeError("Unsupported platform")
os.environ[preload_env] = get_env(
[
os.environ.get(preload_env),
Expand Down
Loading