【发布时间】:2021-08-04 10:39:24
【问题描述】:
当我尝试通过 pycuda 运行矩阵乘法示例时。
kernel_code_template = """
__global__ void MatrixMulKernel(float *a,float *b,float *c){
int tx = threadIdx.x;
int ty = threadIdx.y;
float Pvalue = 0;
for(int i=0; i<%(N)s; ++i){
float Aelement = a[ty * %(N)s + i];
float Belement = b[i * %(M)s + tx];
Pvalue += Aelement * Belement;
}
c[ty * %[M]s + tx] = Pvalue;
}
"""
M, N = 2, 3
kernel_code = kernel_code_template % {'M': M, 'N': N}
它报告了如下错误:
kernel_code = kernel_code_template % {'M': M, 'N': N}
TypeError: not enough arguments for format string
我试过检查“%”标记是否有任何问题,但什么都没有。
【问题讨论】:
-
您使用的是哪个版本的 Python?
-
3.7 @Thomas
-
干杯,添加了我的答案。
-
" %[M]s" -- 你打错了