A kernel launch does not return an error code. If the launch configuration is invalid, for example a block with more than 1024 threads, the kernel simply never runs, your output buffer keeps whatever garbage it held, and the program carries on as if nothing happened. CUDA records the failure instead, and you have to ask for it.
Write a host function that launches a kernel and reports whether it worked:
__global__ kernel that writes out[i] = 0.5f * i for every i < n.int fill_half_index(float* out, int n, int threads) where out is a host pointer with room for n floats. Allocate device memory, launch the kernel with threads threads per block and just enough blocks to cover n, and check for errors both right after the launch and after waiting for the kernel to finish.
out, free the device memory and return 0 (cudaSuccess).out untouched and return the error code as an int.n == 0 there is nothing to do: return 0 without launching anything. (A grid of zero blocks is itself an invalid launch.)The tests print the name of the code you return with cudaGetErrorName, so an unchecked failure shows up as cudaSuccess next to garbage. Do not write a main() in your solution.