我正在根据雪莉的书在库达中写一个路径追踪器。我的输出是正方形的。
如果改变块的尺寸,块的大小就会改变。对于这个图像,块的尺寸遵循长宽比,基本上16 *9是块大小。我知道,如果不实际显示整个代码,就很难调试它。我只是问你是否知道我应该从哪里开始调试它。我的预感是我的随机数发生器出了问题。这是它的代码,以防我做错了什么。以下是主机代码:
int total_pixel_size = WIDTH * HEIGHT;
size_t frameSize = 3 * total_pixel_size;
// declare random state
int SEED = time(NULL);
thrust::device_ptr<curandState> randState1 = thrust::device_malloc<curandState>(frameSize);
CUDA_CONTROL(cudaGetLastError());
// declare random state 2
thrust::device_ptr<curandState> randState2 = thrust::device_malloc<curandState>(1);
CUDA_CONTROL(cudaGetLastError());
rand_init<<<1, 1>>>(thrust::raw_pointer_cast(randState2),
SEED);
CUDA_CONTROL(cudaGetLastError());
CUDA_CONTROL(cudaDeviceSynchronize());
dim3 blocks(WIDTH / BLOCK_WIDTH + 1,
HEIGHT / BLOCK_HEIGHT + 1);
dim3 threads(BLOCK_WIDTH, BLOCK_HEIGHT);
render_init<<<blocks, threads>>>(
WIDTH, HEIGHT, thrust::raw_pointer_cast(randState1),
SEED);以下是设备代码:
__global__ void rand_init(curandState *randState,
int seed) {
if (threadIdx.x == 0 && blockIdx.x == 0) {
curand_init(seed, 0, 0, randState);
}
}
__global__ void render_init(int mx, int my,
curandState *randState,
int seed) {
if (threadIdx.x == 0 && threadIdx.y == 0) {
curand_init(seed, 0, 0, randState);
}
int i = threadIdx.x + blockIdx.x * blockDim.x;
int j = threadIdx.y + blockIdx.y * blockDim.y;
if ((i >= mx) || (j >= my)) {
return;
}
int pixel_index = j * mx + i;
// same seed, different index
curand_init(seed + pixel_index, pixel_index, 0,
&randState[pixel_index]);
}我真的很感激任何关于这个问题的建议。

。
下面是另一幅具有不同块大小和尺寸但具有相同问题的图像:

发布于 2020-10-08 02:30:57
我设法修好了。它确实与重复的随机序列有关。问题如下。curandState* randState是curandStates的数组,对curand_*的大多数调用都需要一个curandState指针。我将randState (数组)发送到curand_*函数,而不是它的一个成员的指针。现在我的大部分图片都是这样的:

https://computergraphics.stackexchange.com/questions/10247
复制相似问题