报错内容如下,在 ti.cpu 下就没有问题:
TypeError: unsupported operand type(s) for *: 'taichi._lib.core.taichi_python.CuSparseMatrix' and 'taichi._lib.core.taichi_python.CuSparseMatrix'
今天运行文档中的案例的时候出现了这个错误,我也不知道是哪里的问题,而且没有第二个 cuda 设备,我也不知道是不是我环境装得不对导致的。
运行环境:
- Windows 11 22H2
- RTX 3060 Laptop CUDA 12.0
- Python 3.8.15
- Taichi 1.4.0 commit fbe92fd8
- llvm 15.0.1
运行的整个代码:
import taichi as ti
arch = ti.cuda
ti.init(arch=arch, debug=True)
n = 3
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] += 1
fill(K)
print(">>>> K.print_triplets()")
K.print_triplets()
A = K.build()
print(">>>> A = K.build()")
print(A)
print(">>>> Multiplication with a scalar on the right: E = A * 3.0")
E = A * 3.0
print(E)
print(">>>> Element-wise multiplication: H = E * A")
H = E * A
print(H)
print(f">>>> Element Access: A[0,0] = {A[0,0]}")
整个报错片段:
Traceback (most recent call last):
File ".\test.py", line 28, in <module>
H = E * A
File "C:\Users\m\miniconda3\envs\taichi\lib\site-packages\taichi\linalg\sparse_matrix.py", line 92, in __mul__
sm = self.matrix * other.matrix
TypeError: unsupported operand type(s) for *: 'taichi._lib.core.taichi_python.CuSparseMatrix' and 'taichi._lib.core.taichi_python.CuSparseMatrix'