当字符串元素相等时,请复制相同的字符串,否则在此类条目中将“ XXX”指定为新的字符串元素。
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
c = numpy.random.randn(2,2)
c = c.astype(numpy.str)
d = numpy.random.randn(2,2)
d = d.astype(numpy.str)
for i in range(0,2):
for j in range(0,2):
c[i][j]= input("Value for c")
d[i][j]= input("Value for d")
Value for c aaa
Value for d aa
Value for c bbb
Value for d bbb
Value for c xxx
Value for d xxx
Value for c yyy
Value for d yy
c_gpu = cuda.mem_alloc(c.nbytes)
d_gpu = cuda.mem_alloc(d.nbytes)
cuda.memcpy_htod(c_gpu, c)
cuda.memcpy_htod(d_gpu, d)
module1 = SourceModule ("""
__global__ void com(char **c, char **d)
{
int idx = threadIdx.x + threadIdx.y*blockDim.x;
if(c[idx] == d[idx])
c[idx] = c[idx];
else
c[idx]= "XXX";
}
""")
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:10:UserWarning:CUDA编译器成功,但表示以下内容: kernel.cu(9):警告:不建议将字符串文字转换为“ char *”
#加载内容时,从sys.path中删除CWD。 p>
fy = module1.get_function("com")
fy(c_gpu, d_gpu, block=(2,2,1))
x = numpy.empty_like(c)
cuda.memcpy_dtoh(x, c_gpu)
print(x)
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-14-fc17d851ef81> in <module>()
----> 1 print(x)
7 frames
/usr/local/lib/python3.6/dist-packages/numpy/core/arrayprint.py in recurser(index, hanging_indent, curr_width)
734
735 if axes_left == 0:
--> 736 return format_function(a[index])
737
738 # when recursing, add a space to align with the [ added, and reduce the
UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 8-11: code point not in range(0x110000)