1
+ // -----------------------------------------------------------------------------
2
+ //
3
+ // "CAPIPrecis"
4
+ //
5
+ // -----------------------------------------------------------------------------
6
+ // Copyright (c) 2014-2019 All rights reserved
7
+ // -----------------------------------------------------------------------------
8
+ // Author : Abdullah Mughrabi
9
+
10
+ // File : memcpy.c
11
+ // Create : 2019-09-28 14:41:30
12
+ // Revise : 2019-11-29 11:17:40
13
+ // Editor : Abdullah Mughrabi
14
+ // -----------------------------------------------------------------------------
15
+ #include <stdio.h>
16
+ #include <stdlib.h>
17
+ #include <stdint.h>
18
+ #include <unistd.h>
19
+ #include <string.h>
20
+ #include <math.h>
21
+ #include <omp.h>
22
+
23
+ #include "mt19937.h"
24
+ #include "timer.h"
25
+ #include "myMalloc.h"
26
+ #include "config.h"
27
+
28
+ //CAPI
29
+ #include "libcxl.h"
30
+ #include "capienv.h"
31
+
32
+ #include "memcpy-tutorial.h"
33
+
34
+ struct DataArraysTut * newDataArraysTut (struct Arguments * arguments ){
35
+
36
+ struct DataArraysTut * dataArraysTut = (struct DataArraysTut * ) my_malloc (sizeof (struct DataArraysTut ));
37
+
38
+ dataArraysTut -> size = arguments -> size ;
39
+
40
+ dataArraysTut -> array_send = (uint32_t * ) my_malloc (sizeof (uint32_t )* (dataArraysTut -> size ));
41
+ dataArraysTut -> array_receive = (uint32_t * ) my_malloc (sizeof (uint32_t )* (dataArraysTut -> size ));
42
+
43
+ return dataArraysTut ;
44
+
45
+ }
46
+
47
+ void freeDataArraysTut (struct DataArraysTut * dataArraysTut ){
48
+
49
+ if (dataArraysTut ){
50
+ if (dataArraysTut -> array_send )
51
+ free (dataArraysTut -> array_send );
52
+ if (dataArraysTut -> array_receive )
53
+ free (dataArraysTut -> array_receive );
54
+ free (dataArraysTut );
55
+ }
56
+ }
57
+
58
+ void initializeDataArraysTut (struct DataArraysTut * dataArraysTut ){
59
+
60
+ uint64_t i ;
61
+
62
+ #pragma omp parallel for
63
+ for (i = 0 ; i < dataArraysTut -> size ; i ++ )
64
+ {
65
+ dataArraysTut -> array_send [i ] = i ;
66
+ dataArraysTut -> array_receive [i ] = 0 ;
67
+ }
68
+ }
69
+
70
+ void copyDataArraysTut (struct DataArraysTut * dataArraysTut , struct Arguments * arguments ){
71
+
72
+ // uint64_t i;
73
+
74
+ // #pragma omp parallel for
75
+ // for(i = 0; i < dataArraysTut->size; i++)
76
+ // {
77
+ // //generate READ_CL_NA array_send[i] // read engine
78
+ // //generate WRITE_CL array_receive[i] // write engine
79
+ // dataArraysTut->array_receive[i] = dataArraysTut->array_send[i];
80
+ // }
81
+
82
+ struct cxl_afu_h * afu ;
83
+
84
+ // ********************************************************************************************
85
+ // *************** MAP CSR DataStructure **************
86
+ // ********************************************************************************************
87
+
88
+ struct WEDStructTut * wed = mapDataArraysTutToWED (dataArraysTut );
89
+
90
+ // ********************************************************************************************
91
+ // *************** Setup AFU **************
92
+ // ********************************************************************************************
93
+
94
+ setupAFUTut (& afu , wed );
95
+
96
+ struct AFUStatus afu_status = {0 };
97
+ afu_status .afu_config = arguments -> afu_config ;
98
+ afu_status .afu_config_2 = arguments -> afu_config_2 ;
99
+ afu_status .cu_config = arguments -> cu_config ; // non zero CU triggers the AFU to work
100
+ afu_status .cu_config = ((afu_status .cu_config << 24 ) | (arguments -> numThreads ));
101
+ afu_status .cu_config_2 = afu_status .cu_config_2 ;
102
+ afu_status .cu_config_3 = 1 ;
103
+ afu_status .cu_config_4 = 1 ;
104
+ afu_status .cu_stop = wed -> size_send ;
105
+
106
+ startAFU (& afu , & afu_status );
107
+
108
+ // ********************************************************************************************
109
+ // *************** START AFU **************
110
+ // ********************************************************************************************
111
+
112
+ startCU (& afu , & afu_status );
113
+
114
+ // ********************************************************************************************
115
+ // *************** WAIT AFU **************
116
+ // ********************************************************************************************
117
+
118
+ waitAFU (& afu , & afu_status );
119
+
120
+ printMMIO_error (afu_status .error );
121
+
122
+ releaseAFU (& afu );
123
+ free (wed );
124
+
125
+
126
+
127
+ }
128
+
129
+ uint64_t compareDataArraysTut (struct DataArraysTut * dataArraysTut ){
130
+
131
+ uint64_t missmatch = 0 ;
132
+ uint64_t i ;
133
+
134
+ #pragma omp parallel for shared(dataArraysTut) reduction(+: missmatch)
135
+ for (i = 0 ; i < dataArraysTut -> size ; i ++ )
136
+ {
137
+ if (dataArraysTut -> array_receive [i ] != dataArraysTut -> array_send [i ]){
138
+ // printf("[%llu] %u != %u\n",i , dataArraysTut->array_receive[i], dataArraysTut->array_send[i] );
139
+ missmatch ++ ;
140
+ }
141
+ }
142
+
143
+ return missmatch ;
144
+ }
0 commit comments