Skip to content

Commit 55435bc

Browse files
committed
Backup
1 parent 7f76576 commit 55435bc

File tree

282 files changed

+40430
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+40430
-121
lines changed

cog-experiment/aes.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"inoutStreamsNumber": 1,
3+
"inStreamsNumber": 0,
4+
"outStreamsNumber": 0,
5+
"inStatic": {
6+
"n": 2,
7+
"sizes": [
8+
2,
9+
4
10+
]
11+
},
12+
"outStatic": {
13+
"n": 0,
14+
"sizes": [
15+
]
16+
},
17+
"callingOrder": {
18+
"nTotal": 4,
19+
"order": ["rdx", "rcx", "rsi", "rdi"]
20+
}
21+
}

cog-experiment/aes_ctr_acc.cpp

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//
2+
// Copyright (c) 2017, Intel Corporation
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
//
8+
// Redistributions of source code must retain the above copyright notice, this
9+
// list of conditions and the following disclaimer.
10+
//
11+
// Redistributions in binary form must reproduce the above copyright notice,
12+
// this list of conditions and the following disclaimer in the documentation
13+
// and/or other materials provided with the distribution.
14+
//
15+
// Neither the name of the Intel Corporation nor the names of its contributors
16+
// may be used to endorse or promote products derived from this software
17+
// without specific prior written permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
// POSSIBILITY OF SUCH DAMAGE.
30+
31+
#include <stdint.h>
32+
#include <stdlib.h>
33+
#include <unistd.h>
34+
#include <assert.h>
35+
36+
#include <inttypes.h>
37+
#include <uuid/uuid.h>
38+
39+
#include <iostream>
40+
#include <string>
41+
#include <bits/stdc++.h>
42+
43+
using namespace std;
44+
45+
#include "opae_svc_wrapper.h"
46+
#include "csr_mgr.h"
47+
48+
// State from the AFU's JSON file, extracted using OPAE's afu_json_mgr script
49+
#include "afu_json_info.h"
50+
51+
#ifdef __cplusplus
52+
#define EXTERNC extern "C"
53+
#else
54+
#define EXTERNC
55+
#endif
56+
57+
EXTERNC void aes_ctr_acc(uint8_t key[], uint8_t iv[], uint8_t volatile data[], uint32_t length) {
58+
59+
// Find and connect to the accelerator
60+
OPAE_SVC_WRAPPER fpga(AFU_ACCEL_UUID);
61+
assert(fpga.isOk());
62+
63+
// Connect the CSR manager
64+
CSR_MGR csrs(fpga);
65+
66+
//printf("Page size is %d\n", getpagesize());
67+
68+
69+
auto data_handle = fpga.attachBuffer((uint8_t*)data, getpagesize() * (length/4096));
70+
71+
72+
73+
74+
75+
76+
77+
78+
// Allocate 8 pages memory buffer
79+
/* auto data_handle = fpga.allocBuffer(getpagesize() * (length/4096));
80+
auto *data_fpga = reinterpret_cast<volatile uint8_t*>(data_handle->c_type());
81+
//uint64_t buf_src_pa = buf_src_handle->io_address();
82+
assert(NULL != data_fpga);
83+
84+
for(int i = 0; i<length; i++){
85+
data_fpga[i] = data[i];
86+
}*/
87+
88+
/*
89+
//printf("Buf src virtual address is %p\n", buf_src);
90+
91+
// Allocate 8 pages memory buffer
92+
auto buf_dest_handle = fpga.allocBuffer(getpagesize() * ((DATA_LENGTH)/4096));
93+
auto *buf_dest = reinterpret_cast<volatile uint8_t*>(buf_dest_handle->c_type());
94+
uint64_t buf_dest_pa = buf_dest_handle->io_address();
95+
assert(NULL != buf_dest);
96+
*(buf_dest+(DATA_LENGTH)-1) = 0;
97+
98+
printf("Buf dest virtual address is %p\n", buf_dest);
99+
*/
100+
101+
csrs.writeCSR(0, (uint64_t)data); // Address of src
102+
csrs.writeCSR(1, (uint64_t)data); // Address of dest
103+
csrs.writeCSR(2, (uint64_t)(length/64)); // How many cache lines?
104+
//csrs.writeCSR(2, (uint64_t)1); // How many cache lines?
105+
// Need to check how to convert from uint8_t array to uint64_t
106+
csrs.writeCSR(4, (uint64_t)*(uint64_t*)iv); // IV 0
107+
csrs.writeCSR(5, (uint64_t)*(uint64_t*)(iv+8)); // IV 1
108+
csrs.writeCSR(6, (uint64_t)*(uint64_t*)key); // key 0
109+
csrs.writeCSR(7, (uint64_t)*(uint64_t*)(key+8)); // key 1
110+
csrs.writeCSR(8, (uint64_t)*(uint64_t*)(key+16)); // key 2
111+
csrs.writeCSR(9, (uint64_t)*(uint64_t*)(key+24)); // key 3
112+
csrs.writeCSR(3, (uint64_t)1); // Run signal
113+
114+
// Spin, waiting for the value in memory to change to something non-zero.
115+
while (0 == csrs.readCSR(0))_mm_pause();
116+
117+
/* for(int i = 0; i<length; i++){
118+
data[i] = data_fpga[i];
119+
}*/
120+
121+
//printf("Data received!\n");
122+
123+
return;
124+
125+
}

0 commit comments

Comments
 (0)