MCPcopy Create free account
hub / github.com/apache/tvm / find_libdevice_path

Function find_libdevice_path

python/tvm/support/nvcc.py:896–949  ·  view source on GitHub ↗

Utility function to find libdevice Parameters ---------- arch : int The compute architecture in int Returns ------- path : str Path to libdevice.

(arch)

Source from the content-addressed store, hash-verified

894
895@tvm_ffi.register_global_func("tvm_callback_libdevice_path")
896def find_libdevice_path(arch):
897 """Utility function to find libdevice
898
899 Parameters
900 ----------
901 arch : int
902 The compute architecture in int
903
904 Returns
905 -------
906 path : str
907 Path to libdevice.
908 """
909 cuda_path = find_cuda_path()
910 lib_path = os.path.join(cuda_path, "nvvm/libdevice")
911 if not os.path.exists(lib_path):
912 # Debian/Ubuntu repackaged CUDA path
913 lib_path = os.path.join(cuda_path, "lib/nvidia-cuda-toolkit/libdevice")
914 selected_ver = 0
915 selected_path = None
916 cuda_ver = get_cuda_version(cuda_path)
917 major_minor = (cuda_ver[0], cuda_ver[1])
918 if major_minor in (
919 (9, 0),
920 (9, 1),
921 (10, 0),
922 (10, 1),
923 (10, 2),
924 (11, 0),
925 (11, 1),
926 (11, 2),
927 (11, 3),
928 ):
929 path = os.path.join(lib_path, "libdevice.10.bc")
930 else:
931 for fn in os.listdir(lib_path):
932 if not fn.startswith("libdevice"):
933 continue
934
935 try:
936 # expected pattern: libdevice.${ARCH}.10.bc
937 # e.g., libdevice.compute_20.10.bc
938 ver = int(fn.split(".")[-3].split("_")[-1])
939 if selected_ver < ver <= arch:
940 selected_ver = ver
941 selected_path = fn
942 except ValueError:
943 # it can just be `libdevice.10.bc` in CUDA 10
944 selected_path = fn
945
946 if selected_path is None:
947 raise RuntimeError(f"Cannot find libdevice for arch {arch}")
948 path = os.path.join(lib_path, selected_path)
949 return path
950
951
952def callback_libdevice_path(arch):

Callers 1

callback_libdevice_pathFunction · 0.85

Calls 5

find_cuda_pathFunction · 0.85
get_cuda_versionFunction · 0.85
joinMethod · 0.45
listdirMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…