我在运行官方给出的sparse matrix 例子时将backend改为cuda
import taichi as ti
arch = ti.cuda # or ti.cuda
ti.init(arch=arch)
n = 4
# step 1: create sparse matrix builder
K = ti.linalg.SparseMatrixBuilder(n, n, max_num_triplets=100)
@ti.kernel
def fill(A: ti.types.sparse_matrix_builder()):
for i in range(n):
A[i, i] += i # Only += and -= operators are supported for now.
# step 2: fill the builder with data.
fill(K)
print(">>>> K.print_triplets()")
K.print_triplets()
# outputs:
# >>>> K.print_triplets()
# n=4, m=4, num_triplets=4 (max=100)(0, 0) val=1.0(1, 1) val=1.0(2, 2) val=1.0(3, 3) val=1.0
# step 3: create a sparse matrix from the builder.
A = K.build()
print(">>>> A = K.build()")
print(A)
会在K.build()时报以下错误
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbbd, win, python 3.10.5
[Taichi] Starting on arch=cuda
n=4, m=4, num_triplets=4 (max=100)
[0, 0] = 0.0
[1, 1] = 1.0
[2, 2] = 2.0
[3, 3] = 3.0
[W 07/08/23 10:29:06.388 32924] [cuda_driver.cpp:taichi::lang::CUDADriverBase::load_lib@36] cusparse64_12.dll lib not found.
[E 07/08/23 10:29:06.388 32924] [taichi/program/sparse_matrix.h:taichi::lang::CuSparseMatrix::CuSparseMatrix@228] Failed to load cusparse library!
Traceback (most recent call last):
File "C:\Users\tzn\Desktop\notes\py\taichi\sparse.py", line 19, in <module>
A = K.build()
File "C:\Users\tzn\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\linalg\sparse_matrix.py", line 291, in build
sm = self.ptr.build_cuda()
RuntimeError: [taichi/program/sparse_matrix.h:taichi::lang::CuSparseMatrix::CuSparseMatrix@228] Failed to load cusparse library!