Added a few clearing-up code tweaks

This commit is contained in:
Martin Opat 2024-11-14 12:17:09 +01:00
parent c8e17dfe4f
commit 0bdb7195de
3 changed files with 3 additions and 13 deletions

View File

@ -1,25 +1,14 @@
#include <iostream> #include <iostream>
#include <cuda_runtime.h> #include <cuda_runtime.h>
#define cudaCheckError() { \
cudaError_t e = cudaGetLastError(); \
if (e != cudaSuccess) { \
printf("CUDA error %s:%d: %s\n", __FILE__, __LINE__, \
cudaGetErrorString(e)); \
exit(EXIT_FAILURE); \
} \
}
__global__ void hello_from_gpu() { __global__ void hello_from_gpu() {
printf("Hello from GPU!\n"); printf("Hello from GPU!\n");
} }
int main() { int main() {
hello_from_gpu<<<1, 1>>>(); hello_from_gpu<<<1, 1>>>();
cudaCheckError();
cudaDeviceSynchronize(); cudaDeviceSynchronize();
cudaCheckError();
// Reset device // Reset device
cudaDeviceReset(); cudaDeviceReset();

View File

@ -65,9 +65,10 @@ __global__ void renderKernel(unsigned char* framebuffer, Sphere* spheres, int nu
Vec3 rayOrigin(0, 0, 0); Vec3 rayOrigin(0, 0, 0);
Vec3 colCum(0, 0, 0); Vec3 colCum(0, 0, 0);
double spp = static_cast<double>(SAMPLES_PER_PIXEL);
for (int sample = 0; sample < SAMPLES_PER_PIXEL; sample++) { for (int sample = 0; sample < SAMPLES_PER_PIXEL; sample++) {
double u = (x + (sample / static_cast<double>(SAMPLES_PER_PIXEL)) - WIDTH / 2.0) / WIDTH; double u = (x + (sample / spp) - WIDTH / 2.0) / WIDTH;
double v = (y + (sample / static_cast<double>(SAMPLES_PER_PIXEL)) - HEIGHT / 2.0) / HEIGHT; double v = (y + (sample / spp) - HEIGHT / 2.0) / HEIGHT;
Vec3 rayDir(u, v, 1.0); Vec3 rayDir(u, v, 1.0);
rayDir = rayDir.normalize(); rayDir = rayDir.normalize();