1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 22:58:30 +00:00

Move tuningdb specific functions into their own source file

This commit is contained in:
jsteube 2016-09-06 19:44:27 +02:00
parent b8e47c2ba2
commit 3ed4bfd237
18 changed files with 747 additions and 685 deletions

View File

@ -29,6 +29,9 @@
#define DEVICES_MAX 128
#define PARAMCNT 64
#define CEIL(a) ((a - (int) (a)) > 0 ? a + 1 : a)
#ifdef __APPLE__

View File

@ -8,6 +8,27 @@
#ifndef _EXT_OPENCL_H
#define _EXT_OPENCL_H
#include <stdio.h>
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
#ifdef __APPLE__
#include <OpenCL/cl.h>
#endif
#ifdef WIN
#include <CL/cl.h>
#endif
#ifdef __linux__
#include <CL/cl.h>
#endif
#ifdef __FreeBSD__
#include <CL/cl.h>
#endif
#define CL_PLATFORMS_MAX 16
static const char CL_VENDOR_AMD[] = "Advanced Micro Devices, Inc.";
@ -33,24 +54,184 @@ typedef enum vendor_id
} vendor_id_t;
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
typedef struct __hc_device_param hc_device_param_t;
#ifdef __APPLE__
#include <OpenCL/cl.h>
#endif
struct __hc_device_param
{
cl_device_id device;
cl_device_type device_type;
#ifdef WIN
#include <CL/cl.h>
#endif
uint device_id;
uint platform_devices_id; // for mapping with hms devices
#ifdef __linux__
#include <CL/cl.h>
#endif
bool skipped;
#ifdef __FreeBSD__
#include <CL/cl.h>
#endif
uint sm_major;
uint sm_minor;
uint kernel_exec_timeout;
uint device_processors;
u64 device_maxmem_alloc;
u64 device_global_mem;
u32 device_maxclock_frequency;
size_t device_maxworkgroup_size;
uint vector_width;
uint kernel_threads;
uint kernel_loops;
uint kernel_accel;
uint kernel_loops_min;
uint kernel_loops_max;
uint kernel_accel_min;
uint kernel_accel_max;
uint kernel_power;
uint hardware_power;
size_t size_pws;
size_t size_tmps;
size_t size_hooks;
size_t size_bfs;
size_t size_combs;
size_t size_rules;
size_t size_rules_c;
size_t size_root_css;
size_t size_markov_css;
size_t size_digests;
size_t size_salts;
size_t size_shown;
size_t size_results;
size_t size_plains;
FILE *combs_fp;
comb_t *combs_buf;
void *hooks_buf;
pw_t *pws_buf;
uint pws_cnt;
u64 words_off;
u64 words_done;
uint outerloop_pos;
uint outerloop_left;
uint innerloop_pos;
uint innerloop_left;
uint exec_pos;
double exec_ms[EXEC_CACHE];
// workaround cpu spinning
double exec_us_prev1[EXPECTED_ITERATIONS];
double exec_us_prev2[EXPECTED_ITERATIONS];
double exec_us_prev3[EXPECTED_ITERATIONS];
// this is "current" speed
uint speed_pos;
u64 speed_cnt[SPEED_CACHE];
double speed_ms[SPEED_CACHE];
hc_timer_t timer_speed;
// device specific attributes starting
char *device_name;
char *device_vendor;
char *device_name_chksum;
char *device_version;
char *driver_version;
bool opencl_v12;
double nvidia_spin_damp;
cl_platform_id platform;
cl_uint device_vendor_id;
cl_uint platform_vendor_id;
cl_kernel kernel1;
cl_kernel kernel12;
cl_kernel kernel2;
cl_kernel kernel23;
cl_kernel kernel3;
cl_kernel kernel_mp;
cl_kernel kernel_mp_l;
cl_kernel kernel_mp_r;
cl_kernel kernel_amp;
cl_kernel kernel_tm;
cl_kernel kernel_weak;
cl_kernel kernel_memset;
cl_context context;
cl_program program;
cl_program program_mp;
cl_program program_amp;
cl_command_queue command_queue;
cl_mem d_pws_buf;
cl_mem d_pws_amp_buf;
cl_mem d_words_buf_l;
cl_mem d_words_buf_r;
cl_mem d_rules;
cl_mem d_rules_c;
cl_mem d_combs;
cl_mem d_combs_c;
cl_mem d_bfs;
cl_mem d_bfs_c;
cl_mem d_tm_c;
cl_mem d_bitmap_s1_a;
cl_mem d_bitmap_s1_b;
cl_mem d_bitmap_s1_c;
cl_mem d_bitmap_s1_d;
cl_mem d_bitmap_s2_a;
cl_mem d_bitmap_s2_b;
cl_mem d_bitmap_s2_c;
cl_mem d_bitmap_s2_d;
cl_mem d_plain_bufs;
cl_mem d_digests_buf;
cl_mem d_digests_shown;
cl_mem d_salt_bufs;
cl_mem d_esalt_bufs;
cl_mem d_bcrypt_bufs;
cl_mem d_tmps;
cl_mem d_hooks;
cl_mem d_result;
cl_mem d_scryptV0_buf;
cl_mem d_scryptV1_buf;
cl_mem d_scryptV2_buf;
cl_mem d_scryptV3_buf;
cl_mem d_root_css_buf;
cl_mem d_markov_css_buf;
void *kernel_params[PARAMCNT];
void *kernel_params_mp[PARAMCNT];
void *kernel_params_mp_r[PARAMCNT];
void *kernel_params_mp_l[PARAMCNT];
void *kernel_params_amp[PARAMCNT];
void *kernel_params_tm[PARAMCNT];
void *kernel_params_memset[PARAMCNT];
u32 kernel_params_buf32[PARAMCNT];
u32 kernel_params_mp_buf32[PARAMCNT];
u64 kernel_params_mp_buf64[PARAMCNT];
u32 kernel_params_mp_r_buf32[PARAMCNT];
u64 kernel_params_mp_r_buf64[PARAMCNT];
u32 kernel_params_mp_l_buf32[PARAMCNT];
u64 kernel_params_mp_l_buf64[PARAMCNT];
u32 kernel_params_amp_buf32[PARAMCNT];
u32 kernel_params_memset_buf32[PARAMCNT];
};
typedef cl_int (CL_API_CALL *OCL_CLBUILDPROGRAM) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *);
typedef cl_mem (CL_API_CALL *OCL_CLCREATEBUFFER) (cl_context, cl_mem_flags, size_t, void *, cl_int *);

