修改排序网络后的奇怪行为
weird behavior after modifying sortingnetworks cuda
我需要修改这个CUDA排序网络提供的二进制排序算法。我已经修改了它以接受float2数组的结构,并且所有操作都很好,直到我在内核中添加了一个额外的uint变量。我也在必要的时候正确地修改了函数的声明,但我无缘无故地得到了太多错误,至少从我所能说的。。。这是代码的一部分:
__global__ void bitonicSortShared(
float2 *d_P_out,
float2 *d_P_in,
uint arrayLength,
uint dir,
uint xy
)
{//here gives the Error 2
//Shared memory storage for one or more short vectors
__shared__ float2 s_key[SHARED_SIZE_LIMIT];
//Offset to the beginning of subbatch and load data
d_P_in += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
d_P_out += blockIdx.x * SHARED_SIZE_LIMIT + threadIdx.x;
s_key[threadIdx.x + 0] = d_P_in[ 0];
s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)] = d_P_in[(SHARED_SIZE_LIMIT / 2)];
for (uint size = 2; size < arrayLength; size <<= 1){
//Bitonic merge
uint ddd = dir ^ ((threadIdx.x & (size / 2)) != 0);
for (uint stride = size / 2; stride > 0; stride >>= 1) {
__syncthreads();
uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
Comparator( s_key[pos + 0], s_key[pos + stride], ddd, xy );
}
}
//ddd == dir for the last bitonic merge step
{
for (uint stride = arrayLength / 2; stride > 0; stride >>= 1) {
__syncthreads();
uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
Comparator( s_key[pos + 0], s_key[pos + stride], dir, xy );
}
}
__syncthreads();// here gives the Error 3 and so on
d_P_out[ 0] = s_key[threadIdx.x + 0];
d_P_out[(SHARED_SIZE_LIMIT / 2)] = s_key[threadIdx.x + (SHARED_SIZE_LIMIT / 2)];
}
这里的比较器功能:
__device__ inline void Comparator(
float2 &keyA,
float2 &keyB,
uint dir,
uint xy )
{
float2 t;
if (xy == 0){
if ((keyA.x > keyB.x) == dir) {
t = keyA;
keyA = keyB;
keyB = t;
}
} // I MISSED THAT and the error was reported in the other .cu file. :|
else{
if ((keyA.y > keyB.y) == dir) {
t = keyA;
keyA = keyB;
keyB = t;
}
}
}
这些错误没有任何意义,我已经检查了一遍,以防我忘记了括号或其他什么,但一切都很好。以下是一些错误:
Error 2 error : expected a ";" E:...bitonicSort.cu 27
Error 4 error : explicit type is missing ("int" assumed) E:...bitonicSort.cu 56
Error 5 error : cannot overload functions distinguished by return type alone E:...bitonicSort.cu 56
Error 6 error : the size of an array must be greater than zero E:...bitonicSort.cu 57
Error 7 error : identifier "s_key" is undefined E:...bitonicSort.cu 57
Error 8 error : this declaration has no storage class or type specifier E:...bitonicSort.cu 58
Error 9 error : variable "d_P_out" has already been defined E:...bitonicSort.cu 58
Error 10 error : initialization with "{...}" expected for aggregate object E:...bitonicSort.cu 58
Error 11 error : expected a declaration E:...bitonicSort.cu 59
Error 13 error : expected a declaration E:...bitonicSort.cu 98
Error 14 error : explicit type is missing ("int" assumed) E:...bitonicSort.cu 105
我使用的是visualstudio2010和windows7。提前感谢您的光临!
EDIT错误实际上在包含比较器函数的.cuh文件中。如果你愿意,可以随意投票结束问题。
Comparator
函数在源文件中位于bitonicSortShared
函数之前,并且在Comparator
函数末尾没有足够的大括号。添加一个类似的:
keyB = t;
}
}
}
} // add this curly close-brace
相关文章:
- 选择排序C++(已修改)并非适用于所有情况
- 类(可能是代理)的命名,允许在不修改基础容器的情况下对项目进行排序和删除
- 如何使用用户定义的键控制和修改 std::map 排序
- 内存排序或读取-修改-写入操作,仅(读/写)内存顺序
- 修改的选择排序,选择最大的数字,然后交换到最后
- 带修改(偏移)的气泡排序
- 如何修改函数以按C++的排序顺序插入每个项目
- 修改排序的数组或每次对数组进行排序
- 可修改的多集集:两级排序容器
- 排序向量不断修改数据并打印不正确的结果
- 用于修改网络接口属性的 Win32 API
- 通过修改链接来对链接列表进行排序
- 修改气泡排序的程序出错
- C++迭代器的未排序修改
- 修改排序网络后的奇怪行为
- 使用树排序修改数组
- 在C++11中,未排序的修改警告变为结果未使用的警告
- C++:未排序的修改和对"i"的访问
- 修改c++ std::set中元素中与排序相关的部分
- c++中文件按修改时间排序