Intel HEXL for FPGA
Intel Homomorphic Encryption FPGA Acceleration Library, accelerating the modular arithmetic operations used in homomorphic encryption.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fpga_assert.h
Go to the documentation of this file.
1 // Copyright (C) 2020-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #ifndef __FPGA_ASSERT_H__
5 #define __FPGA_ASSERT_H__
6 
7 #define FPGA_ASSERT_1_ARGS(condition) FPGA_ASSERT_INT(condition, 0)
8 #define FPGA_ASSERT_2_ARGS(condition, message) \
9  FPGA_ASSERT_INT(condition, message)
10 
11 #define GET_ARG(arg1, arg2, func, ...) func
12 #define FPGA_ASSERT_MACRO_CHOOSER(...) \
13  GET_ARG(__VA_ARGS__, FPGA_ASSERT_2_ARGS, FPGA_ASSERT_1_ARGS)
14 
15 #define FPGA_ASSERT(...) FPGA_ASSERT_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
16 
17 #ifdef FPGA_DEBUG
18 #include <iostream>
19 
20 #include "stack_trace.h"
21 
22 #define FPGA_ASSERT_INT(condition, message) \
23  { \
24  if (!(condition)) { \
25  std::cerr << "Assertion: '" << #condition << "' failed at " \
26  << __FILE__ << ":" << __LINE__ << std::endl; \
27  if (message) { \
28  std::cerr << " Error: " << #message << std::endl; \
29  } \
30  intel::hexl::fpga::StackTrace* stack = \
31  intel::hexl::fpga::StackTrace::stack(); \
32  stack->dump(std::cerr); \
33  abort(); \
34  exit(1); \
35  } \
36  }
37 
38 #else
39 
40 #define FPGA_ASSERT_INT(condition, message) \
41  {}
42 
43 #endif
44 
45 #endif