Skip to content

Commit e30ddd1

Browse files
author
Abdullah Mughrabi
committed
added tutorial skeleton
1 parent 3c429ae commit e30ddd1

File tree

14 files changed

+901
-22
lines changed

14 files changed

+901
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef MEMCPY_TUTORIAL_H
2+
#define MEMCPY_TUTORIAL_H
3+
4+
#include <stdint.h>
5+
#include "config.h"
6+
7+
// ********************************************************************************************
8+
// *************** DataStructure **************
9+
// ********************************************************************************************
10+
11+
struct __attribute__((__packed__)) DataArraysTut
12+
{
13+
uint64_t size; // 4-Bytes
14+
uint32_t *array_send; // 8-Bytes pointer
15+
uint32_t *array_receive; // 8-Bytes pointer
16+
};
17+
18+
struct DataArraysTut *newDataArraysTut(struct Arguments *arguments);
19+
void freeDataArraysTut(struct DataArraysTut *dataArraysTut);
20+
void initializeDataArraysTut(struct DataArraysTut *dataArraysTut);
21+
void copyDataArraysTut(struct DataArraysTut *dataArraysTut, struct Arguments *arguments);
22+
uint64_t compareDataArraysTut(struct DataArraysTut *dataArraysTut);
23+
24+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef MEMCPY_TUTORIAL_H
2+
#define MEMCPY_TUTORIAL_H
3+
4+
#include <stdint.h>
5+
#include "config.h"
6+
7+
// ********************************************************************************************
8+
// *************** DataStructure **************
9+
// ********************************************************************************************
10+
11+
struct __attribute__((__packed__)) DataArraysTut
12+
{
13+
uint64_t size; // 4-Bytes
14+
uint32_t *array_send; // 8-Bytes pointer
15+
uint32_t *array_receive; // 8-Bytes pointer
16+
};
17+
18+
struct DataArraysTut *newDataArraysTut(struct Arguments *arguments);
19+
void freeDataArraysTut(struct DataArraysTut *dataArraysTut);
20+
void initializeDataArraysTut(struct DataArraysTut *dataArraysTut);
21+
void copyDataArraysTut(struct DataArraysTut *dataArraysTut, struct Arguments *arguments);
22+
uint64_t compareDataArraysTut(struct DataArraysTut *dataArraysTut);
23+
24+
#endif

00_bench/include/capi_utils/capienv.h

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "myMalloc.h"
66
#include "libcxl.h"
77

8+
9+
#include "memcpy-tutorial.h"
810
#include "memcpy.h"
911
#include "mmtiled.h"
1012

@@ -142,6 +144,38 @@ struct __attribute__((__packed__)) WEDStruct
142144
struct WEDStruct *mapDataArraysToWED(struct DataArrays *dataArrays);
143145
void printWEDPointers(struct WEDStruct *wed);
144146

147+
// ********************************************************************************************
148+
// *************** DataStructure Tutorial **************
149+
// ********************************************************************************************
150+
151+
struct __attribute__((__packed__)) WEDStructTut
152+
{
153+
uint64_t size_send; // 8-Bytes
154+
uint64_t size_recive; // 8-Bytes
155+
void *array_send; // 8-Bytes
156+
void *array_receive; // 8-Bytes
157+
void *pointer1; // 8-Bytes
158+
void *pointer2; // 8-Bytes
159+
void *pointer3; // 8-Bytes
160+
void *pointer4; // 8-Bytes
161+
//---------------------------------------------------//--// 64bytes
162+
void *pointer5; // 8-Bytes
163+
void *pointer6; // 8-Bytes
164+
void *pointer7; // 8-Bytes
165+
void *pointer8; // 8-Bytes
166+
void *pointer9; // 8-Bytes
167+
void *pointer10; // 8-Bytes
168+
void *pointer11; // 8-Bytes
169+
void *pointer12; // 8-Bytes
170+
}; // 32-bytes used from 128-Bytes WED;
171+
172+
// ********************************************************************************************
173+
// *************** afu_config BIT-MAPPING **************
174+
// ********************************************************************************************
175+
176+
struct WEDStructTut *mapDataArraysTutToWED(struct DataArraysTut *dataArraysTut);
177+
void printWEDPointersTut(struct WEDStructTut *wed);
178+
145179
// ********************************************************************************************
146180
// *************** DataStructure **************
147181
// ********************************************************************************************
@@ -185,6 +219,7 @@ void printMMIO_error( uint64_t error );
185219

186220
int setupAFU(struct cxl_afu_h **afu, struct WEDStruct *wed);
187221
int setupAFUMM(struct cxl_afu_h **afu, struct WEDStructMM *wed);
222+
int setupAFUTut(struct cxl_afu_h **afu, struct WEDStructTut *wed);
188223

189224
void startAFU(struct cxl_afu_h **afu, struct AFUStatus *afu_status);
190225
void startCU(struct cxl_afu_h **afu, struct AFUStatus *afu_status);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
#include "memcpy-tutorial.h"
29+
30+
struct DataArraysTut *newDataArraysTut(struct Arguments *arguments){
31+
32+
struct DataArraysTut *dataArraysTut = (struct DataArraysTut *) my_malloc(sizeof(struct DataArraysTut));
33+
34+
dataArraysTut->size = arguments->size;
35+
36+
dataArraysTut->array_send = (uint32_t *) my_malloc(sizeof(uint32_t)* (dataArraysTut->size));
37+
dataArraysTut->array_receive = (uint32_t *) my_malloc(sizeof(uint32_t)* (dataArraysTut->size));
38+
39+
return dataArraysTut;
40+
41+
}
42+
43+
void freeDataArraysTut(struct DataArraysTut *dataArraysTut){
44+
45+
if(dataArraysTut){
46+
if(dataArraysTut->array_send)
47+
free(dataArraysTut->array_send);
48+
if(dataArraysTut->array_receive)
49+
free(dataArraysTut->array_receive);
50+
free(dataArraysTut);
51+
}
52+
}
53+
54+
void initializeDataArraysTut(struct DataArraysTut *dataArraysTut){
55+
56+
uint64_t i;
57+
58+
#pragma omp parallel for
59+
for(i = 0; i < dataArraysTut->size; i++)
60+
{
61+
dataArraysTut->array_send[i] = i;
62+
dataArraysTut->array_receive[i] = 0;
63+
}
64+
}
65+
66+
void copyDataArraysTut(struct DataArraysTut *dataArraysTut, struct Arguments *arguments){
67+
68+
uint64_t i;
69+
70+
#pragma omp parallel for
71+
for(i = 0; i < dataArraysTut->size; i++)
72+
{
73+
//generate READ_CL_NA array_send[i] // read engine
74+
//generate WRITE_CL array_receive[i] // write engine
75+
dataArraysTut->array_receive[i] = dataArraysTut->array_send[i];
76+
}
77+
78+
}
79+
80+
uint64_t compareDataArraysTut(struct DataArraysTut *dataArraysTut){
81+
82+
uint64_t missmatch = 0;
83+
uint64_t i;
84+
85+
#pragma omp parallel for shared(dataArraysTut) reduction(+: missmatch)
86+
for(i = 0; i < dataArraysTut->size; i++)
87+
{
88+
if(dataArraysTut->array_receive[i] != dataArraysTut->array_send[i]){
89+
// printf("[%llu] %u != %u\n",i , dataArraysTut->array_receive[i], dataArraysTut->array_send[i] );
90+
missmatch ++;
91+
}
92+
}
93+
94+
return missmatch;
95+
}

0 commit comments

Comments
 (0)