我正在使用一些从主机到设备发送大量数据的代码,并且行为不正常.
在下面的代码中,我试图从主机向设备发送一个数组.数组大小在每次迭代时递增,逐渐增加发送到设备的内存量.数组中的第一个元素填充非零值,并从内核中读取并打印到控制台.从主机和设备读取时,该值应该相同,但在某些迭代中,它不是.
这是代码:
int SizeArray = 0;
for(int j=1; j<100 ;j++){
//Array memory allocation, starting with 4MB in first iteration to 400MB in last one
SizeArray = j * 1000000 * sizeof(float);
Array = (float*)malloc(SizeArray);
memset(Array, 0, SizeArray);
//Give the array's first element some nonzero value
//This is the value that is expected to be printed by the kernel execution
Array[0] = j;
memArray = clCreateBuffer(context, CL_MEM_READ_WRITE, SizeArray, NULL, &ret);
//Write the array contents into the buffer inside the device …Run Code Online (Sandbox Code Playgroud)