1 /****************************************************************************
3 Author : Gabriele 'matrix' Gristina <gabriele.gristina@gmail.com>
4 Date : Sun Jan 10 13:59:37 CET 2021
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 ****************************************************************************/
29 #include <OpenCL/opencl.h>
31 #define CL_TARGET_OPENCL_VERSION 220
32 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
36 #include "ht2crack5opencl.h"
43 // max number of concurrent devices (tested up to 4x RTX 3090)
44 #define MAX_OPENCL_DEVICES 16
47 typedef struct compute_device_ctx
{
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
;
59 unsigned char pad1
[1];
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
;
79 unsigned char pad1
[2];
80 compute_device_ctx_t device
[0x10];
86 unsigned char pad2
[1];
87 cl_platform_id platform_id
;
91 } compute_platform_ctx_t
;
93 typedef struct opencl_ctx
{
94 char *kernelSource
[1];
95 size_t kernelSource_len
;
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
;
116 unsigned char pad2
[1];
117 short thread_sched_type
;
118 bool force_hitag2_opencl
;
120 unsigned char pad3
[3];
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
);