#include void logDevices() { int count; if (cudaGetDeviceCount(&count) != cudaSuccess) { printf("No CUDA devices found\n"); return; } printf("CUDA devices found: %d\n", count); for (int i = 0; i < count; ++i) { cudaDeviceProp properties; if (cudaGetDeviceProperties(&properties, i) == cudaSuccess) { printf("Device [%d]: %s\n", i, properties.name); } } } __global__ void kernel(int* array, int N) { for (int i = 0; i < N; ++i) { array[i] = i; } } int main() { logDevices(); constexpr int N = 100; int* host_array = new int[N]; int* device_array = nullptr; bool success = false; if (cudaMalloc(&device_array, N * sizeof(int)) != cudaSuccess) { goto cleanup; } kernel<<<1, 1>>>(device_array, N); if (cudaMemcpy( host_array, device_array, N * sizeof(int), cudaMemcpyDeviceToHost) != cudaSuccess) { goto cleanup; } for (int i = 0; i < N; ++i) { printf("%d ", host_array[i]); } printf("\n"); success = true; cleanup: delete[] host_array; if (device_array != nullptr) { cudaFree(device_array); } return success ? 0 : 1; }