19
include/filehandling.h Normal file
View File

@ -0,0 +1,19 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#ifndef _FILEHANDLING_H
#define _FILEHANDLING_H
#include <stdio.h>
#include <string.h>
#include <errno.h>
uint count_lines (FILE *fd);
int fgetl (FILE *fp, char *line_buf);
int in_superchop (char *buf);
#endif // _FILEHANDLING_H

View File

@ -126,8 +126,6 @@ static const char ST_0010[] = "Autotuning";
* functions
*/
uint count_lines (FILE *fd);
void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *));
int sort_by_u32 (const void *p1, const void *p2);
@ -179,8 +177,7 @@ u64 mydivc64 (const u64 dividend, const u64 divisor);
void format_speed_display (double val, char *buf, size_t len);
void format_timer_display (struct tm *tm, char *buf, size_t len);
int fgetl (FILE *fp, char *line_buf);
int in_superchop (char *buf);
char **scan_directory (const char *path);
int count_dictionaries (char **dictionary_files);
@ -198,10 +195,6 @@ void myquit (void);
void set_cpu_affinity (char *cpu_affinity);
void tuning_db_destroy (tuning_db_t *tuning_db);
tuning_db_t *tuning_db_alloc (FILE *fp);
tuning_db_t *tuning_db_init (const char *tuning_db_file);
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type);
void naive_replace (char *s, const u8 key_char, const u8 replace_char);
void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char);

46
include/tuningdb.h Normal file
View File

@ -0,0 +1,46 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#ifndef _TUNINGDB_H
#define _TUNINGDB_H
#include <stdio.h>
#include <errno.h>
typedef struct
{
char *device_name;
char *alias_name;
} tuning_db_alias_t;
typedef struct
{
char *device_name;
int attack_mode;
int hash_type;
int workload_profile;
int vector_width;
int kernel_accel;
int kernel_loops;
} tuning_db_entry_t;
typedef struct
{
tuning_db_alias_t *alias_buf;
int alias_cnt;
tuning_db_entry_t *entry_buf;
int entry_cnt;
} tuning_db_t;
void tuning_db_destroy (tuning_db_t *tuning_db);
tuning_db_t *tuning_db_alloc (FILE *fp);
tuning_db_t *tuning_db_init (const char *tuning_db_file);
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type);
#endif // _TUNINGDB_H

View File

