filed.fill 函数不支持i64类型?

我在使用fill函数时遇到了问题
那就是,在设置 default_ip=ti.i64
的情况下再使用fill(1)遇到了错误
具体代码报错为:

[Taichi] version 1.1.3, llvm 10.0.0, commit 1262a70a, win, python 3.10.7
[Taichi] Starting on arch=x64
C:\Users\001\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\ast\ast_transformer.py:38: Warning: Casting range_for 
boundary values from i64 to i32, which may cause numerical issues
  warnings.warn(
[I 09/24/22 10:00:39.829 6296] [D:/a/taichi/taichi/taichi/codegen/llvm/llvm_codegen_utils.cpp:check_func_call_signature@134] Function : Dense_lookup_element
[I 09/24/22 10:00:39.829 6296] [D:/a/taichi/taichi/taichi/codegen/llvm/llvm_codegen_utils.cpp:check_func_call_signature@135]     Type : i8* (i8*, i8*, i32)
[E 09/24/22 10:00:39.830 6296] [D:/a/taichi/taichi/taichi/codegen/llvm/llvm_codegen_utils.cpp:check_func_call_signature@144]   parameter 
2 mismatch: required=i32, provided=i64


Traceback (most recent call last):
  File "c:\Code\python\Test\test7.py", line 18, in <module>
    prefix_sum()
  File "C:\Users\001\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\kernel_impl.py", line 915, in wrapped
    return primal(*args, **kwargs)
  File "C:\Users\001\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\kernel_impl.py", line 842, in __call__        
    return self.runtime.compiled_functions[key](*args)
  File "C:\Users\001\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\kernel_impl.py", line 769, in func__
    raise e from None
  File "C:\Users\001\AppData\Local\Programs\Python\Python310\lib\site-packages\taichi\lang\kernel_impl.py", line 766, in func__
    t_kernel(launch_ctx)
RuntimeError: [D:/a/taichi/taichi/taichi/codegen/llvm/llvm_codegen_utils.cpp:check_func_call_signature@144]   parameter 2 mismatch: required=i32, provided=i64

报错说只支持i32类型
以下为源代码

import taichi as ti

ti.init(arch=ti.cpu, default_ip=ti.i64)
n = 1024
val = ti.field(dtype=ti.i64, shape=n)
val.fill(1)


@ti.kernel
def prefix_sum():
    ti.loop_config(serialize=True)
    for i in range(1, 1024):
        val[i] += val[i - 1]


prefix_sum()
print(val)

fill函数在我的理解里,应该也支持填充i64、f64类型吧

我理解错上,上述代码不是在 val.fill(1) 处报错
而是在
for i in range(1, 1024):
val[i] += val[i - 1]
报错
怎样才能避免这种错误呢?

我知道了
val[ti.i32(i)] += val[ti.i32(i-1)]
就能避免报错
感觉这点可以优化

Hi @sanxiadaba , 非常欢迎来到Taichi论坛。

因为你初始化时默认精度是i64,所以在for循环里val的idx是i64,但Taichi需要的是i32的idx。这确实是个问题,你可以提个ISSUE么?

感谢回答,这就提1issue去

2 Likes