taichi在使用cuda后端时,在执行到ti.linalg.SparseSolver时会显示”Failed to load cusolver library!“。在使用CPU后端时没有问题。
这是代码:
import taichi as ti
ti.init(arch = ti.cuda)
a = ti.linalg.SparseMatrixBuilder(5, 5)
b = ti.ndarray(float, 5)
@ti.kernel
def fill(a: ti.types.sparse_matrix_builder(), b:ti.types.ndarray()):
for i in range(5):
for j in range(5):
a[i, j] += ti.floor(ti.randn()*10)
b[i] = ti.floor(ti.random()*10)
fill(a,b)
k = a.build()
solver = ti.linalg.SparseSolver(solver_type="LU")
solver.analyze_pattern(k)
solver.factorize(k)
res = solver.solve(b)
print(k)
print([b[0], b[1], b[2], b[3], b[4]])
print([res[0], res[1], res[2], res[3], res[4]])
这是运行的结果
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbbd, win, python 3.9.13
[Taichi] Starting on arch=cuda
[W 07/13/23 15:39:00.829 24152] [cuda_driver.cpp:taichi::lang::CUDADriverBase::load_lib@36] cusolver64_12.dll lib not found.
[E 07/13/23 15:39:00.829 24152] [sparse_solver.cpp:taichi::lang::CuSparseSolver::init_solver@193] Failed to load cusolver library!
Traceback (most recent call last):
File "c:\Users\liuyu\Desktop\gt\test.py", line 15, in <module>
solver = ti.linalg.SparseSolver(solver_type="LU")
File "C:\Users\liuyu\anaconda3\lib\site-packages\taichi\linalg\sparse_solver.py", line 34, in __init__
self.solver = _ti_core.make_cusparse_solver(dtype, solver_type, ordering)
RuntimeError: [sparse_solver.cpp:taichi::lang::CuSparseSolver::init_solver@193] Failed to load cusolver library!
我的显卡是nvidia rtx3050 laptop, 使用windows 11, 显卡驱动536.25, cuda版本12.2, 按照nvidia官方的表格,cuda版本和驱动版本是兼容的。