@ -330,220 +330,11 @@ typedef struct
} wordr_t;
typedef struct
{
char *device_name;
char *alias_name;
} tuning_db_alias_t;
typedef struct
{
char *device_name;
int attack_mode;
int hash_type;
int workload_profile;
int vector_width;
int kernel_accel;
int kernel_loops;
} tuning_db_entry_t;
typedef struct
{
tuning_db_alias_t *alias_buf;
int alias_cnt;
tuning_db_entry_t *entry_buf;
int entry_cnt;
} tuning_db_t;
#define RULES_MAX 256
#define PW_MIN 0
#define PW_MAX 54
#define PW_MAX1 (PW_MAX + 1)
#define PW_DICTMAX 31
#define PW_DICTMAX1 (PW_DICTMAX + 1)
#define PARAMCNT 64
struct __hc_device_param
{
cl_device_id device;
cl_device_type device_type;
uint device_id;
uint platform_devices_id; // for mapping with hms devices
bool skipped;
uint sm_major;
uint sm_minor;
uint kernel_exec_timeout;
uint device_processors;
u64 device_maxmem_alloc;
u64 device_global_mem;
u32 device_maxclock_frequency;
size_t device_maxworkgroup_size;
uint vector_width;
uint kernel_threads;
uint kernel_loops;
uint kernel_accel;
uint kernel_loops_min;
uint kernel_loops_max;
uint kernel_accel_min;
uint kernel_accel_max;
uint kernel_power;
uint hardware_power;
size_t size_pws;
size_t size_tmps;
size_t size_hooks;
size_t size_bfs;
size_t size_combs;
size_t size_rules;
size_t size_rules_c;
size_t size_root_css;
size_t size_markov_css;
size_t size_digests;
size_t size_salts;
size_t size_shown;
size_t size_results;
size_t size_plains;
FILE *combs_fp;
comb_t *combs_buf;
void *hooks_buf;
pw_t *pws_buf;
uint pws_cnt;
u64 words_off;
u64 words_done;
uint outerloop_pos;
uint outerloop_left;
uint innerloop_pos;
uint innerloop_left;
uint exec_pos;
double exec_ms[EXEC_CACHE];
// workaround cpu spinning
double exec_us_prev1[EXPECTED_ITERATIONS];
double exec_us_prev2[EXPECTED_ITERATIONS];
double exec_us_prev3[EXPECTED_ITERATIONS];
// this is "current" speed
uint speed_pos;
u64 speed_cnt[SPEED_CACHE];
double speed_ms[SPEED_CACHE];
hc_timer_t timer_speed;
// device specific attributes starting
char *device_name;
char *device_vendor;
char *device_name_chksum;
char *device_version;
char *driver_version;
bool opencl_v12;
double nvidia_spin_damp;
cl_platform_id platform;
cl_uint device_vendor_id;
cl_uint platform_vendor_id;
cl_kernel kernel1;
cl_kernel kernel12;
cl_kernel kernel2;
cl_kernel kernel23;
cl_kernel kernel3;
cl_kernel kernel_mp;
cl_kernel kernel_mp_l;
cl_kernel kernel_mp_r;
cl_kernel kernel_amp;
cl_kernel kernel_tm;
cl_kernel kernel_weak;
cl_kernel kernel_memset;
cl_context context;
cl_program program;
cl_program program_mp;
cl_program program_amp;
cl_command_queue command_queue;
cl_mem d_pws_buf;
cl_mem d_pws_amp_buf;
cl_mem d_words_buf_l;
cl_mem d_words_buf_r;
cl_mem d_rules;
cl_mem d_rules_c;
cl_mem d_combs;
cl_mem d_combs_c;
cl_mem d_bfs;
cl_mem d_bfs_c;
cl_mem d_tm_c;
cl_mem d_bitmap_s1_a;
cl_mem d_bitmap_s1_b;
cl_mem d_bitmap_s1_c;
cl_mem d_bitmap_s1_d;
cl_mem d_bitmap_s2_a;
cl_mem d_bitmap_s2_b;
cl_mem d_bitmap_s2_c;
cl_mem d_bitmap_s2_d;
cl_mem d_plain_bufs;
cl_mem d_digests_buf;
cl_mem d_digests_shown;
cl_mem d_salt_bufs;
cl_mem d_esalt_bufs;
cl_mem d_bcrypt_bufs;
cl_mem d_tmps;
cl_mem d_hooks;
cl_mem d_result;
cl_mem d_scryptV0_buf;
cl_mem d_scryptV1_buf;
cl_mem d_scryptV2_buf;
cl_mem d_scryptV3_buf;
cl_mem d_root_css_buf;
cl_mem d_markov_css_buf;
void *kernel_params[PARAMCNT];
void *kernel_params_mp[PARAMCNT];
void *kernel_params_mp_r[PARAMCNT];
void *kernel_params_mp_l[PARAMCNT];
void *kernel_params_amp[PARAMCNT];
void *kernel_params_tm[PARAMCNT];
void *kernel_params_memset[PARAMCNT];
u32 kernel_params_buf32[PARAMCNT];
u32 kernel_params_mp_buf32[PARAMCNT];
u64 kernel_params_mp_buf64[PARAMCNT];
u32 kernel_params_mp_r_buf32[PARAMCNT];
u64 kernel_params_mp_r_buf64[PARAMCNT];
u32 kernel_params_mp_l_buf32[PARAMCNT];
u64 kernel_params_mp_l_buf64[PARAMCNT];
u32 kernel_params_amp_buf32[PARAMCNT];
u32 kernel_params_memset_buf32[PARAMCNT];
};
typedef struct __hc_device_param hc_device_param_t;
#endif // _TYPES_H

