-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathOptimizeLogic
46 lines (36 loc) · 1.11 KB
/
OptimizeLogic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <omp.h>
#define MAX_ITERATIONS 100
// Loop unrolling (4x)
void PMLL_LogicLoop_Optimized() {
#pragma omp parallel for
for (int i = 0; i < MAX_ITERATIONS; i += 4) {
printf("Updating memory graph at iteration %d\n", i);
printf("Updating memory graph at iteration %d\n", i + 1);
printf("Updating memory graph at iteration %d\n", i + 2);
printf("Updating memory graph at iteration %d\n", i + 3);
}
}
int main() {
PMLL_LogicLoop_Optimized();
return 0;
}
#include <cuda_runtime.h>
#include <stdio.h>
__global__ void PMLL_LogicLoop_GPU(int *counter) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < MAX_ITERATIONS) {
printf("Updating memory graph at iteration %d\n", tid);
}
}
int main() {
int *d_counter;
cudaMalloc((void **)&d_counter, sizeof(int));
cudaMemset(d_counter, 0, sizeof(int));
dim3 blockSize(256);
dim3 gridSize((MAX_ITERATIONS + blockSize.x - 1) / blockSize.x);
PMLL_LogicLoop_GPU<<<gridSize, blockSize>>>(d_counter);
cudaDeviceSynchronize();
cudaFree(d_counter);
return 0;
}