Fabcoin Core  0.16.2
P2P Digital Currency
libgpusolver.h
Go to the documentation of this file.
1 /* MIT License
2  *
3  * Copyright (c) 2016 Omar Alvarez <omar.alvarez@udc.es>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef __GPU_SOLVER_H
25 #define __GPU_SOLVER_H
26 
27 #include <cstdio>
28 #include <csignal>
29 #include <iostream>
30 
31 #include "crypto/equihash.h"
32 #include "libclwrapper.h"
33 #include "uint256.h"
34 
35 
36 #include "param.h"
37 #include <cassert>
38 
39 #ifdef __APPLE__
40 #include <OpenCL/opencl.h>
41 #else
42 #include <CL/cl.h>
43 #endif
44 
45 // The maximum size of the .cl file we read in and compile
46 #define MAX_SOURCE_SIZE (0x200000)
47 
48 #define DIGITBITS_S PREFIX
49 
50 class GPUSolverCancelledException : public std::exception
51 {
52  virtual const char* what() const throw() {
53  return "GPU Equihash solver was cancelled";
54  }
55 };
56 
58 {
61 };
62 
63 class GPUSolver {
64 
65 public:
66  GPUSolver();
67  GPUSolver(unsigned platform, unsigned device);
68  ~GPUSolver();
69  bool run(unsigned int n, unsigned int k, uint8_t *header, size_t header_len, uint256 nonce,
70  const std::function<bool(std::vector<unsigned char>)> validBlock,
71  const std::function<bool(GPUSolverCancelCheck)> cancelled,
72  crypto_generichash_blake2b_state base_state);
73 
74 private:
76  bool GPU;
77  bool initOK;
78  static const uint32_t PROOFSIZE = 1 << PARAM_K;
79  //TODO 20?
81  uint32_t n_sol;
82  //Avg
83  uint32_t counter = 0;
84  float sum = 0.f;
85  float avg = 0.f;
86 
87  bool GPUSolve(unsigned int n, unsigned int k, uint8_t *header, size_t header_len, uint256 &nonce,
88  const std::function<bool(std::vector<unsigned char>)> validBlock,
89  const std::function<bool(GPUSolverCancelCheck)> cancelled,
90  crypto_generichash_blake2b_state base_state);
91 
92 };
93 
94 #endif // __GPU_SOLVER_H
#define function(a, b, c, d, k, s)
sols_t * indices
Definition: libgpusolver.h:80
uint32_t n_sol
Definition: libgpusolver.h:81
GPUSolverCancelCheck
Definition: libgpusolver.h:57
virtual const char * what() const
Definition: libgpusolver.h:52
volatile double sum
Definition: Examples.cpp:23
cl_gpuminer * miner
Definition: libgpusolver.h:75
256-bit opaque blob.
Definition: uint256.h:132
#define PARAM_K
Definition: param.h:4
bool initOK
Definition: libgpusolver.h:77