View File

@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi
## Objects
##
NATIVE_OBJS := obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
NATIVE_OBJS := obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
ifeq ($(UNAME),Linux)
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
endif
LINUX_32_OBJS := obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
LINUX_32_OBJS := obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
# Windows CRT file globbing:
@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
WIN_32_OBJS := obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
WIN_32_OBJS := obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
##
## Targets: Global

View File

@ -5,13 +5,13 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "mpsp.h"
#include "rp_cpu.h"

View File

@ -6,8 +6,11 @@
*/
#include "common.h"
#include "logging.h"
#include "types_int.h"
#include "types.h"
#include "memory.h"
#include "logging.h"
#include "timer.h"
#include "dynloader.h"
#include "ext_OpenCL.h"

106
src/filehandling.c Normal file
View File

@ -0,0 +1,106 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#include "common.h"
#include "types_int.h"
#include "memory.h"
#include "filehandling.h"
uint count_lines (FILE *fd)
{
uint cnt = 0;
char *buf = (char *) mymalloc (HCBUFSIZ + 1);
char prev = '\n';
while (!feof (fd))
{
size_t nread = fread (buf, sizeof (char), HCBUFSIZ, fd);
if (nread < 1) continue;
size_t i;
for (i = 0; i < nread; i++)
{
if (prev == '\n') cnt++;
prev = buf[i];
}
}
myfree (buf);
return cnt;
}
int fgetl (FILE *fp, char *line_buf)
{
int line_len = 0;
while (!feof (fp))
{
const int c = fgetc (fp);
if (c == EOF) break;
line_buf[line_len] = (char) c;
line_len++;
if (line_len == HCBUFSIZ) line_len--;
if (c == '\n') break;
}
if (line_len == 0) return 0;
if (line_buf[line_len - 1] == '\n')
{
line_len--;
line_buf[line_len] = 0;
}
if (line_len == 0) return 0;
if (line_buf[line_len - 1] == '\r')
{
line_len--;
line_buf[line_len] = 0;
}
return (line_len);
}
int in_superchop (char *buf)
{
int len = strlen (buf);
while (len)
{
if (buf[len - 1] == '\n')
{
len--;
continue;
}
if (buf[len - 1] == '\r')
{
len--;
continue;
}
break;
}
buf[len] = 0;
return len;
}

View File

@ -8,6 +8,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "bitops.h"
#include "memory.h"
#include "folder.h"
@ -25,10 +27,10 @@
#include "cpu_md5.h"
#include "cpu_sha1.h"
#include "cpu_sha256.h"
#include "filehandling.h"
#include "tuningdb.h"
#include "thread.h"
#include "timer.h"
#include "locking.h"
#include "types.h"
#include "rp_cpu.h"
#include "rp_kernel_on_cpu.h"
#include "inc_hash_constants.h"

View File

@ -5,6 +5,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "memory.h"
#include "logging.h"
#include "ext_OpenCL.h"
@ -12,8 +14,6 @@
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "mpsp.h"
#include "rp_cpu.h"

View File

@ -5,6 +5,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "bitops.h"
#include "memory.h"
#include "convert.h"
@ -22,8 +24,6 @@
#include "cpu_sha256.h"
#include "rp_kernel_on_cpu.h"
#include "inc_hash_constants.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "mpsp.h"
#include "rp_cpu.h"

View File

@ -5,12 +5,13 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "timer.h"
#include "types.h"
#include "memory.h"
#include "hwmon.h"

View File

@ -5,6 +5,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "memory.h"
#include "logging.h"
#include "convert.h"
@ -13,9 +15,8 @@
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "timer.h"
#include "filehandling.h"
#include "thread.h"
#include "types.h"
#include "hwmon.h"
#include "mpsp.h"
#include "rp_cpu.h"

View File

@ -5,6 +5,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "memory.h"
#include "logging.h"
#include "ext_OpenCL.h"
@ -14,8 +16,6 @@
#include "ext_xnvctrl.h"
#include "convert.h"
#include "thread.h"
#include "timer.h"
#include "types.h"
#include "rp_cpu.h"
#include "terminal.h"
#include "hwmon.h"

