FK20 CUDA
frtest.cu
Go to the documentation of this file.
1 // bls12_381: Arithmetic for BLS12-381
2 // Copyright 2022-2023 Dag Arne Osvik
3 // Copyright 2022-2023 Luan Cardoso dos Santos
4 
5 #include "fr.cuh"
6 #include "frtest.cuh"
7 
8 __managed__ testval_t testval[TESTVALS];
9 
11 
16 void init() {
17 
18  testinit();
19 
20  uint64_t
21  p0 = 0xFFFFFFFF00000001U,
22  p1 = 0x53BDA402FFFE5BFEU,
23  p2 = 0x3339D80809A1D805U,
24  p3 = 0x73EDA753299D7D48U;
25 
26  int i = 0;
27 
28  for (int j=0; j<TESTVALS; j++) {
29  testval[j][0] = 0;
30  testval[j][1] = 0;
31  testval[j][2] = 0;
32  testval[j][3] = 0;
33  }
34 
35  {
36  testval[i][0] = p0;
37  testval[i][1] = p1;
38  testval[i][2] = p2;
39  testval[i][3] = p3;
40  }
41  i++;
42 
43  {
44  testval[i][0] = ~p0;
45  testval[i][1] = ~p1;
46  testval[i][2] = ~p2;
47  testval[i][3] = ~p3;
48  }
49  i++;
50 
51  i++; // The third value is 0
52 
53  for (int j=0; j<64; i++,j++) { testval[i][0] = 1ULL << j; }
54  for (int j=0; j<64; i++,j++) { testval[i][1] = 1ULL << j; }
55  for (int j=0; j<64; i++,j++) { testval[i][2] = 1ULL << j; }
56  for (int j=0; j<64; i++,j++) { testval[i][3] = 1ULL << j; }
57 
58  for (int j=2; j<258; i++,j++) {
59  testval[i][0] = ~testval[j][0];
60  testval[i][1] = ~testval[j][1];
61  testval[i][2] = ~testval[j][2];
62  testval[i][3] = ~testval[j][3];
63  }
64 
65  FILE *pf = fopen("/dev/urandom", "r");
66 
67  if (!pf)
68  return;
69 
70  size_t result = fread(&testval[i], sizeof(testval_t), TESTVALS-i, pf);
71 
72  printf("Fixed/random test values: %d/%d\n", i, TESTVALS-i);
73 }
74 
76 //Shorthand for testing a function, with an error check and timer
77 #define TEST(X) \
78  start = clock(); \
79  X <<<1,block>>> (&testval[0]); \
80  err = cudaDeviceSynchronize(); \
81  end = clock(); \
82  if (err != cudaSuccess) printf("Error %d\n", err); \
83  printf(" (%.2f s)\n", (end - start) * (1.0 / CLOCKS_PER_SEC));
84 
86 
94 int main(int argc, char **argv) {
95  clock_t start, end;
96  cudaError_t err;
97 
98  int level = 0;
99 
100  if (argc > 1)
101  level = atoi(argv[1]);
102 
103  init();
104 
105  dim3 block = 1;
106 
107  TEST(FrTestKAT);
108  if (err != cudaSuccess) {
109  return err;
110  }
111  FrTestFFT();
112 
113  if (level >= 1) {
114  TEST(FrTestCmp);
116  TEST(FrTestSub);
118  }
119 
120  if (level >= 2) {
124  }
125 
126  if (level >= 3) {
133  }
134 
135 /*
136  TEST(FrTestCopy);
137  TEST(FrTestNeg);
138  TEST(FrTestMul);
139  TEST(FrTestInv);
140 
141  TEST(FrTestReflexivity);
142  TEST(FrTestSymmetry);
143  TEST(FrTestAdditiveIdentity);
144  TEST(FrTestMultiplicativeIdentity);
145  TEST(FrTestAdditiveInverse);
146  TEST(FrTestMultiplicativeInverse);
147 */
148 
149  return 0;
150 }
151 
152 // vim: ts=4 et sw=4 si
#define TESTVALS
Definition: fptest.cuh:13
void init()
initialize test values
Definition: frtest.cu:16
int main(int argc, char **argv)
Self test of the functions over Fr.
Definition: frtest.cu:94
#define TEST(X)
Definition: frtest.cu:77
__managed__ testval_t testval[TESTVALS]
Definition: frtest.cu:8
void FrTestFFT()
Tests fft and inverse fft over Fr using KAT.
Definition: frtest_fft.cu:17
__global__ void FrTestCommutativeAdd(testval_t *testval)
Test the cumulative property of addition.
Definition: frtest_add.cu:16
__global__ void FrTestAssociativeAdd(testval_t *testval)
Test the associative property of addition.
Definition: frtest_add.cu:58
__global__ void FrTestAddSub(testval_t *testval)
Test for the fr_addsub kernel.
__global__ void FrTestCmp(testval_t *testval)
Test for the comparison function; checks for inconsistencies in the following properties:
Definition: frtest_cmp.cu:21
__global__ void FrTestSubDistributiveLeft(testval_t *testval)
Check the distributive property of multiplication in Fr (left of subtraction):
__global__ void FrTestAddDistributiveRight(testval_t *testval)
Check the distributive property of multiplication in Fr (right of addition):
__global__ void FrTestAddDistributiveLeft(testval_t *testval)
Check the distributive property of multiplication in Fr (left of addition):
__global__ void FrTestSubDistributiveRight(testval_t *testval)
Check the distributive property of multiplication in Fr (right of subtraction):
__global__ void FrTestFibonacci(testval_t *)
Test addition and subtraction in Fr using a fibonacci sequence (chain dependency) from 1 to ITERATION...
__global__ void FrTestKAT(testval_t *)
tests using KAT for: fr_cpy, fr_reduce4, fr_eq, fr_neq, fr_neg, fr_x2, fr_x3, fr_add,...
Definition: frtest_kat.cu:15
__global__ void FrTestAssociativeMul(testval_t *testval)
Test of the associative property of multiplication (x*y)*z == x*(y*z)
Definition: frtest_mul.cu:56
__global__ void FrTestCommutativeMul(testval_t *testval)
Test of the commutative property of multiplication x*y == y*x.
Definition: frtest_mul.cu:15
__global__ void FrTestMulConst(testval_t *testval)
Test multiply by constant on Fr:
__global__ void FrTestSub(testval_t *testval)
Test of subtraction x == y-(y-x)
Definition: frtest_sub.cu:15
void testinit()
Sets a global variable to true if the STDOUT is a terminal. Needs to be done like so because while a ...
Definition: test.cu:18