hf mf fchk - output style
[RRG-proxmark3.git] / tools / hitag2crack / crack5opencl / opencl.h
blob78cd3d34792e6ebe05f0db028c1feb617a58a702
1 /****************************************************************************
3 Author : Gabriele 'matrix' Gristina <gabriele.gristina@gmail.com>
4 Date : Sun Jan 10 13:59:37 CET 2021
5 Version: 0.1beta
6 License: GNU General Public License v3 or any later version (see LICENSE.txt)
8 *****************************************************************************
9 Copyright (C) 2020-2021 <Gabriele Gristina>
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ****************************************************************************/
25 #ifndef OPENCL_H
26 #define OPENCL_H
28 #ifdef __APPLE__
29 #include <OpenCL/opencl.h>
30 #else
31 #define CL_TARGET_OPENCL_VERSION 220
32 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
33 #include <CL/cl.h>
34 #endif
36 #include "ht2crack5opencl.h"
37 #include "queue.h"
38 #include <stdbool.h>
40 #include <stdio.h>
41 #include <errno.h>
43 // max number of concurrent devices (tested up to 4x RTX 3090)
44 #define MAX_OPENCL_DEVICES 16
46 // defines structures
47 typedef struct compute_device_ctx {
48 char name[0xff];
49 char vendor[0x40];
50 char version[0x40];
51 char driver_version[0x40];
53 bool is_gpu, is_apple_gpu, is_nv;
54 bool have_lop3, have_local_memory;
55 bool warning, unsupported;
57 bool selected;
59 unsigned char pad1[1];
60 unsigned int profile;
62 unsigned int sm_maj;
63 unsigned int sm_min;
64 unsigned int compute_units;
66 cl_device_id device_id;
67 cl_platform_id platform_id;
69 } compute_device_ctx_t;
71 typedef struct compute_platform_ctx {
72 unsigned int device_cnt;
73 unsigned int compute_units_max;
75 bool is_nv, is_apple, is_intel, is_pocl;
76 bool warning;
77 bool selected;
79 unsigned char pad1[2];
80 compute_device_ctx_t device[0x10];
82 char name[0xff];
83 char vendor[0x40];
84 char version[0x40];
86 unsigned char pad2[1];
87 cl_platform_id platform_id;
88 cl_context context;
89 cl_program program;
91 } compute_platform_ctx_t;
93 typedef struct opencl_ctx {
94 char *kernelSource[1];
95 size_t kernelSource_len;
97 size_t *global_ws;
98 size_t *local_ws;
99 unsigned int *profiles;
101 cl_device_id *device_ids; // compute device id's array
102 cl_context *contexts; // compute contexts
103 cl_command_queue *commands; // compute command queue (for each device)
104 cl_program *programs; // compute program's
105 cl_kernel *kernels; // compute kernel's
107 // cl_mem cand_base; // device memory used for the candidate base
108 cl_mem *keystreams; // device memory used for the keystream array
109 cl_mem *candidates; // device memory used for the candidates array
110 cl_mem *matches; // device memory used for the matches array
111 cl_mem *matches_found; // device memory used for the matches_found array
112 cl_mem *checks; // device memory used for uid, aR2, nR1, nR2
114 wu_queue_ctx_t queue_ctx;
115 bool profiling;
116 unsigned char pad2[1];
117 short thread_sched_type;
118 bool force_hitag2_opencl;
120 unsigned char pad3[3];
122 } opencl_ctx_t;
124 bool plat_dev_enabled(unsigned int id, unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type);
125 unsigned int get_smallest_profile(compute_platform_ctx_t *cd_ctx, size_t ocl_platform_cnt);
126 int discoverDevices(unsigned int profile_selected, uint32_t device_types_selected, cl_uint *platform_detected_cnt, size_t *selected_platforms_cnt, size_t *selected_devices_cnt, compute_platform_ctx_t **cd_ctx, unsigned int *plat_sel, unsigned int plat_cnt, unsigned int *dev_sel, unsigned int dev_cnt, bool verbose, bool show);
127 int runKernel(opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t *matches_found, size_t id);
129 #endif // OPENCL_H