View File

@ -8,6 +8,8 @@
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "memory.h"
#include "logging.h"
#include "ext_OpenCL.h"
@ -18,8 +20,6 @@
#include "convert.h"
#include "locking.h"
#include "thread.h"
#include "timer.h"
#include "types.h"
#include "rp_cpu.h"
#include "terminal.h"
#include "hwmon.h"
@ -50,34 +50,7 @@ void fsync (int fd)
* mixed shared functions
*/
uint count_lines (FILE *fd)
{
uint cnt = 0;
char *buf = (char *) mymalloc (HCBUFSIZ + 1);
char prev = '\n';
while (!feof (fd))
{
size_t nread = fread (buf, sizeof (char), HCBUFSIZ, fd);
if (nread < 1) continue;
size_t i;
for (i = 0; i < nread; i++)
{
if (prev == '\n') cnt++;
prev = buf[i];
}
}
myfree (buf);
return cnt;
}
#ifdef __APPLE__
int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set)
@ -596,40 +569,6 @@ int sort_by_digest_p0p1 (const void *v1, const void *v2)
return 0;
}
static int sort_by_tuning_db_alias (const void *v1, const void *v2)
{
const tuning_db_alias_t *t1 = (const tuning_db_alias_t *) v1;
const tuning_db_alias_t *t2 = (const tuning_db_alias_t *) v2;
const int res1 = strcmp (t1->device_name, t2->device_name);
if (res1 != 0) return (res1);
return 0;
}
static int sort_by_tuning_db_entry (const void *v1, const void *v2)
{
const tuning_db_entry_t *t1 = (const tuning_db_entry_t *) v1;
const tuning_db_entry_t *t2 = (const tuning_db_entry_t *) v2;
const int res1 = strcmp (t1->device_name, t2->device_name);
if (res1 != 0) return (res1);
const int res2 = t1->attack_mode
- t2->attack_mode;
if (res2 != 0) return (res2);
const int res3 = t1->hash_type
- t2->hash_type;
if (res3 != 0) return (res3);
return 0;
}
void format_debug (char *debug_file, uint debug_mode, unsigned char *orig_plain_ptr, uint orig_plain_len, unsigned char *mod_plain_ptr, uint mod_plain_len, char *rule_buf, int rule_len)
{
uint outfile_autohex = data.outfile_autohex;
@ -1255,74 +1194,6 @@ void format_speed_display (double val, char *buf, size_t len)
}
}
int fgetl (FILE *fp, char *line_buf)
{
int line_len = 0;
while (!feof (fp))
{
const int c = fgetc (fp);
if (c == EOF) break;
line_buf[line_len] = (char) c;
line_len++;
if (line_len == HCBUFSIZ) line_len--;
if (c == '\n') break;
}
if (line_len == 0) return 0;
if (line_buf[line_len - 1] == '\n')
{
line_len--;
line_buf[line_len] = 0;
}
if (line_len == 0) return 0;
if (line_buf[line_len - 1] == '\r')
{
line_len--;
line_buf[line_len] = 0;
}
return (line_len);
}
int in_superchop (char *buf)
{
int len = strlen (buf);
while (len)
{
if (buf[len - 1] == '\n')
{
len--;
continue;
}
if (buf[len - 1] == '\r')
{
len--;
continue;
}
break;
}
buf[len] = 0;
return len;
}
char **scan_directory (const char *path)
{
char *tmp_path = mystrdup (path);
@ -1946,310 +1817,6 @@ void check_checkpoint ()
}
}
/**
* tuning db
*/
void tuning_db_destroy (tuning_db_t *tuning_db)
{
int i;
for (i = 0; i < tuning_db->alias_cnt; i++)
{
tuning_db_alias_t *alias = &tuning_db->alias_buf[i];
myfree (alias->device_name);
myfree (alias->alias_name);
}
for (i = 0; i < tuning_db->entry_cnt; i++)
{
tuning_db_entry_t *entry = &tuning_db->entry_buf[i];
myfree (entry->device_name);
}
myfree (tuning_db->alias_buf);
myfree (tuning_db->entry_buf);
myfree (tuning_db);
}
tuning_db_t *tuning_db_alloc (FILE *fp)
{
tuning_db_t *tuning_db = (tuning_db_t *) mymalloc (sizeof (tuning_db_t));
int num_lines = count_lines (fp);
// a bit over-allocated
tuning_db->alias_buf = (tuning_db_alias_t *) mycalloc (num_lines + 1, sizeof (tuning_db_alias_t));
tuning_db->alias_cnt = 0;
tuning_db->entry_buf = (tuning_db_entry_t *) mycalloc (num_lines + 1, sizeof (tuning_db_entry_t));
tuning_db->entry_cnt = 0;
return tuning_db;
}
tuning_db_t *tuning_db_init (const char *tuning_db_file)
{
FILE *fp = fopen (tuning_db_file, "rb");
if (fp == NULL)
{
log_error ("%s: %s", tuning_db_file, strerror (errno));
exit (-1);
}
tuning_db_t *tuning_db = tuning_db_alloc (fp);
rewind (fp);
int line_num = 0;
char *buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp))
{
char *line_buf = fgets (buf, HCBUFSIZ - 1, fp);
if (line_buf == NULL) break;
line_num++;
const int line_len = in_superchop (line_buf);
if (line_len == 0) continue;
if (line_buf[0] == '#') continue;
// start processing
char *token_ptr[7] = { NULL };
int token_cnt = 0;
char *next = strtok (line_buf, "\t ");
token_ptr[token_cnt] = next;
token_cnt++;
while ((next = strtok (NULL, "\t ")) != NULL)
{
token_ptr[token_cnt] = next;
token_cnt++;
}
if (token_cnt == 2)
{
char *device_name = token_ptr[0];
char *alias_name = token_ptr[1];
tuning_db_alias_t *alias = &tuning_db->alias_buf[tuning_db->alias_cnt];
alias->device_name = mystrdup (device_name);
alias->alias_name = mystrdup (alias_name);
tuning_db->alias_cnt++;
}
else if (token_cnt == 6)
{
if ((token_ptr[1][0] != '0') &&
(token_ptr[1][0] != '1') &&
(token_ptr[1][0] != '3') &&
(token_ptr[1][0] != '*'))
{
log_info ("WARNING: Tuning-db: Invalid attack_mode '%c' in Line '%u'", token_ptr[1][0], line_num);
continue;
}
if ((token_ptr[3][0] != '1') &&
(token_ptr[3][0] != '2') &&
(token_ptr[3][0] != '4') &&
(token_ptr[3][0] != '8') &&
(token_ptr[3][0] != 'N'))
{
log_info ("WARNING: Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num);
continue;
}
char *device_name = token_ptr[0];
int attack_mode = -1;
int hash_type = -1;
int vector_width = -1;
int kernel_accel = -1;
int kernel_loops = -1;
if (token_ptr[1][0] != '*') attack_mode = atoi (token_ptr[1]);
if (token_ptr[2][0] != '*') hash_type = atoi (token_ptr[2]);
if (token_ptr[3][0] != 'N') vector_width = atoi (token_ptr[3]);
if (token_ptr[4][0] != 'A')
{
kernel_accel = atoi (token_ptr[4]);
if ((kernel_accel < 1) || (kernel_accel > 1024))
{
log_info ("WARNING: Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num);
continue;
}
}
else
{
kernel_accel = 0;
}
if (token_ptr[5][0] != 'A')
{
kernel_loops = atoi (token_ptr[5]);
if ((kernel_loops < 1) || (kernel_loops > 1024))
{
log_info ("WARNING: Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num);
continue;
}
}
else
{
kernel_loops = 0;
}
tuning_db_entry_t *entry = &tuning_db->entry_buf[tuning_db->entry_cnt];
entry->device_name = mystrdup (device_name);
entry->attack_mode = attack_mode;
entry->hash_type = hash_type;
entry->vector_width = vector_width;
entry->kernel_accel = kernel_accel;
entry->kernel_loops = kernel_loops;
tuning_db->entry_cnt++;
}
else
{
log_info ("WARNING: Tuning-db: Invalid number of token in Line '%u'", line_num);
continue;
}
}
myfree (buf);
fclose (fp);
// todo: print loaded 'cnt' message
// sort the database
qsort (tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
qsort (tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
return tuning_db;
}
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type)
{
static tuning_db_entry_t s;
// first we need to convert all spaces in the device_name to underscore
char *device_name_nospace = mystrdup (device_param->device_name);
int device_name_length = strlen (device_name_nospace);
int i;
for (i = 0; i < device_name_length; i++)
{
if (device_name_nospace[i] == ' ') device_name_nospace[i] = '_';
}
// find out if there's an alias configured
tuning_db_alias_t a;
a.device_name = device_name_nospace;
tuning_db_alias_t *alias = bsearch (&a, tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
char *alias_name = (alias == NULL) ? NULL : alias->alias_name;
// attack-mode 6 and 7 are attack-mode 1 basically
if (attack_mode == 6) attack_mode = 1;
if (attack_mode == 7) attack_mode = 1;
// bsearch is not ideal but fast enough
s.device_name = device_name_nospace;
s.attack_mode = attack_mode;
s.hash_type = hash_type;
tuning_db_entry_t *entry = NULL;
// this will produce all 2^3 combinations required
for (i = 0; i < 8; i++)
{
s.device_name = (i & 1) ? "*" : device_name_nospace;
s.attack_mode = (i & 2) ? -1 : attack_mode;
s.hash_type = (i & 4) ? -1 : hash_type;
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
// in non-wildcard mode do some additional checks:
if ((i & 1) == 0)
{
// in case we have an alias-name
if (alias_name != NULL)
{
s.device_name = alias_name;
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
}
// or by device type
if (device_param->device_type & CL_DEVICE_TYPE_CPU)
{
s.device_name = "DEVICE_TYPE_CPU";
}
else if (device_param->device_type & CL_DEVICE_TYPE_GPU)
{
s.device_name = "DEVICE_TYPE_GPU";
}
else if (device_param->device_type & CL_DEVICE_TYPE_ACCELERATOR)
{
s.device_name = "DEVICE_TYPE_ACCELERATOR";
}
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
}
}
// free converted device_name
myfree (device_name_nospace);
return entry;
}
/**
* parallel running threads

349
src/tuningdb.c Normal file
View File

@ -0,0 +1,349 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "logging.h"
#include "memory.h"
#include "filehandling.h"
#include "ext_OpenCL.h"
#include "tuningdb.h"
static int sort_by_tuning_db_alias (const void *v1, const void *v2)
{
const tuning_db_alias_t *t1 = (const tuning_db_alias_t *) v1;
const tuning_db_alias_t *t2 = (const tuning_db_alias_t *) v2;
const int res1 = strcmp (t1->device_name, t2->device_name);
if (res1 != 0) return (res1);
return 0;
}
static int sort_by_tuning_db_entry (const void *v1, const void *v2)
{
const tuning_db_entry_t *t1 = (const tuning_db_entry_t *) v1;
const tuning_db_entry_t *t2 = (const tuning_db_entry_t *) v2;
const int res1 = strcmp (t1->device_name, t2->device_name);
if (res1 != 0) return (res1);
const int res2 = t1->attack_mode
- t2->attack_mode;
if (res2 != 0) return (res2);
const int res3 = t1->hash_type
- t2->hash_type;
if (res3 != 0) return (res3);
return 0;
}
void tuning_db_destroy (tuning_db_t *tuning_db)
{
int i;
for (i = 0; i < tuning_db->alias_cnt; i++)
{
tuning_db_alias_t *alias = &tuning_db->alias_buf[i];
myfree (alias->device_name);
myfree (alias->alias_name);
}
for (i = 0; i < tuning_db->entry_cnt; i++)
{
tuning_db_entry_t *entry = &tuning_db->entry_buf[i];
myfree (entry->device_name);
}
myfree (tuning_db->alias_buf);
myfree (tuning_db->entry_buf);
myfree (tuning_db);
}
tuning_db_t *tuning_db_alloc (FILE *fp)
{
tuning_db_t *tuning_db = (tuning_db_t *) mymalloc (sizeof (tuning_db_t));
int num_lines = count_lines (fp);
// a bit over-allocated
tuning_db->alias_buf = (tuning_db_alias_t *) mycalloc (num_lines + 1, sizeof (tuning_db_alias_t));
tuning_db->alias_cnt = 0;
tuning_db->entry_buf = (tuning_db_entry_t *) mycalloc (num_lines + 1, sizeof (tuning_db_entry_t));
tuning_db->entry_cnt = 0;
return tuning_db;
}
tuning_db_t *tuning_db_init (const char *tuning_db_file)
{
FILE *fp = fopen (tuning_db_file, "rb");
if (fp == NULL)
{
log_error ("%s: %s", tuning_db_file, strerror (errno));
exit (-1);
}
tuning_db_t *tuning_db = tuning_db_alloc (fp);
rewind (fp);
int line_num = 0;
char *buf = (char *) mymalloc (HCBUFSIZ);
while (!feof (fp))
{
char *line_buf = fgets (buf, HCBUFSIZ - 1, fp);
if (line_buf == NULL) break;
line_num++;
const int line_len = in_superchop (line_buf);
if (line_len == 0) continue;
if (line_buf[0] == '#') continue;
// start processing
char *token_ptr[7] = { NULL };
int token_cnt = 0;
char *next = strtok (line_buf, "\t ");
token_ptr[token_cnt] = next;
token_cnt++;
while ((next = strtok (NULL, "\t ")) != NULL)
{
token_ptr[token_cnt] = next;
token_cnt++;
}
if (token_cnt == 2)
{
char *device_name = token_ptr[0];
char *alias_name = token_ptr[1];
tuning_db_alias_t *alias = &tuning_db->alias_buf[tuning_db->alias_cnt];
alias->device_name = mystrdup (device_name);
alias->alias_name = mystrdup (alias_name);
tuning_db->alias_cnt++;
}
else if (token_cnt == 6)
{
if ((token_ptr[1][0] != '0') &&
(token_ptr[1][0] != '1') &&
(token_ptr[1][0] != '3') &&
(token_ptr[1][0] != '*'))
{
log_info ("WARNING: Tuning-db: Invalid attack_mode '%c' in Line '%u'", token_ptr[1][0], line_num);
continue;
}
if ((token_ptr[3][0] != '1') &&
(token_ptr[3][0] != '2') &&
(token_ptr[3][0] != '4') &&
(token_ptr[3][0] != '8') &&
(token_ptr[3][0] != 'N'))
{
log_info ("WARNING: Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num);
continue;
}
char *device_name = token_ptr[0];
int attack_mode = -1;
int hash_type = -1;
int vector_width = -1;
int kernel_accel = -1;
int kernel_loops = -1;
if (token_ptr[1][0] != '*') attack_mode = atoi (token_ptr[1]);
if (token_ptr[2][0] != '*') hash_type = atoi (token_ptr[2]);
if (token_ptr[3][0] != 'N') vector_width = atoi (token_ptr[3]);
if (token_ptr[4][0] != 'A')
{
kernel_accel = atoi (token_ptr[4]);
if ((kernel_accel < 1) || (kernel_accel > 1024))
{
log_info ("WARNING: Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num);
continue;
}
}
else
{
kernel_accel = 0;
}
if (token_ptr[5][0] != 'A')
{
kernel_loops = atoi (token_ptr[5]);
if ((kernel_loops < 1) || (kernel_loops > 1024))
{
log_info ("WARNING: Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num);
continue;
}
}
else
{
kernel_loops = 0;
}
tuning_db_entry_t *entry = &tuning_db->entry_buf[tuning_db->entry_cnt];
entry->device_name = mystrdup (device_name);
entry->attack_mode = attack_mode;
entry->hash_type = hash_type;
entry->vector_width = vector_width;
entry->kernel_accel = kernel_accel;
entry->kernel_loops = kernel_loops;
tuning_db->entry_cnt++;
}
else
{
log_info ("WARNING: Tuning-db: Invalid number of token in Line '%u'", line_num);
continue;
}
}
myfree (buf);
fclose (fp);
// todo: print loaded 'cnt' message
// sort the database
qsort (tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
qsort (tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
return tuning_db;
}
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type)
{
static tuning_db_entry_t s;
// first we need to convert all spaces in the device_name to underscore
char *device_name_nospace = mystrdup (device_param->device_name);
int device_name_length = strlen (device_name_nospace);
int i;
for (i = 0; i < device_name_length; i++)
{
if (device_name_nospace[i] == ' ') device_name_nospace[i] = '_';
}
// find out if there's an alias configured
tuning_db_alias_t a;
a.device_name = device_name_nospace;
tuning_db_alias_t *alias = bsearch (&a, tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
char *alias_name = (alias == NULL) ? NULL : alias->alias_name;
// attack-mode 6 and 7 are attack-mode 1 basically
if (attack_mode == 6) attack_mode = 1;
if (attack_mode == 7) attack_mode = 1;
// bsearch is not ideal but fast enough
s.device_name = device_name_nospace;
s.attack_mode = attack_mode;
s.hash_type = hash_type;
tuning_db_entry_t *entry = NULL;
// this will produce all 2^3 combinations required
for (i = 0; i < 8; i++)
{
s.device_name = (i & 1) ? "*" : device_name_nospace;
s.attack_mode = (i & 2) ? -1 : attack_mode;
s.hash_type = (i & 4) ? -1 : hash_type;
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
// in non-wildcard mode do some additional checks:
if ((i & 1) == 0)
{
// in case we have an alias-name
if (alias_name != NULL)
{
s.device_name = alias_name;
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
}
// or by device type
if (device_param->device_type & CL_DEVICE_TYPE_CPU)
{
s.device_name = "DEVICE_TYPE_CPU";
}
else if (device_param->device_type & CL_DEVICE_TYPE_GPU)
{
s.device_name = "DEVICE_TYPE_GPU";
}
else if (device_param->device_type & CL_DEVICE_TYPE_ACCELERATOR)
{
s.device_name = "DEVICE_TYPE_ACCELERATOR";
}
entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
if (entry != NULL) break;
}
}
// free converted device_name
myfree (device_name_nospace);
return entry;
}