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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| #include <stdio.h>
void init_array(int* arr, int n, int start_num){ int i; for(i = 0; i < n; i++) { arr[i] = start_num + i; } }
void use_into() { int n = 3, i; int p[n], p1[n];
init_array(p, n, 0); init_array(p1, n, n);
for(i = 0; i < n; i++) { printf("before offload: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n; i++) { printf("before offload: p1[%d] is %d\n", i, p1[i]); }
printf("==============================\n"); #pragma offload target(mic) in(p[0:n] : into(p1[0:n])) out(p1) { for(i = 0; i < n; i++) { printf("On Mic: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n; i++) { printf("On Mic: p1[%d] is %d\n", i, p1[i]); } }
for(i = 0; i < n; i++) { printf("after offload: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n; i++) { printf("after offload: p1[%d] is %d\n", i, p1[i]); }
printf("==============================\n"); }
void use_into2() { int n = 4, i; int p[n], p1[n+1], p2[n-1];
init_array(p, n, 0); init_array(p1, n+1, n); init_array(p2, n-1, 2*n+1);
for(i = 0; i < n; i++) { printf("before offload: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n+1; i++) { printf("before offload: p1[%d] is %d\n", i, p1[i]); } for(i = 0; i < n-1; i++) { printf("before offload: p2[%d] is %d\n", i, p2[i]); } printf("==============================\n"); #pragma offload target(mic) in(p[0:n]:into(p1[0:n+1])) in(p[0:n-1]:into(p2[0:n-1])) out(p1) out(p2) { for(i = 0; i < n; i++) { printf("on mic: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n+1; i++) { printf("on mic: p1[%d] is %d\n", i, p1[i]); } for(i = 0; i < n-1; i++) { printf("on mic: p2[%d] is %d\n", i, p2[i]); } }
for(i = 0; i < n; i++) { printf("after offload: p[%d] is %d\n", i, p[i]); } for(i = 0; i < n+1; i++) { printf("after offload: p1[%d] is %d\n", i, p1[i]); } for(i = 0; i < n-1; i++) { printf("after offload: p2[%d] is %d\n", i, p2[i]); } printf("==============================\n"); }
void use_into3() { int n = 10, i; int p[n * n]; int a[n][n];
init_array(p, n * n, 0); #pragma offload target(mic) in(p:into(a)) out(a:into(p)) { for(i = 0; i < n; i++) { printf("on mic: a[%d][0] is %d\n", i, a[i][0]);
}
a[0][0] = 1000; a[1][0] = 1000; }
printf("p[0] is %d and p[10] is %d\n", p[0], p[10]); printf("==============================\n"); }
int main() { use_into(); }
|