FK20 CUDA
g1test.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 <stdint.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 
11 #include "g1.cuh"
12 #include "g1test.cuh"
13 
14 __managed__ testval_t testval[TESTVALS];
15 
17 
22 void init() {
23 
24  printf("%s\n", __func__);
25 
26  testinit();
27 
28  /*
29  uint64_t t[2*TESTVALS];
30 
31  FILE *pf = fopen("/dev/urandom", "r");
32 
33  if (!pf)
34  return;
35 
36  size_t result = fread(&testval[i], sizeof(testval_t), TESTVALS-i, pf);
37  */
38 }
39 
41 //Shorthand for testing a function, with an error check and timer
42 #define TEST(X) \
43  start = clock(); \
44  X <<<grid,block>>> (&testval[0]); \
45  err = cudaDeviceSynchronize(); \
46  end = clock(); \
47  if (err != cudaSuccess) printf("Error %d (%s)\n", err, cudaGetErrorName(err)); \
48  printf(" (%.2f s)\n", (end - start) * (1.0 / CLOCKS_PER_SEC));
49 
51 
59 int main(int argc, char **argv) {
60  clock_t start, end;
61  cudaError_t err;
62 #if 1
63  dim3 block(1,1,1);
64  dim3 grid(1,1,1);
65 #else
66  dim3 block(32,8,1);
67  dim3 grid(82,1,1);
68 #endif
69 
70  unsigned rows = 2;
71 
72  if (argc > 1)
73  rows = atoi(argv[1]);
74 
75  if (rows < 1)
76  rows = 1;
77 
78  if (rows > 512)
79  rows = 512;
80 
81  init();
82 
83  TEST(G1TestKAT);
85  TEST(G1TestDbl);
86 
87  G1TestFFT(rows);
88 
89  return err;
90 }
91 
92 // vim: ts=4 et sw=4 si
#define TESTVALS
Definition: fptest.cuh:13
void init()
initialization
Definition: g1test.cu:22
int main(int argc, char **argv)
Test for points in G1.
Definition: g1test.cu:59
#define TEST(X)
Definition: g1test.cu:42
__managed__ testval_t testval[TESTVALS]
Definition: g1test.cu:14
void G1TestFFT(unsigned rows)
Test for FFT and IFFT of points on the G1 curve. Checks self consistency with the following propertie...
Definition: g1test_fft.cu:136
__global__ void G1TestDbl(testval_t *)
Test for point doubling in G1:
Definition: g1test_dbl.cu:18
__global__ void G1TestFibonacci(testval_t *)
Test addition and multiplication using a fibonacci sequence (cascading data dependency)
__global__ void G1TestKAT(testval_t *)
Test operation over G1 using KAT and self consistency:
Definition: g1test_kat.cu:58
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