FK20 CUDA
fk20test_poly2toeplitz_coefficients_fft.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 "fk20.cuh"
7 #include "fk20test.cuh"
8 
9 // Testvector inputs
10 
11 extern __managed__ fr_t polynomial[512*4096];
12 
13 // Testvector output
14 
15 extern __managed__ fr_t toeplitz_coefficients_fft[512*16][512];
16 
17 // Workspace
18 
19 static __managed__ uint8_t cmp[512*16*512];
20 static __managed__ fr_t fr_tmp[512*16*512];
21 
35 int main(int argc, char **argv) {
36 
37  testinit();
38 
39  int rows = 2;
40 
41  if (argc > 1)
42  rows = atoi(argv[1]);
43 
44  if (rows < 1)
45  rows = 1;
46 
47  if (rows > 512)
48  rows = 512;
49 
50  cudaError_t err;
51  bool pass = true;
52  clock_t start, end;
53 
55 
56  for (int i=0; i<5; i++) {
57 
59 
60  pass = true;
61 
62  printf("=== RUN %s\n", "fk20_poly2toeplitz_coefficients_fft: polynomial -> toeplitz_coefficients_fft");
63 
64  start = clock();
65  fk20_poly2toeplitz_coefficients_fft<<<512, 256>>>(fr_tmp, polynomial);
66  err = cudaDeviceSynchronize();
67  end = clock();
68 
69  if (err != cudaSuccess)
70  printf("Error fk20_poly2toeplitz_coefficients_fft: %d (%s)\n", err, cudaGetErrorName(err));
71  else
72  printf(" (%.3f s)\n", (end - start) * (1.0 / CLOCKS_PER_SEC));
73 
74  // Clear comparison results
75 
76  for (int i=0; i<512*16*512; i++)
77  cmp[i] = 0;
78 
79  fr_eq_wrapper<<<16, 256>>>(cmp, 512*16*512, fr_tmp, (fr_t *)toeplitz_coefficients_fft);
80 
81  err = cudaDeviceSynchronize();
82  if (err != cudaSuccess) printf("Error fr_eq_wrapper: %d (%s)\n", err, cudaGetErrorName(err));
83 
84  // Check result
85 
86  for (int i=0; pass && i<512*16*512; i++)
87  if (cmp[i] != 1) {
88  printf("poly2tc error %04x\n", i);
89  pass = false;
90  }
91 
92  PRINTPASS(pass);
93 
95  }
96  return 0;
97 }
98 
99 // vim: ts=4 et sw=4 si
__managed__ uint8_t cmp[16 *512]
int main(int argc, char **argv)
Tests only fk20_poly2toeplitz_coefficients_fft, five successive times. This testing is to catch a con...
__managed__ fr_t polynomial[512 *4096]
__managed__ fr_t toeplitz_coefficients_fft[512 *16][512]
uint64_t fr_t[4]
Subgroup element stored as a 256-bit array (a 4-element little-endian array of uint64_t)....
Definition: fr.cuh:24
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
#define PRINTPASS(pass)
Definition: test.h:25