我编写了CUDA代码。
unsigned long mask_buffer;
int s;
off_t p,
for(p=0;p!=5000;p++)
{
for(s=start;s!=end;s++)
{
ref_off = *(((unsigned int*)(idx_base)) + p);
if((int)(first_indexes[s-start_sequence] % 8 - ref_off % 8) < 0)
{
int shamt2 = (ref_off % 8 - first_indexes[s-start_sequence] % 8);
mask_buffer = *((unsigned long *)(msk_base + (ref_off - first_indexes[s-start_sequence])/8)) >> shamt2;
if( ( (*(unsigned long *)(seqmaskc + 16 * (s-start_sequence))) ^ mask_buffer ) << shamt2)
continue;
}
else if((int)(first_indexes[s-start_sequence] % 8 - ref_off % 8) == 0)
{
mask_buffer = *((unsigned long *)(msk_base + (ref_off)/8));
if( (*(unsigned long *)(seqmaskc + 16 * (s-start_sequence)) ^ mask_buffer))
continue;
}
else
{
int shamt2 = 8 - (first_indexes[s-start_sequence] % 8 - ref_off % 8);
mask_buffer = *((unsigned long *)(msk_base + (ref_off/8- first_indexes[s-start_sequence]/8) - 1)) >> shamt2;
if( ( (*(unsigned long *)(seqmaskc + 16 * (s-start_sequence))) ^ mask_buffer ) << shamt2)
continue;
}
int shamt = (ref_off % 4 - first_indexes[s-start_sequence] % 4) * 2;
memcpy(reference_blk, ref_base + ref_off / 4 - first_indexes[s-start_sequence] / 4, sequence_bytes);
for (rp = last_rp ; rp != (unsigned long *) reference_blk ; rp--)
{
unsigned long tmp = ((*rp) & ((1 << shamt) - 1)) << (8 * sizeof(unsigned long) - shamt);
*rp = (*rp >> shamt) | shifted_in;
shifted_in = tmp;
}
*rp = (*rp >> shamt) | shifted_in;
if (sequence_length & 0x3)
reference_blk[sequence_length >> 2] &= (1 << ((sequence_length & 0x3) << 1)) - 1;
for ( i = sequence_length >> 2 ; i & (SEQUENCE_ALIGN - 1) ; i++ )
reference_blk[i] = 0;
//-- instead of memcmp --//
int v = 0;
char *p1 = (char *)sequence;
char *p2 = (char *)reference_blk;
int tmp_asd = sequence_bytes;
while(tmp_asd!=0)
{
v = *(p1++) - *(p2++);
if(v!=0)
break;
tmp_asd--;
}
if(v == 0)
{
mat_count[s - (int)start_sequence]++; /* Maintain count */
mat_position[s - (int)start_sequence] = ref_off-first_indexes[s-start_sequence]; /* Record latest position */
}
}
}
这个for循环是我的代码的主要功能。 但问题是变量“p”从未超过5或6。 我的计算机上有GT530,我的CUDA驱动程序版本和运行时版本也是4.0。 这段代码有什么问题???
答案 0 :(得分:1)
假设这确实是一个内核,在你的新代码编辑之前你的原始帖子声称它是,你不能在CUDA内核中调用标准的C库函数,如memcpy
(你这样做大约一半 - 通过代码)。您只能在内核中调用__device__
个函数。因此,除非这是在CUDA中重新实现memcpy
,否则在内核中调用该函数是行不通的......
此外,如果您要尝试编写需要检查组中其他线程编写结果的CUDA内核,例如您在内核的内存比较部分进行的操作,则需要在代码中放置一些同步点,以确保在开始检查这些线程的结果之前所有线程都已到达某个点。如果您正在尝试检查另一个块可能写入主内存的内容,那么还有同步原语,以确保任何先前线程块的结果已写入主内存。