MatchLib
All Classes Namespaces Files Functions Modules Pages
ScratchpadTypes.h
1/*
2 * Copyright (c) 2016-2021, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef SCRATCHPAD_TYPES_H
17#define SCRATCHPAD_TYPES_H
18
19#include <nvhls_int.h>
20#include <nvhls_types.h>
21#include <nvhls_message.h>
22#include <comptrees.h>
23
24
25// Define enums for request type
26enum ScratchpadOpcode_enum {LOAD, STORE, ScratchpadOpcode_Length};
27static const unsigned int kScratchpadOpcodeSize = ac::log2_ceil<ScratchpadOpcode_Length>::val;
28typedef NVUINTW(kScratchpadOpcodeSize) ScratchpadOpcode;
29
30template <typename T, unsigned int AddrWidth, unsigned int N>
31class cli_req_t : public nvhls_message
32{
33 public:
34 static const unsigned int type_width = Wrapped<T>::width;
35 static const unsigned int width = kScratchpadOpcodeSize + N + N * (AddrWidth + type_width);
36
37 ScratchpadOpcode opcode;
38 sc_lv<N> valids;
39 NVUINTW(AddrWidth) addr [N];
40 T data [N];
41
42 template<unsigned int Size>
43 void Marshall(Marshaller<Size>& m) {
44 m & opcode;
45 m & valids;
46 #pragma hls_unroll yes
47 for (unsigned int i=0; i<N; i++) m & addr[i];
48 #pragma hls_unroll yes
49 for (unsigned int i=0; i<N; i++) m & data[i];
50 }
51};
52
53
54template <typename T, unsigned int N>
55class cli_rsp_t : public nvhls_message
56{
57public:
58 sc_lv<N> valids;
59 T data [N];
60 static const unsigned int type_width = Wrapped<T>::width;
61 static const unsigned int width = N + type_width * N;
62 template <unsigned int Size>
63 void Marshall(Marshaller<Size>& m) {
64 m & valids;
65 #pragma hls_unroll yes
66 for (unsigned int i=0; i<N; i++) m & data[i];
67 }
68
69};
70
71#endif
#define NVUINTW(width)
Definition nvhls_types.h:35