MatchLib
Toggle main menu visibility
Main Page
Namespaces
Namespace List
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
Functions
Files
File List
File Members
All
Macros
•
All
Classes
Namespaces
Files
Functions
Modules
Pages
Loading...
Searching...
No Matches
cmod
include
testbench
nvhls_rand.h
1
/*
2
* Copyright (c) 2016-2024, 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
17
#ifndef __NVHLS_RAND__
18
#define __NVHLS_RAND__
19
20
#include <nvhls_int.h>
21
#include <nvhls_types.h>
22
#include <TypeToBits.h>
23
24
namespace
nvhls {
60
inline
int
set_random_seed
() {
61
unsigned
int
seed = 0;
62
#ifdef NVHLS_RAND_SEED
63
seed = (
NVHLS_RAND_SEED
);
64
#endif
65
const
char
*
env_rand_seed
= std::getenv(
"NVHLS_RAND_SEED"
);
66
if
(
env_rand_seed
!=
NULL
) seed =
atoi
(
env_rand_seed
);
67
srand
(seed);
68
cout
<<
"================================"
<<
endl
;
69
cout
<<
dec
<<
"SETTING RANDOM SEED = "
<< seed <<
endl
;
70
cout
<<
"================================"
<<
endl
;
71
return
seed;
72
}
60
inline
int
set_random_seed
() {
…
}
73
92
template
<
typename
Payload>
93
Payload
gen_random_payload
() {
94
Payload
payload
;
95
NVUINTW
(Payload::width)
random
=
rand
();
96
int
num
= Payload::width/32 + 1;
97
for
(
int
i
= 0;
i
<
num
;
i
++) {
98
random
= (
random
<< 32) +
rand
();
99
}
100
sc_lv<Payload::width>
payload_lv
=
TypeToBits<NVUINTW(Payload::width) >
(
random
);
101
payload
=
BitsToType<Payload>
(
payload_lv
);
102
return
payload
;
103
}
93
Payload
gen_random_payload
() {
…
}
122
template
<
int
bitw
id
th>
123
NVUINTW
(
bitwidth
) get_rand() {
124
NVUINTW
(
bitwidth
)
random
=
rand
();
125
int
num
=
bitwidth
/32 + 1;
126
for
(
int
i
= 0;
i
<
num
;
i
++) {
127
random
= (
random
<< 32) +
rand
();
128
}
129
return
random
;
130
}
123
NVUINTW
(
bitwidth
) get_rand() {
…
}
131
132
}
133
#endif
nvhls::gen_random_payload
Payload gen_random_payload()
Generate Random payload of any type.
Definition
nvhls_rand.h:93
NVUINTW
#define NVUINTW(width)
Definition
nvhls_types.h:35
nvhls::get_slc
nvhls_t< W >::nvuint_t get_slc(type X, const unsigned int i)
Function that returns slice of bits.
Definition
nvhls_int.h:437
nvhls::set_random_seed
int set_random_seed()
Set random seed.
Definition
nvhls_rand.h:60
Generated on Thu Apr 24 2025 16:48:01 for MatchLib by
1.9.8