Skip to content

Commit

Permalink
[RUNTIME] Support environments with multiple cudalibs (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrocha authored Oct 3, 2022
1 parent 4a2d3b7 commit 2b0f877
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/test/unit/language/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def change_value(Lock):
Lock = torch.zeros((1,), device='cuda', dtype=torch.int32)
change_value[(1,)](Lock)

assert(Lock[0] == 1)
assert (Lock[0] == 1)

# 2. only one block enters the critical section
@triton.jit
Expand Down
14 changes: 8 additions & 6 deletions python/triton/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,9 @@ def put(self, data, filename, binary=True):


@functools.lru_cache()
def libcuda_dir():
loc = subprocess.check_output(["whereis", "libcuda.so"]).decode().strip().split()[-1]
return os.path.dirname(loc)
def libcuda_dirs():
locs = subprocess.check_output(["whereis", "libcuda.so"]).decode().strip().split()[1:]
return [os.path.dirname(loc) for loc in locs]


@contextlib.contextmanager
Expand All @@ -1118,7 +1118,7 @@ def quiet():


def _build(name, src, srcdir):
cuda_lib_dir = libcuda_dir()
cuda_lib_dirs = libcuda_dirs()
cu_include_dir = "/usr/local/cuda/include"
suffix = sysconfig.get_config_var('EXT_SUFFIX')
so = os.path.join(srcdir, '{name}{suffix}'.format(name=name, suffix=suffix))
Expand All @@ -1130,12 +1130,14 @@ def _build(name, src, srcdir):
gcc = shutil.which("gcc")
cc = gcc if gcc is not None else clang
py_include_dir = get_paths()["include"]
ret = subprocess.check_call([cc, src, "-O3", f"-I{cu_include_dir}", f"-I{py_include_dir}", f"-I{srcdir}", "-shared", "-fPIC", f"-L{cuda_lib_dir}", "-lcuda", "-o", so])
cc_cmd = [cc, src, "-O3", f"-I{cu_include_dir}", f"-I{py_include_dir}", f"-I{srcdir}", "-shared", "-fPIC", "-lcuda", "-o", so]
cc_cmd += [f"-L{dir}" for dir in cuda_lib_dirs]
ret = subprocess.check_call(cc_cmd)
if ret == 0:
return so
# fallback on setuptools
extra_compile_args = []
library_dirs = [cuda_lib_dir]
library_dirs = cuda_lib_dirs
include_dirs = [srcdir, cu_include_dir]
libraries = ['cuda']
# extra arguments
Expand Down

0 comments on commit 2b0f877

Please sign in to comment.