MatchLib
All Classes Namespaces Files Functions Modules Pages
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
24namespace nvhls {
60inline 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}
73
92template < typename 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 }
102 return payload;
103}
122template < int bitwidth>
123NVUINTW(bitwidth) get_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}
131
132}
133#endif
Payload gen_random_payload()
Generate Random payload of any type.
Definition nvhls_rand.h:93
#define NVUINTW(width)
Definition nvhls_types.h:35
nvhls_t< W >::nvuint_t get_slc(type X, const unsigned int i)
Function that returns slice of bits.
Definition nvhls_int.h:437
int set_random_seed()
Set random seed.
Definition nvhls_rand.h:60