ex7: start

This commit is contained in:
2025-11-04 13:11:12 +01:00
parent a4578d1c26
commit 0813765831

View File

@@ -1,3 +1,4 @@
#include <cuda_runtime_api.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
@@ -11,7 +12,8 @@
// TASK: T1
// Include the cooperative groups library
// BEGIN: T1
;
#include <cooperative_groups.h>
namespace cg = cooperative_groups; // TODO
// END: T1
// Convert 'struct timeval' into seconds in double prec. floating point
@@ -172,6 +174,28 @@ void occupancy(void) {
// Make sure at least one CUDA-capable device exists
static bool init_cuda() {
// BEGIN: T2
int count;
if (cudaGetDeviceCount(&count) != cudaSuccess)
return false;
printf("CUDA device count: %d\n", count);
if (count > 0) {
cudaDeviceProp p;
if (cudaSetDevice(0) != cudaSuccess)
return false;
if (cudaGetDeviceProperties(&p, 0) != cudaSuccess)
return false;
printf("CUDA device #0:\n");
printf(" Name: %s\n", p.name);
printf(" Compute capability: %d.%d\n", p.major, p.minor);
printf(" Multiprocessors: %d\n", p.multiProcessorCount);
printf(" Warp size: %d\n", p.warpSize);
printf(" Global memory: %.1fGiB bytes\n", p.totalGlobalMem / (1024.0 * 1024.0 * 1024.0));
printf(" Per-block shared memory: %.1fKiB\n", p.sharedMemPerBlock / 1024.0);
printf(" Per-block registers: %d\n", p.regsPerBlock);
}
return true;
// END: T2
}