diff --git a/include/autotune.h b/include/autotune.h index 8282e6174..91fe92c9c 100644 --- a/include/autotune.h +++ b/include/autotune.h @@ -8,7 +8,7 @@ #define OPENCL_VECTOR_WIDTH 0 -int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig); +int autotune (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig); void *thread_autotune (void *p); diff --git a/include/data.h b/include/data.h index 2a18a9cde..6e10e2925 100644 --- a/include/data.h +++ b/include/data.h @@ -26,11 +26,9 @@ typedef struct * threads */ - uint devices_status; - uint devices_cnt; - uint devices_active; - hc_device_param_t *devices_param; + + opencl_ctx_t *opencl_ctx; uint shutdown_inner; uint shutdown_outer; @@ -74,12 +72,6 @@ typedef struct int rule_len_l; int rule_len_r; - /** - * opencl library stuff - */ - - void *ocl; - /** * hardware watchdog */ @@ -181,7 +173,7 @@ typedef struct char *truecrypt_keyfiles; char *veracrypt_keyfiles; uint veracrypt_pim; - uint workload_profile; + char *custom_charset_1; char *custom_charset_2; char *custom_charset_3; diff --git a/include/hash_management.h b/include/hash_management.h index ab19df474..28bf0a0d5 100644 --- a/include/hash_management.h +++ b/include/hash_management.h @@ -15,8 +15,8 @@ int sort_by_hash_no_salt (const void *v1, const void *v2); void save_hash (); -void check_hash (hc_device_param_t *device_param, plain_t *plain); +void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, plain_t *plain); -int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashconfig_t *hashconfig); +int check_cracked (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint salt_pos, hashconfig_t *hashconfig); #endif // _HASH_MANAGEMENT_H diff --git a/include/hwmon.h b/include/hwmon.h index 1e0a6d37d..588afc7ce 100644 --- a/include/hwmon.h +++ b/include/hwmon.h @@ -42,16 +42,16 @@ int hm_check_fanspeed_control (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_ // int hm_get_device_num (void *adl, HM_ADAPTER_ADL hm_adapter_index, int *hm_device_num); // void hm_get_opencl_busid_devid (hm_attrs_t *hm_device, uint opencl_num_devices, cl_device_id *devices); -int hm_get_threshold_slowdown_with_device_id (const uint device_id); -int hm_get_threshold_shutdown_with_device_id (const uint device_id); -int hm_get_temperature_with_device_id (const uint device_id); -int hm_get_fanspeed_with_device_id (const uint device_id); -int hm_get_fanpolicy_with_device_id (const uint device_id); -int hm_get_buslanes_with_device_id (const uint device_id); -int hm_get_utilization_with_device_id (const uint device_id); -int hm_get_memoryspeed_with_device_id (const uint device_id); -int hm_get_corespeed_with_device_id (const uint device_id); -int hm_get_throttle_with_device_id (const uint device_id); +int hm_get_threshold_slowdown_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_threshold_shutdown_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_temperature_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_fanspeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_fanpolicy_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_buslanes_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_utilization_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_memoryspeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_corespeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); +int hm_get_throttle_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id); int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed, const int fanpolicy); int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspeed, const int fanpolicy); int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fanspeed); diff --git a/include/opencl.h b/include/opencl.h index 646e99f3f..021ee8e66 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -224,25 +224,71 @@ struct __hc_device_param u32 kernel_params_memset_buf32[PARAMCNT]; }; -uint setup_opencl_platforms_filter (char *opencl_platforms); -u32 setup_devices_filter (char *opencl_devices); -cl_device_type setup_device_types_filter (char *opencl_device_types); +typedef struct +{ + int disable; + + void *ocl; + + cl_uint platforms_cnt; + cl_platform_id *platforms; + + cl_uint platform_devices_cnt; + cl_device_id *platform_devices; + + u32 devices_cnt; + u32 devices_active; + + hc_device_param_t *devices_param; + + u32 devices_status; + + u32 opencl_platforms_filter; + u32 devices_filter; + cl_device_type device_types_filter; + + u32 opencl_vector_width; + u32 opencl_vector_width_chgd; + + u32 nvidia_spin_damp; + u32 nvidia_spin_damp_chgd; + + uint kernel_loops; + uint kernel_loops_chgd; + + uint kernel_accel; + uint kernel_accel_chgd; + + uint workload_profile; + + int need_adl; + int need_nvml; + int need_nvapi; + int need_xnvctrl; + +} opencl_ctx_t; void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources); void writeProgramBin (char *dst, u8 *binary, size_t binary_size); -int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw); +int gidd_to_pw_t (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw); -int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration); -int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint num, const uint event_update, const uint iteration, hashconfig_t *hashconfig); -int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const uint num); -int run_kernel_tm (hc_device_param_t *device_param); -int run_kernel_amp (hc_device_param_t *device_param, const uint num); -int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint value, const uint num); -int run_kernel_bzero (hc_device_param_t *device_param, cl_mem buf, const size_t size); +int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration); +int run_kernel (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num, const uint event_update, const uint iteration, hashconfig_t *hashconfig); +int run_kernel_mp (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num); +int run_kernel_tm (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param); +int run_kernel_amp (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num); +int run_kernel_memset (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cl_mem buf, const uint value, const uint num); +int run_kernel_bzero (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cl_mem buf, const size_t size); -int run_copy (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt); +int run_copy (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt); -int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt); +int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt); + +int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, const char *opencl_devices, const char *opencl_device_types, const uint opencl_vector_width, const uint opencl_vector_width_chgd, const uint nvidia_spin_damp, const uint nvidia_spin_damp_chgd, const uint workload_profile, const uint kernel_accel, const uint kernel_accel_chgd, const uint kernel_loops, const uint kernel_loops_chgd, const uint keyspace, const uint stdout_flag); +void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx); + +int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const uint attack_mode, const uint quiet, const uint force, const uint benchmark, const uint machine_readable, const uint algorithm_pos); +void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx); #endif // _OPENCL_H diff --git a/include/restore.h b/include/restore.h index 3bd6e939a..dd4e96a99 100644 --- a/include/restore.h +++ b/include/restore.h @@ -47,18 +47,18 @@ typedef struct } restore_data_t; -u64 get_lowest_words_done (); +u64 get_lowest_words_done (opencl_ctx_t *opencl_ctx); restore_data_t *init_restore (int argc, char **argv); void read_restore (const char *eff_restore_file, restore_data_t *rd); -void write_restore (const char *new_restore_file, restore_data_t *rd); +void write_restore (opencl_ctx_t *opencl_ctx, const char *new_restore_file, restore_data_t *rd); -void cycle_restore (); +void cycle_restore (opencl_ctx_t *opencl_ctx); -void check_checkpoint (); +void check_checkpoint (opencl_ctx_t *opencl_ctx); -void stop_at_checkpoint (); +void stop_at_checkpoint (opencl_ctx_t *opencl_ctx); #endif // _RESTORE_H diff --git a/include/status.h b/include/status.h index 106081944..aa7ae852c 100644 --- a/include/status.h +++ b/include/status.h @@ -31,9 +31,9 @@ typedef enum status_rc double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); -void status_display_machine_readable (); -void status_display (); -void status_benchmark_automate (); -void status_benchmark (); +void status_display_machine_readable (opencl_ctx_t *opencl_ctx); +void status_display (opencl_ctx_t *opencl_ctx); +void status_benchmark_automate (opencl_ctx_t *opencl_ctx); +void status_benchmark (opencl_ctx_t *opencl_ctx); #endif // _STATUS_H diff --git a/include/stdout.h b/include/stdout.h index b97df77c7..1e840ad5d 100644 --- a/include/stdout.h +++ b/include/stdout.h @@ -31,6 +31,6 @@ typedef struct } out_t; -void process_stdout (hc_device_param_t *device_param, const uint pws_cnt); +void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint pws_cnt); #endif // _STDOUT_H diff --git a/include/thread.h b/include/thread.h index 2810b46b6..82f1eb9f7 100644 --- a/include/thread.h +++ b/include/thread.h @@ -62,12 +62,12 @@ void hc_signal (void (callback) (int)); #endif -void myabort (); -void myquit (); +void myabort (opencl_ctx_t *opencl_ctx); +void myquit (opencl_ctx_t *opencl_ctx); -void SuspendThreads (); -void ResumeThreads (); +void SuspendThreads (opencl_ctx_t *opencl_ctx); +void ResumeThreads (opencl_ctx_t *opencl_ctx); -void bypass (); +void bypass (opencl_ctx_t *opencl_ctx); #endif // _THREAD_H diff --git a/include/tuningdb.h b/include/tuningdb.h index a3fb4d56f..3b3182d14 100644 --- a/include/tuningdb.h +++ b/include/tuningdb.h @@ -43,6 +43,6 @@ typedef struct 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); +tuning_db_entry_t *tuning_db_search (const tuning_db_t *tuning_db, const char *device_name, const cl_device_type device_type, int attack_mode, const int hash_type); #endif // _TUNINGDB_H diff --git a/include/weak_hash.h b/include/weak_hash.h index c00ef1559..0d6e775ec 100644 --- a/include/weak_hash.h +++ b/include/weak_hash.h @@ -8,6 +8,6 @@ #define WEAK_HASH_THRESHOLD 100 -void weak_hash_check (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint salt_pos); +void weak_hash_check (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint salt_pos); #endif // _WEAK_HASH_H diff --git a/src/autotune.c b/src/autotune.c index 939266670..fb2234ca0 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -14,11 +14,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -32,7 +33,7 @@ extern hc_global_data_t data; static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; -static double try_run (hc_device_param_t *device_param, hashconfig_t *hashconfig, const u32 kernel_accel, const u32 kernel_loops) +static double try_run (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const u32 kernel_accel, const u32 kernel_loops) { const u32 kernel_power_try = device_param->device_processors * device_param->kernel_threads * kernel_accel; @@ -42,11 +43,11 @@ static double try_run (hc_device_param_t *device_param, hashconfig_t *hashconfig if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { - run_kernel (KERN_RUN_1, device_param, kernel_power_try, true, 0, hashconfig); + run_kernel (KERN_RUN_1, opencl_ctx, device_param, kernel_power_try, true, 0, hashconfig); } else { - run_kernel (KERN_RUN_2, device_param, kernel_power_try, true, 0, hashconfig); + run_kernel (KERN_RUN_2, opencl_ctx, device_param, kernel_power_try, true, 0, hashconfig); } const double exec_ms_prev = get_avg_exec_time (device_param, 1); @@ -54,9 +55,9 @@ static double try_run (hc_device_param_t *device_param, hashconfig_t *hashconfig return exec_ms_prev; } -int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) +int autotune (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig) { - const double target_ms = TARGET_MS_PROFILE[data.workload_profile - 1]; + const double target_ms = TARGET_MS_PROFILE[opencl_ctx->workload_profile - 1]; const u32 kernel_accel_min = device_param->kernel_accel_min; const u32 kernel_accel_max = device_param->kernel_accel_max; @@ -75,10 +76,10 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) { if (hashconfig->hash_mode != 2000) { - try_run (device_param, hashconfig, kernel_accel, kernel_loops); - try_run (device_param, hashconfig, kernel_accel, kernel_loops); - try_run (device_param, hashconfig, kernel_accel, kernel_loops); - try_run (device_param, hashconfig, kernel_accel, kernel_loops); + try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); + try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); + try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); + try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); } device_param->kernel_accel = kernel_accel; @@ -98,7 +99,7 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) if (data.attack_kern == ATTACK_KERN_BF) { - run_kernel_memset (device_param, device_param->d_pws_buf, 7, kernel_power_max * sizeof (pw_t)); + run_kernel_memset (opencl_ctx, device_param, device_param->d_pws_buf, 7, kernel_power_max * sizeof (pw_t)); } else { @@ -109,7 +110,7 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) device_param->pws_buf[i].pw_len = 7 + (i & 7); } - cl_int CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -123,7 +124,7 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) { if (data.kernel_rules_cnt > 1) { - cl_int CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, 0, 0, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t), 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, 0, 0, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t), 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -135,7 +136,7 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) } else { - run_kernel_amp (device_param, kernel_power_max); + run_kernel_amp (opencl_ctx, device_param, kernel_power_max); } #define VERIFIER_CNT 1 @@ -146,11 +147,11 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) { for (kernel_loops = kernel_loops_max; kernel_loops > kernel_loops_min; kernel_loops >>= 1) { - double exec_ms = try_run (device_param, hashconfig, kernel_accel_min, kernel_loops); + double exec_ms = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_min, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (device_param, hashconfig, kernel_accel_min, kernel_loops); + double exec_ms_v = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_min, kernel_loops); exec_ms = MIN (exec_ms, exec_ms_v); } @@ -172,11 +173,11 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) if (kernel_accel_try < kernel_accel_min) continue; if (kernel_accel_try > kernel_accel_max) break; - double exec_ms = try_run (device_param, hashconfig, kernel_accel_try, kernel_loops); + double exec_ms = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_try, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (device_param, hashconfig, kernel_accel_try, kernel_loops); + double exec_ms_v = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_try, kernel_loops); exec_ms = MIN (exec_ms, exec_ms_v); } @@ -195,11 +196,11 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) // due to the rebalance it's possible that the runtime reduces from 48ms to 47ms // and this creates the possibility to double the workload -> 47 * 2 = 95ms, which is < 96ms - double exec_ms_pre_final = try_run (device_param, hashconfig, kernel_accel, kernel_loops); + double exec_ms_pre_final = try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_pre_final_v = try_run (device_param, hashconfig, kernel_accel, kernel_loops); + double exec_ms_pre_final_v = try_run (opencl_ctx, device_param, hashconfig, kernel_accel, kernel_loops); exec_ms_pre_final = MIN (exec_ms_pre_final, exec_ms_pre_final_v); } @@ -225,11 +226,11 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) diff_new = diff; - double exec_ms = try_run (device_param, hashconfig, kernel_accel_try, kernel_loops_try); + double exec_ms = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_try, kernel_loops_try); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (device_param, hashconfig, kernel_accel_try, kernel_loops_try); + double exec_ms_v = try_run (opencl_ctx, device_param, hashconfig, kernel_accel_try, kernel_loops_try); exec_ms = MIN (exec_ms, exec_ms_v); } @@ -262,15 +263,15 @@ int autotune (hc_device_param_t *device_param, hashconfig_t *hashconfig) /* memset (device_param->pws_buf, 0, kernel_power_max * sizeof (pw_t)); - hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); - hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_pws_amp_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_amp_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); */ - run_kernel_memset (device_param, device_param->d_pws_buf, 0, kernel_power_max * sizeof (pw_t)); + run_kernel_memset (opencl_ctx, device_param, device_param->d_pws_buf, 0, kernel_power_max * sizeof (pw_t)); if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL) { - run_kernel_memset (device_param, device_param->d_pws_amp_buf, 0, kernel_power_max * sizeof (pw_t)); + run_kernel_memset (opencl_ctx, device_param, device_param->d_pws_amp_buf, 0, kernel_power_max * sizeof (pw_t)); } // reset timer @@ -317,9 +318,11 @@ void *thread_autotune (void *p) if (device_param->skipped) return NULL; + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + hashconfig_t *hashconfig = data.hashconfig; - autotune (device_param, hashconfig); + autotune (opencl_ctx, device_param, hashconfig); return NULL; } diff --git a/src/data.c b/src/data.c index 8c6118651..c84e942f4 100644 --- a/src/data.c +++ b/src/data.c @@ -13,11 +13,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/dispatch.c b/src/dispatch.c index 0426a05ac..a3ff422f5 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -16,13 +16,14 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -118,13 +119,15 @@ void *thread_calc_stdin (void *p) if (device_param->skipped) return NULL; + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + hashconfig_t *hashconfig = data.hashconfig; char *buf = (char *) mymalloc (HCBUFSIZ_LARGE); const uint attack_kern = data.attack_kern; - while ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + while ((opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { hc_thread_mutex_lock (mux_dispatcher); @@ -194,18 +197,18 @@ void *thread_calc_stdin (void *p) words_cur++; - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; } hc_thread_mutex_unlock (mux_dispatcher); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; // flush @@ -213,9 +216,9 @@ void *thread_calc_stdin (void *p) if (pws_cnt) { - run_copy (device_param, hashconfig, pws_cnt); + run_copy (opencl_ctx, device_param, hashconfig, pws_cnt); - run_cracker (device_param, hashconfig, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, pws_cnt); device_param->pws_cnt = 0; @@ -223,11 +226,11 @@ void *thread_calc_stdin (void *p) still required? if (attack_kern == ATTACK_KERN_STRAIGHT) { - run_kernel_bzero (device_param, device_param->d_rules_c, device_param->size_rules_c); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_rules_c, device_param->size_rules_c); } else if (attack_kern == ATTACK_KERN_COMBI) { - run_kernel_bzero (device_param, device_param->d_combs_c, device_param->size_combs); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs_c, device_param->size_combs); } */ } @@ -247,6 +250,8 @@ void *thread_calc (void *p) if (device_param->skipped) return NULL; + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + hashconfig_t *hashconfig = data.hashconfig; const uint attack_mode = data.attack_mode; @@ -254,7 +259,7 @@ void *thread_calc (void *p) if (attack_mode == ATTACK_MODE_BF) { - while ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + while ((opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { const uint work = get_work (device_param, -1u); @@ -269,9 +274,9 @@ void *thread_calc (void *p) if (pws_cnt) { - run_copy (device_param, hashconfig, pws_cnt); + run_copy (opencl_ctx, device_param, hashconfig, pws_cnt); - run_cracker (device_param, hashconfig, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, pws_cnt); device_param->pws_cnt = 0; @@ -281,12 +286,12 @@ void *thread_calc (void *p) */ } - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; if (data.benchmark == 1) break; @@ -366,7 +371,7 @@ void *thread_calc (void *p) u64 words_cur = 0; - while ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + while ((opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { u64 words_off = 0; u64 words_fin = 0; @@ -456,28 +461,28 @@ void *thread_calc (void *p) pw_add (device_param, (u8 *) line_buf, line_len); - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; } - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; } - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; // // flush @@ -487,9 +492,9 @@ void *thread_calc (void *p) if (pws_cnt) { - run_copy (device_param, hashconfig, pws_cnt); + run_copy (opencl_ctx, device_param, hashconfig, pws_cnt); - run_cracker (device_param, hashconfig, pws_cnt); + run_cracker (opencl_ctx, device_param, hashconfig, pws_cnt); device_param->pws_cnt = 0; @@ -506,12 +511,12 @@ void *thread_calc (void *p) */ } - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; if (words_fin == 0) break; diff --git a/src/ext_OpenCL.c b/src/ext_OpenCL.c index 459c7581d..736cd7e9e 100644 --- a/src/ext_OpenCL.c +++ b/src/ext_OpenCL.c @@ -141,9 +141,9 @@ void ocl_close (OCL_PTR *ocl) if (ocl) { if (ocl->lib) + { hc_dlclose (ocl->lib); - - myfree (ocl); + } } } diff --git a/src/hash_management.c b/src/hash_management.c index 00e4acfce..44c96f9bc 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -15,11 +15,13 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" +#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -27,7 +29,6 @@ #include "data.h" #include "terminal.h" #include "status.h" -#include "thread.h" #include "rp_kernel_on_cpu.h" #include "hash_management.h" @@ -222,7 +223,7 @@ void save_hash () unlink (old_hashfile); } -void check_hash (hc_device_param_t *device_param, plain_t *plain) +void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, plain_t *plain) { debugfile_ctx_t *debugfile_ctx = data.debugfile_ctx; loopback_ctx_t *loopback_ctx = data.loopback_ctx; @@ -271,7 +272,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) { pw_t pw; - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (int i = 0; i < 16; i++) { @@ -319,7 +320,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) { pw_t pw; - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (int i = 0; i < 16; i++) { @@ -377,7 +378,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) { pw_t pw; - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (int i = 0; i < 16; i++) { @@ -408,7 +409,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) { pw_t pw; - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (int i = 0; i < 16; i++) { @@ -481,7 +482,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) { - if ((data.devices_status != STATUS_CRACKED) && (data.status != 1)) + if ((opencl_ctx->devices_status != STATUS_CRACKED) && (data.status != 1)) { if (outfile_ctx->filename == NULL) if (quiet == 0) send_prompt (); } @@ -510,7 +511,7 @@ void check_hash (hc_device_param_t *device_param, plain_t *plain) } } -int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashconfig_t *hashconfig) +int check_cracked (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint salt_pos, hashconfig_t *hashconfig) { salt_t *salt_buf = &data.salts_buf[salt_pos]; @@ -518,7 +519,7 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon cl_int CL_err; - CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -535,7 +536,7 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon plain_t *cracked = (plain_t *) mycalloc (num_cracked, sizeof (plain_t)); - CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_plain_bufs, CL_TRUE, 0, num_cracked * sizeof (plain_t), cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_plain_bufs, CL_TRUE, 0, num_cracked * sizeof (plain_t), cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -572,9 +573,9 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon } } - if (data.salts_done == data.salts_cnt) data.devices_status = STATUS_CRACKED; + if (data.salts_done == data.salts_cnt) opencl_ctx->devices_status = STATUS_CRACKED; - check_hash (device_param, &cracked[i]); + check_hash (opencl_ctx, device_param, &cracked[i]); } hc_thread_mutex_unlock (mux_display); @@ -605,7 +606,7 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon memset (data.digests_shown_tmp, 0, salt_buf->digests_cnt * sizeof (uint)); - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, salt_buf->digests_offset * sizeof (uint), salt_buf->digests_cnt * sizeof (uint), &data.digests_shown_tmp[salt_buf->digests_offset], 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, salt_buf->digests_offset * sizeof (uint), salt_buf->digests_cnt * sizeof (uint), &data.digests_shown_tmp[salt_buf->digests_offset], 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -617,7 +618,7 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon num_cracked = 0; - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -629,5 +630,3 @@ int check_cracked (hc_device_param_t *device_param, const uint salt_pos, hashcon return 0; } - - diff --git a/src/hashcat.c b/src/hashcat.c index bc4067c0e..d41bb8afc 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -45,8 +45,10 @@ #include "cpu_sha1.h" #include "cpu_sha256.h" #include "filehandling.h" -#include "opencl.h" #include "tuningdb.h" +#include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "locking.h" #include "rp_cpu.h" @@ -54,9 +56,7 @@ #include "terminal.h" #include "inc_hash_constants.h" #include "shared.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -249,7 +249,6 @@ int main (int argc, char **argv) uint increment_min = INCREMENT_MIN; uint increment_max = INCREMENT_MAX; char *cpu_affinity = NULL; - OCL_PTR *ocl = NULL; char *opencl_devices = NULL; char *opencl_platforms = NULL; char *opencl_device_types = NULL; @@ -1570,7 +1569,7 @@ int main (int argc, char **argv) data.veracrypt_keyfiles = veracrypt_keyfiles; data.veracrypt_pim = veracrypt_pim; data.scrypt_tmto = scrypt_tmto; - data.workload_profile = workload_profile; + /** * cpu affinity @@ -1699,32 +1698,11 @@ int main (int argc, char **argv) * Init OpenCL library loader */ - if (keyspace == 0) - { - ocl = (OCL_PTR *) mymalloc (sizeof (OCL_PTR)); + opencl_ctx_t *opencl_ctx = (opencl_ctx_t *) mymalloc (sizeof (opencl_ctx_t)); - ocl_init (ocl); + data.opencl_ctx = opencl_ctx; - data.ocl = ocl; - } - - /** - * OpenCL platform selection - */ - - u32 opencl_platforms_filter = setup_opencl_platforms_filter (opencl_platforms); - - /** - * OpenCL device selection - */ - - u32 devices_filter = setup_devices_filter (opencl_devices); - - /** - * OpenCL device type selection - */ - - cl_device_type device_types_filter = setup_device_types_filter (opencl_device_types); + opencl_ctx_init (opencl_ctx, opencl_platforms, opencl_devices, opencl_device_types, opencl_vector_width, opencl_vector_width_chgd, nvidia_spin_damp, nvidia_spin_damp_chgd, workload_profile, kernel_accel, kernel_accel_chgd, kernel_loops, kernel_loops_chgd, keyspace, stdout_flag); /** * benchmark @@ -1768,7 +1746,7 @@ int main (int argc, char **argv) { workload_profile = 3; - data.workload_profile = workload_profile; + opencl_ctx->workload_profile = workload_profile; } } @@ -2894,7 +2872,7 @@ int main (int argc, char **argv) salts_done++; } - if (salts_done == salts_cnt) data.devices_status = STATUS_CRACKED; + if (salts_done == salts_cnt) opencl_ctx->devices_status = STATUS_CRACKED; } local_free (digests_buf); @@ -3295,1051 +3273,9 @@ int main (int argc, char **argv) } } - /** - * OpenCL platforms: detect - */ + const int rc_devices_init = opencl_ctx_devices_init (opencl_ctx, hashconfig, tuning_db, attack_mode, quiet, force, benchmark, machine_readable, algorithm_pos); - cl_platform_id platforms[CL_PLATFORMS_MAX] = { 0 }; - cl_device_id platform_devices[DEVICES_MAX] = { 0 }; - - cl_uint platforms_cnt = 0; - cl_uint platform_devices_cnt = 0; - - if (keyspace == 0) - { - cl_int CL_err = hc_clGetPlatformIDs (data.ocl, CL_PLATFORMS_MAX, platforms, &platforms_cnt); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformIDs(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (platforms_cnt == 0) - { - log_info (""); - log_info ("ATTENTION! No OpenCL compatible platform found"); - log_info (""); - log_info ("You're probably missing the OpenCL runtime installation"); - log_info (" AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); - log_info (" Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); - log_info (" NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); - log_info (""); - - return -1; - } - - if (opencl_platforms_filter != (uint) -1) - { - uint platform_cnt_mask = ~(((uint) -1 >> platforms_cnt) << platforms_cnt); - - if (opencl_platforms_filter > platform_cnt_mask) - { - log_error ("ERROR: The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%d)", platforms_cnt); - - return -1; - } - } - } - - if (opencl_device_types == NULL) - { - /** - * OpenCL device types: - * In case the user did not specify --opencl-device-types and the user runs hashcat in a system with only a CPU only he probably want to use that CPU. - */ - - cl_device_type device_types_all = 0; - - for (uint platform_id = 0; platform_id < platforms_cnt; platform_id++) - { - if ((opencl_platforms_filter & (1u << platform_id)) == 0) continue; - - cl_platform_id platform = platforms[platform_id]; - - cl_int CL_err = hc_clGetDeviceIDs (data.ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); - - if (CL_err != CL_SUCCESS) - { - //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - - // Silently ignore at this point, it will be reused later and create a note for the user at that point - - continue; - } - - for (uint platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) - { - cl_device_id device = platform_devices[platform_devices_id]; - - cl_device_type device_type; - - cl_int CL_err = hc_clGetDeviceInfo (data.ocl, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_types_all |= device_type; - } - } - - // In such a case, automatically enable CPU device type support, since it's disabled by default. - - if ((device_types_all & (CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR)) == 0) - { - device_types_filter |= CL_DEVICE_TYPE_CPU; - } - - // In another case, when the user uses --stdout, using CPU devices is much faster to setup - // If we have a CPU device, force it to be used - - if (stdout_flag == 1) - { - if (device_types_all & CL_DEVICE_TYPE_CPU) - { - device_types_filter = CL_DEVICE_TYPE_CPU; - } - } - } - - /** - * OpenCL devices: simply push all devices from all platforms into the same device array - */ - - int need_adl = 0; - int need_nvml = 0; - #ifndef __APPLE__ - int need_nvapi = 0; - int need_xnvctrl = 0; - #endif - - hc_device_param_t *devices_param = (hc_device_param_t *) mycalloc (DEVICES_MAX, sizeof (hc_device_param_t)); - - data.devices_param = devices_param; - - uint devices_cnt = 0; - - uint devices_active = 0; - - for (uint platform_id = 0; platform_id < platforms_cnt; platform_id++) - { - cl_int CL_err = CL_SUCCESS; - - cl_platform_id platform = platforms[platform_id]; - - char platform_vendor[HCBUFSIZ_TINY] = { 0 }; - - CL_err = hc_clGetPlatformInfo (data.ocl, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - // find our own platform vendor because pocl and mesa are pushing original vendor_id through opencl - // this causes trouble with vendor id based macros - // we'll assign generic to those without special optimization available - - cl_uint platform_vendor_id = 0; - - if (strcmp (platform_vendor, CL_VENDOR_AMD) == 0) - { - platform_vendor_id = VENDOR_ID_AMD; - } - else if (strcmp (platform_vendor, CL_VENDOR_AMD_USE_INTEL) == 0) - { - platform_vendor_id = VENDOR_ID_AMD_USE_INTEL; - } - else if (strcmp (platform_vendor, CL_VENDOR_APPLE) == 0) - { - platform_vendor_id = VENDOR_ID_APPLE; - } - else if (strcmp (platform_vendor, CL_VENDOR_INTEL_BEIGNET) == 0) - { - platform_vendor_id = VENDOR_ID_INTEL_BEIGNET; - } - else if (strcmp (platform_vendor, CL_VENDOR_INTEL_SDK) == 0) - { - platform_vendor_id = VENDOR_ID_INTEL_SDK; - } - else if (strcmp (platform_vendor, CL_VENDOR_MESA) == 0) - { - platform_vendor_id = VENDOR_ID_MESA; - } - else if (strcmp (platform_vendor, CL_VENDOR_NV) == 0) - { - platform_vendor_id = VENDOR_ID_NV; - } - else if (strcmp (platform_vendor, CL_VENDOR_POCL) == 0) - { - platform_vendor_id = VENDOR_ID_POCL; - } - else - { - platform_vendor_id = VENDOR_ID_GENERIC; - } - - uint platform_skipped = ((opencl_platforms_filter & (1u << platform_id)) == 0); - - CL_err = hc_clGetDeviceIDs (data.ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); - - if (CL_err != CL_SUCCESS) - { - //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - - platform_skipped = 2; - } - - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) - { - if (machine_readable == 0) - { - if (platform_skipped == 0) - { - const int len = log_info ("OpenCL Platform #%u: %s", platform_id + 1, platform_vendor); - - char line[256] = { 0 }; - - for (int i = 0; i < len; i++) line[i] = '='; - - log_info (line); - } - else if (platform_skipped == 1) - { - log_info ("OpenCL Platform #%u: %s, skipped", platform_id + 1, platform_vendor); - log_info (""); - } - else if (platform_skipped == 2) - { - log_info ("OpenCL Platform #%u: %s, skipped! No OpenCL compatible devices found", platform_id + 1, platform_vendor); - log_info (""); - } - } - } - - if (platform_skipped == 1) continue; - if (platform_skipped == 2) continue; - - for (uint platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) - { - size_t param_value_size = 0; - - const uint device_id = devices_cnt; - - hc_device_param_t *device_param = &data.devices_param[device_id]; - - device_param->platform_vendor_id = platform_vendor_id; - - device_param->device = platform_devices[platform_devices_id]; - - device_param->device_id = device_id; - - device_param->platform_devices_id = platform_devices_id; - - device_param->platform = platform; - - // device_type - - cl_device_type device_type; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_type &= ~CL_DEVICE_TYPE_DEFAULT; - - device_param->device_type = device_type; - - // device_name - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *device_name = (char *) mymalloc (param_value_size); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_name = device_name; - - // device_vendor - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *device_vendor = (char *) mymalloc (param_value_size); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_vendor = device_vendor; - - cl_uint device_vendor_id = 0; - - if (strcmp (device_vendor, CL_VENDOR_AMD) == 0) - { - device_vendor_id = VENDOR_ID_AMD; - } - else if (strcmp (device_vendor, CL_VENDOR_AMD_USE_INTEL) == 0) - { - device_vendor_id = VENDOR_ID_AMD_USE_INTEL; - } - else if (strcmp (device_vendor, CL_VENDOR_APPLE) == 0) - { - device_vendor_id = VENDOR_ID_APPLE; - } - else if (strcmp (device_vendor, CL_VENDOR_INTEL_BEIGNET) == 0) - { - device_vendor_id = VENDOR_ID_INTEL_BEIGNET; - } - else if (strcmp (device_vendor, CL_VENDOR_INTEL_SDK) == 0) - { - device_vendor_id = VENDOR_ID_INTEL_SDK; - } - else if (strcmp (device_vendor, CL_VENDOR_MESA) == 0) - { - device_vendor_id = VENDOR_ID_MESA; - } - else if (strcmp (device_vendor, CL_VENDOR_NV) == 0) - { - device_vendor_id = VENDOR_ID_NV; - } - else if (strcmp (device_vendor, CL_VENDOR_POCL) == 0) - { - device_vendor_id = VENDOR_ID_POCL; - } - else - { - device_vendor_id = VENDOR_ID_GENERIC; - } - - device_param->device_vendor_id = device_vendor_id; - - // tuning db - - tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param, attack_mode, hashconfig->hash_mode); - - // device_version - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *device_version = (char *) mymalloc (param_value_size); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_version = device_version; - - // device_opencl_version - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *device_opencl_version = (char *) mymalloc (param_value_size); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, device_opencl_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->opencl_v12 = device_opencl_version[9] > '1' || device_opencl_version[11] >= '2'; - - myfree (device_opencl_version); - - // vector_width - - cl_uint vector_width; - - if (opencl_vector_width_chgd == 0) - { - if (tuningdb_entry == NULL || tuningdb_entry->vector_width == -1) - { - if (hashconfig->opti_type & OPTI_TYPE_USES_BITS_64) - { - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - } - else - { - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - } - } - else - { - vector_width = (cl_uint) tuningdb_entry->vector_width; - } - } - else - { - vector_width = opencl_vector_width; - } - - if (vector_width > 16) vector_width = 16; - - device_param->vector_width = vector_width; - - // max_compute_units - - cl_uint device_processors; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_processors = device_processors; - - // device_maxmem_alloc - // note we'll limit to 2gb, otherwise this causes all kinds of weird errors because of possible integer overflows in opencl runtimes - - cl_ulong device_maxmem_alloc; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_maxmem_alloc = MIN (device_maxmem_alloc, 0x7fffffff); - - // device_global_mem - - cl_ulong device_global_mem; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_global_mem = device_global_mem; - - // max_work_group_size - - size_t device_maxworkgroup_size; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_maxworkgroup_size = device_maxworkgroup_size; - - // max_clock_frequency - - cl_uint device_maxclock_frequency; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->device_maxclock_frequency = device_maxclock_frequency; - - // device_endian_little - - cl_bool device_endian_little; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (device_endian_little == CL_FALSE) - { - log_info ("- Device #%u: WARNING: Not a little endian device", device_id + 1); - - device_param->skipped = 1; - } - - // device_available - - cl_bool device_available; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (device_available == CL_FALSE) - { - log_info ("- Device #%u: WARNING: Device not available", device_id + 1); - - device_param->skipped = 1; - } - - // device_compiler_available - - cl_bool device_compiler_available; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (device_compiler_available == CL_FALSE) - { - log_info ("- Device #%u: WARNING: No compiler available for device", device_id + 1); - - device_param->skipped = 1; - } - - // device_execution_capabilities - - cl_device_exec_capabilities device_execution_capabilities; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if ((device_execution_capabilities & CL_EXEC_KERNEL) == 0) - { - log_info ("- Device #%u: WARNING: Device does not support executing kernels", device_id + 1); - - device_param->skipped = 1; - } - - // device_extensions - - size_t device_extensions_size; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *device_extensions = mymalloc (device_extensions_size + 1); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (strstr (device_extensions, "base_atomics") == 0) - { - log_info ("- Device #%u: WARNING: Device does not support base atomics", device_id + 1); - - device_param->skipped = 1; - } - - if (strstr (device_extensions, "byte_addressable_store") == 0) - { - log_info ("- Device #%u: WARNING: Device does not support byte addressable store", device_id + 1); - - device_param->skipped = 1; - } - - myfree (device_extensions); - - // device_local_mem_size - - cl_ulong device_local_mem_size; - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - if (device_local_mem_size < 32768) - { - log_info ("- Device #%u: WARNING: Device local mem size is too small", device_id + 1); - - device_param->skipped = 1; - } - - // If there's both an Intel CPU and an AMD OpenCL runtime it's a tricky situation - // Both platforms support CPU device types and therefore both will try to use 100% of the physical resources - // This results in both utilizing it for 50% - // However, Intel has much better SIMD control over their own hardware - // It makes sense to give them full control over their own hardware - - if (device_type & CL_DEVICE_TYPE_CPU) - { - if (device_param->device_vendor_id == VENDOR_ID_AMD_USE_INTEL) - { - if (data.force == 0) - { - if (algorithm_pos == 0) - { - log_info ("- Device #%u: WARNING: Not a native Intel OpenCL runtime, expect massive speed loss", device_id + 1); - log_info (" You can use --force to override this but do not post error reports if you do so"); - } - - device_param->skipped = 1; - } - } - } - - // skipped - - device_param->skipped |= ((devices_filter & (1u << device_id)) == 0); - device_param->skipped |= ((device_types_filter & (device_type)) == 0); - - // driver_version - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - char *driver_version = (char *) mymalloc (param_value_size); - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->driver_version = driver_version; - - // device_name_chksum - - char *device_name_chksum = (char *) mymalloc (HCBUFSIZ_TINY); - - #if defined (__x86_64__) - snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%u-%u-%u-%s-%s-%s-%u", 64, device_param->platform_vendor_id, device_param->vector_width, device_param->device_name, device_param->device_version, device_param->driver_version, COMPTIME); - #else - snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%u-%u-%u-%s-%s-%s-%u", 32, device_param->platform_vendor_id, device_param->vector_width, device_param->device_name, device_param->device_version, device_param->driver_version, COMPTIME); - #endif - - uint device_name_digest[4] = { 0 }; - - md5_64 ((uint *) device_name_chksum, device_name_digest); - - snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%08x", device_name_digest[0]); - - device_param->device_name_chksum = device_name_chksum; - - // vendor specific - - if (device_param->device_type & CL_DEVICE_TYPE_GPU) - { - if ((device_param->platform_vendor_id == VENDOR_ID_AMD) && (device_param->device_vendor_id == VENDOR_ID_AMD)) - { - need_adl = 1; - } - - if ((device_param->platform_vendor_id == VENDOR_ID_NV) && (device_param->device_vendor_id == VENDOR_ID_NV)) - { - need_nvml = 1; - - #if defined (__linux__) - need_xnvctrl = 1; - #endif - - #if defined (_WIN) - need_nvapi = 1; - #endif - } - } - - if (device_type & CL_DEVICE_TYPE_GPU) - { - if (device_vendor_id == VENDOR_ID_NV) - { - cl_uint kernel_exec_timeout = 0; - - #define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->kernel_exec_timeout = kernel_exec_timeout; - - cl_uint sm_minor = 0; - cl_uint sm_major = 0; - - #define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 - #define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clGetDeviceInfo (data.ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - device_param->sm_minor = sm_minor; - device_param->sm_major = sm_major; - - // CPU burning loop damper - // Value is given as number between 0-100 - // By default 100% - - device_param->nvidia_spin_damp = (double) nvidia_spin_damp; - - if (nvidia_spin_damp_chgd == 0) - { - if (data.attack_mode == ATTACK_MODE_STRAIGHT) - { - /** - * the workaround is not a friend of rule based attacks - * the words from the wordlist combined with fast and slow rules cause - * fluctuations which cause inaccurate wait time estimations - * using a reduced damping percentage almost compensates this - */ - - device_param->nvidia_spin_damp = 64; - } - } - - device_param->nvidia_spin_damp /= 100; - } - } - - // display results - - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) - { - if (machine_readable == 0) - { - if (device_param->skipped == 0) - { - log_info ("- Device #%u: %s, %lu/%lu MB allocatable, %uMCU", - device_id + 1, - device_name, - (unsigned int) (device_maxmem_alloc / 1024 / 1024), - (unsigned int) (device_global_mem / 1024 / 1024), - (unsigned int) device_processors); - } - else - { - log_info ("- Device #%u: %s, skipped", - device_id + 1, - device_name); - } - } - } - - // common driver check - - if (device_param->skipped == 0) - { - if (device_type & CL_DEVICE_TYPE_GPU) - { - if (platform_vendor_id == VENDOR_ID_AMD) - { - int catalyst_check = (force == 1) ? 0 : 1; - - int catalyst_warn = 0; - - int catalyst_broken = 0; - - if (catalyst_check == 1) - { - catalyst_warn = 1; - - // v14.9 and higher - if (atoi (device_param->driver_version) >= 1573) - { - catalyst_warn = 0; - } - - catalyst_check = 0; - } - - if (catalyst_broken == 1) - { - log_info (""); - log_info ("ATTENTION! The Catalyst driver installed on your system is known to be broken!"); - log_info ("It passes over cracked hashes and will not report them as cracked"); - log_info ("You are STRONGLY encouraged not to use it"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); - - return -1; - } - - if (catalyst_warn == 1) - { - log_info (""); - log_info ("ATTENTION! Unsupported or incorrectly installed Catalyst driver detected!"); - log_info ("You are STRONGLY encouraged to use the official supported catalyst driver"); - log_info ("See hashcat's homepage for official supported catalyst drivers"); - #if defined (_WIN) - log_info ("Also see: http://hashcat.net/wiki/doku.php?id=upgrading_amd_drivers_how_to"); - #endif - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); - - return -1; - } - } - else if (platform_vendor_id == VENDOR_ID_NV) - { - if (device_param->kernel_exec_timeout != 0) - { - if (data.quiet == 0) log_info ("- Device #%u: WARNING! Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); - if (data.quiet == 0) log_info (" See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); - } - } - } - - /* turns out pocl still creates segfaults (because of llvm) - if (device_type & CL_DEVICE_TYPE_CPU) - { - if (platform_vendor_id == VENDOR_ID_AMD) - { - if (force == 0) - { - log_info (""); - log_info ("ATTENTION! OpenCL support for CPU of catalyst driver is not reliable."); - log_info ("You are STRONGLY encouraged not to use it"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info ("A good alternative is the free pocl >= v0.13, but make sure to use a LLVM >= v3.8"); - log_info (""); - - return -1; - } - } - } - */ - - /** - * kernel accel and loops tuning db adjustment - */ - - device_param->kernel_accel_min = 1; - device_param->kernel_accel_max = 1024; - - device_param->kernel_loops_min = 1; - device_param->kernel_loops_max = 1024; - - tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param, attack_mode, hashconfig->hash_mode); - - if (tuningdb_entry) - { - u32 _kernel_accel = tuningdb_entry->kernel_accel; - u32 _kernel_loops = tuningdb_entry->kernel_loops; - - if (_kernel_accel) - { - device_param->kernel_accel_min = _kernel_accel; - device_param->kernel_accel_max = _kernel_accel; - } - - if (_kernel_loops) - { - if (workload_profile == 1) - { - _kernel_loops = (_kernel_loops > 8) ? _kernel_loops / 8 : 1; - } - else if (workload_profile == 2) - { - _kernel_loops = (_kernel_loops > 4) ? _kernel_loops / 4 : 1; - } - - device_param->kernel_loops_min = _kernel_loops; - device_param->kernel_loops_max = _kernel_loops; - } - } - - // commandline parameters overwrite tuningdb entries - - if (kernel_accel) - { - device_param->kernel_accel_min = kernel_accel; - device_param->kernel_accel_max = kernel_accel; - } - - if (kernel_loops) - { - device_param->kernel_loops_min = kernel_loops; - device_param->kernel_loops_max = kernel_loops; - } - - /** - * activate device - */ - - devices_active++; - } - - // next please - - devices_cnt++; - } - - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) - { - if (machine_readable == 0) - { - log_info (""); - } - } - } - - if (keyspace == 0 && devices_active == 0) - { - log_error ("ERROR: No devices found/left"); - - return -1; - } - - // additional check to see if the user has chosen a device that is not within the range of available devices (i.e. larger than devices_cnt) - - if (devices_filter != (uint) -1) - { - uint devices_cnt_mask = ~(((uint) -1 >> devices_cnt) << devices_cnt); - - if (devices_filter > devices_cnt_mask) - { - log_error ("ERROR: The device specified by the --opencl-devices parameter is larger than the number of available devices (%d)", devices_cnt); - - return -1; - } - } - - data.devices_cnt = devices_cnt; - - data.devices_active = devices_active; + if (rc_devices_init == -1) return -1; /** * HM devices: init @@ -4368,7 +3304,7 @@ int main (int argc, char **argv) data.hm_nvml = NULL; data.hm_xnvctrl = NULL; - if ((need_nvml == 1) && (nvml_init (nvml) == 0)) + if ((opencl_ctx->need_nvml == 1) && (nvml_init (nvml) == 0)) { data.hm_nvml = nvml; } @@ -4401,7 +3337,7 @@ int main (int argc, char **argv) } } - if ((need_nvapi == 1) && (nvapi_init (nvapi) == 0)) + if ((opencl_ctx->need_nvapi == 1) && (nvapi_init (nvapi) == 0)) { data.hm_nvapi = nvapi; } @@ -4423,7 +3359,7 @@ int main (int argc, char **argv) } } - if ((need_xnvctrl == 1) && (xnvctrl_init (xnvctrl) == 0)) + if ((opencl_ctx->need_xnvctrl == 1) && (xnvctrl_init (xnvctrl) == 0)) { data.hm_xnvctrl = xnvctrl; } @@ -4432,9 +3368,9 @@ int main (int argc, char **argv) { if (hm_XNVCTRL_XOpenDisplay (data.hm_xnvctrl) == 0) { - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if ((device_param->device_type & CL_DEVICE_TYPE_GPU) == 0) continue; @@ -4447,7 +3383,7 @@ int main (int argc, char **argv) } } - if ((need_adl == 1) && (adl_init (adl) == 0)) + if ((opencl_ctx->need_adl == 1) && (adl_init (adl) == 0)) { data.hm_adl = adl; } @@ -4503,11 +3439,11 @@ int main (int argc, char **argv) * OpenCL devices: allocate buffer for device specific information */ - ADLOD6MemClockState *od_clock_mem_status = (ADLOD6MemClockState *) mycalloc (data.devices_cnt, sizeof (ADLOD6MemClockState)); + ADLOD6MemClockState *od_clock_mem_status = (ADLOD6MemClockState *) mycalloc (opencl_ctx->devices_cnt, sizeof (ADLOD6MemClockState)); - int *od_power_control_status = (int *) mycalloc (data.devices_cnt, sizeof (int)); + int *od_power_control_status = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); - unsigned int *nvml_power_limit = (unsigned int *) mycalloc (data.devices_cnt, sizeof (unsigned int)); + unsigned int *nvml_power_limit = (unsigned int *) mycalloc (opencl_ctx->devices_cnt, sizeof (unsigned int)); /** * User-defined GPU temp handling @@ -4614,9 +3550,9 @@ int main (int argc, char **argv) if (gpu_temp_disable == 0) { - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if ((device_param->device_type & CL_DEVICE_TYPE_GPU) == 0) continue; @@ -4656,13 +3592,13 @@ int main (int argc, char **argv) { hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { /** * Temporary fix: @@ -4802,7 +3738,7 @@ int main (int argc, char **argv) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { // first backup current value, we will restore it later @@ -4849,7 +3785,7 @@ int main (int argc, char **argv) if (data.quiet == 0) log_info_nn ("Initializing device kernels and memory..."); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { cl_int CL_err = CL_SUCCESS; @@ -4857,7 +3793,7 @@ int main (int argc, char **argv) * host buffer */ - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -4878,7 +3814,7 @@ int main (int argc, char **argv) properties[1] = (cl_context_properties) device_param->platform; properties[2] = 0; - CL_err = hc_clCreateContext (data.ocl, properties, 1, &device_param->device, NULL, NULL, &device_param->context); + CL_err = hc_clCreateContext (opencl_ctx->ocl, properties, 1, &device_param->device, NULL, NULL, &device_param->context); if (CL_err != CL_SUCCESS) { @@ -4894,7 +3830,7 @@ int main (int argc, char **argv) // not supported with NV // device_param->command_queue = hc_clCreateCommandQueueWithProperties (device_param->context, device_param->device, NULL); - CL_err = hc_clCreateCommandQueue (data.ocl, device_param->context, device_param->device, CL_QUEUE_PROFILING_ENABLE, &device_param->command_queue); + CL_err = hc_clCreateCommandQueue (opencl_ctx->ocl, device_param->context, device_param->device, CL_QUEUE_PROFILING_ENABLE, &device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -5499,7 +4435,7 @@ int main (int argc, char **argv) load_kernel (source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (data.ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); + CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); if (CL_err != CL_SUCCESS) { @@ -5508,7 +4444,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5520,7 +4456,7 @@ int main (int argc, char **argv) size_t build_log_size = 0; /* - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); if (CL_err != CL_SUCCESS) { @@ -5530,7 +4466,7 @@ int main (int argc, char **argv) } */ - hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -5540,7 +4476,7 @@ int main (int argc, char **argv) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); if (CL_err != CL_SUCCESS) { @@ -5565,7 +4501,7 @@ int main (int argc, char **argv) size_t binary_size; - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); if (CL_err != CL_SUCCESS) { @@ -5576,7 +4512,7 @@ int main (int argc, char **argv) u8 *binary = (u8 *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); if (CL_err != CL_SUCCESS) { @@ -5597,7 +4533,7 @@ int main (int argc, char **argv) load_kernel (cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (data.ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program); + CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program); if (CL_err != CL_SUCCESS) { @@ -5606,7 +4542,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5624,7 +4560,7 @@ int main (int argc, char **argv) load_kernel (source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (data.ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); + CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); if (CL_err != CL_SUCCESS) { @@ -5648,7 +4584,7 @@ int main (int argc, char **argv) snprintf (build_opts_update, sizeof (build_opts_update) - 1, "%s", build_opts); } - CL_err = hc_clBuildProgram (data.ocl, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5660,7 +4596,7 @@ int main (int argc, char **argv) size_t build_log_size = 0; /* - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); if (CL_err != CL_SUCCESS) { @@ -5670,7 +4606,7 @@ int main (int argc, char **argv) } */ - hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -5680,7 +4616,7 @@ int main (int argc, char **argv) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); if (CL_err != CL_SUCCESS) { @@ -5762,7 +4698,7 @@ int main (int argc, char **argv) load_kernel (source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (data.ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_mp); + CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_mp); if (CL_err != CL_SUCCESS) { @@ -5771,7 +4707,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5783,7 +4719,7 @@ int main (int argc, char **argv) size_t build_log_size = 0; /* - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); if (CL_err != CL_SUCCESS) { @@ -5793,7 +4729,7 @@ int main (int argc, char **argv) } */ - hc_clGetProgramBuildInfo (data.ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -5803,7 +4739,7 @@ int main (int argc, char **argv) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); if (CL_err != CL_SUCCESS) { @@ -5828,7 +4764,7 @@ int main (int argc, char **argv) size_t binary_size; - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program_mp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_mp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); if (CL_err != CL_SUCCESS) { @@ -5839,7 +4775,7 @@ int main (int argc, char **argv) u8 *binary = (u8 *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); if (CL_err != CL_SUCCESS) { @@ -5860,7 +4796,7 @@ int main (int argc, char **argv) load_kernel (cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (data.ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program_mp); + CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program_mp); if (CL_err != CL_SUCCESS) { @@ -5869,7 +4805,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5943,7 +4879,7 @@ int main (int argc, char **argv) load_kernel (source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (data.ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_amp); + CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_amp); if (CL_err != CL_SUCCESS) { @@ -5952,7 +4888,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -5964,7 +4900,7 @@ int main (int argc, char **argv) size_t build_log_size = 0; /* - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); if (CL_err != CL_SUCCESS) { @@ -5974,7 +4910,7 @@ int main (int argc, char **argv) } */ - hc_clGetProgramBuildInfo (data.ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -5984,7 +4920,7 @@ int main (int argc, char **argv) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (data.ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); if (CL_err != CL_SUCCESS) { @@ -6009,7 +4945,7 @@ int main (int argc, char **argv) size_t binary_size; - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program_amp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_amp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); if (CL_err != CL_SUCCESS) { @@ -6020,7 +4956,7 @@ int main (int argc, char **argv) u8 *binary = (u8 *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (data.ocl, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); if (CL_err != CL_SUCCESS) { @@ -6041,7 +4977,7 @@ int main (int argc, char **argv) load_kernel (cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (data.ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program_amp); + CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const u8 **) kernel_sources, NULL, &device_param->program_amp); if (CL_err != CL_SUCCESS) { @@ -6050,7 +4986,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clBuildProgram (data.ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -6088,27 +5024,27 @@ int main (int argc, char **argv) * global buffers */ - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_amp_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->d_tmps); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->d_hooks); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_a); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_b); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_c); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_d); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_a); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_b); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_c); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_d); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->d_plain_bufs); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->d_digests_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->d_digests_shown); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->d_salt_bufs); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->d_result); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV0_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_amp_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->d_tmps); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->d_hooks); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_a); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_b); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s1_d); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_a); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_b); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_size, NULL, &device_param->d_bitmap_s2_d); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->d_plain_bufs); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->d_digests_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->d_digests_shown); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->d_salt_bufs); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->d_result); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV0_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); if (CL_err != CL_SUCCESS) { @@ -6117,17 +5053,17 @@ int main (int argc, char **argv) return -1; } - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_size, bitmap_s1_a, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_size, bitmap_s1_b, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_size, bitmap_s1_c, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_size, bitmap_s1_d, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_size, bitmap_s2_a, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_size, bitmap_s2_b, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_size, bitmap_s2_c, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_size, bitmap_s2_d, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, data.digests_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, data.digests_shown, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, data.salts_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_size, bitmap_s1_a, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_size, bitmap_s1_b, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_size, bitmap_s1_c, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_size, bitmap_s1_d, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_size, bitmap_s2_a, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_size, bitmap_s2_b, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_size, bitmap_s2_c, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_size, bitmap_s2_d, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, data.digests_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, data.digests_shown, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, data.salts_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -6142,8 +5078,8 @@ int main (int argc, char **argv) if (attack_kern == ATTACK_KERN_STRAIGHT) { - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); if (CL_err != CL_SUCCESS) { @@ -6152,7 +5088,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_rules, CL_TRUE, 0, size_rules, kernel_rules_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, CL_TRUE, 0, size_rules, kernel_rules_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -6163,10 +5099,10 @@ int main (int argc, char **argv) } else if (attack_kern == ATTACK_KERN_COMBI) { - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); if (CL_err != CL_SUCCESS) { @@ -6177,11 +5113,11 @@ int main (int argc, char **argv) } else if (attack_kern == ATTACK_KERN_BF) { - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->d_tm_c); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); - CL_err |= hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->d_tm_c); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); + CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); if (CL_err != CL_SUCCESS) { @@ -6193,7 +5129,7 @@ int main (int argc, char **argv) if (size_esalts) { - CL_err = hc_clCreateBuffer (data.ocl, device_param->context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->d_esalt_bufs); + CL_err = hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->d_esalt_bufs); if (CL_err != CL_SUCCESS) { @@ -6202,7 +5138,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_esalt_bufs, CL_TRUE, 0, size_esalts, data.esalts_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_esalt_bufs, CL_TRUE, 0, size_esalts, data.esalts_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -6370,7 +5306,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 4); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); if (CL_err != CL_SUCCESS) { @@ -6381,7 +5317,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 8); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); if (CL_err != CL_SUCCESS) { @@ -6392,7 +5328,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 16); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); if (CL_err != CL_SUCCESS) { @@ -6405,7 +5341,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 4); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); if (CL_err != CL_SUCCESS) { @@ -6416,7 +5352,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 8); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); if (CL_err != CL_SUCCESS) { @@ -6427,7 +5363,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 16); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); if (CL_err != CL_SUCCESS) { @@ -6443,7 +5379,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_tm", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel_tm); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel_tm); if (CL_err != CL_SUCCESS) { @@ -6452,7 +5388,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_tm, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_tm, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6467,7 +5403,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_init", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); if (CL_err != CL_SUCCESS) { @@ -6478,7 +5414,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_loop", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); if (CL_err != CL_SUCCESS) { @@ -6489,7 +5425,7 @@ int main (int argc, char **argv) snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_comp", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); if (CL_err != CL_SUCCESS) { @@ -6502,7 +5438,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_hook12", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel12); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel12); if (CL_err != CL_SUCCESS) { @@ -6511,7 +5447,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel12, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel12, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6525,7 +5461,7 @@ int main (int argc, char **argv) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_hook23", hashconfig->kern_type); - CL_err = hc_clCreateKernel (data.ocl, device_param->program, kernel_name, &device_param->kernel23); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel23); if (CL_err != CL_SUCCESS) { @@ -6534,7 +5470,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel23, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel23, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6545,9 +5481,9 @@ int main (int argc, char **argv) } } - CL_err |= hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel1, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel2, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel3, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel1, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel2, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel3, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6558,12 +5494,12 @@ int main (int argc, char **argv) for (uint i = 0; i <= 23; i++) { - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_err != CL_SUCCESS) { @@ -6575,12 +5511,12 @@ int main (int argc, char **argv) for (uint i = 24; i <= 34; i++) { - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_err != CL_SUCCESS) { @@ -6592,7 +5528,7 @@ int main (int argc, char **argv) // GPU memset - CL_err = hc_clCreateKernel (data.ocl, device_param->program, "gpu_memset", &device_param->kernel_memset); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, "gpu_memset", &device_param->kernel_memset); if (CL_err != CL_SUCCESS) { @@ -6601,7 +5537,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_memset, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_memset, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6610,9 +5546,9 @@ int main (int argc, char **argv) return -1; } - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_memset, 0, sizeof (cl_mem), device_param->kernel_params_memset[0]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_memset, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_memset, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 0, sizeof (cl_mem), device_param->kernel_params_memset[0]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); if (CL_err != CL_SUCCESS) { @@ -6625,8 +5561,8 @@ int main (int argc, char **argv) if (attack_mode == ATTACK_MODE_BF) { - CL_err |= hc_clCreateKernel (data.ocl, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); - CL_err |= hc_clCreateKernel (data.ocl, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); + CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); + CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); if (CL_err != CL_SUCCESS) { @@ -6635,8 +5571,8 @@ int main (int argc, char **argv) return -1; } - CL_err |= hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_mp_l, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_mp_r, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp_l, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp_r, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6647,8 +5583,8 @@ int main (int argc, char **argv) if (hashconfig->opts_type & OPTS_TYPE_PT_BITSLICE) { - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); - CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); if (CL_err != CL_SUCCESS) { @@ -6660,7 +5596,7 @@ int main (int argc, char **argv) } else if (attack_mode == ATTACK_MODE_HYBRID1) { - CL_err = hc_clCreateKernel (data.ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); if (CL_err != CL_SUCCESS) { @@ -6669,7 +5605,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6680,7 +5616,7 @@ int main (int argc, char **argv) } else if (attack_mode == ATTACK_MODE_HYBRID2) { - CL_err = hc_clCreateKernel (data.ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); if (CL_err != CL_SUCCESS) { @@ -6689,7 +5625,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6705,7 +5641,7 @@ int main (int argc, char **argv) } else { - CL_err = hc_clCreateKernel (data.ocl, device_param->program_amp, "amp", &device_param->kernel_amp); + CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_amp, "amp", &device_param->kernel_amp); if (CL_err != CL_SUCCESS) { @@ -6714,7 +5650,7 @@ int main (int argc, char **argv) return -1; } - CL_err = hc_clGetKernelWorkGroupInfo (data.ocl, device_param->kernel_amp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_amp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_err != CL_SUCCESS) { @@ -6732,7 +5668,7 @@ int main (int argc, char **argv) { for (uint i = 0; i < 5; i++) { - CL_err = hc_clSetKernelArg (data.ocl, device_param->kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]); + CL_err = hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]); if (CL_err != CL_SUCCESS) { @@ -6744,7 +5680,7 @@ int main (int argc, char **argv) for (uint i = 5; i < 7; i++) { - CL_err = hc_clSetKernelArg (data.ocl, device_param->kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]); + CL_err = hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]); if (CL_err != CL_SUCCESS) { @@ -6762,12 +5698,12 @@ int main (int argc, char **argv) // zero some data buffers - run_kernel_bzero (device_param, device_param->d_pws_buf, size_pws); - run_kernel_bzero (device_param, device_param->d_pws_amp_buf, size_pws); - run_kernel_bzero (device_param, device_param->d_tmps, size_tmps); - run_kernel_bzero (device_param, device_param->d_hooks, size_hooks); - run_kernel_bzero (device_param, device_param->d_plain_bufs, size_plains); - run_kernel_bzero (device_param, device_param->d_result, size_results); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_pws_buf, size_pws); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_pws_amp_buf, size_pws); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_tmps, size_tmps); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_hooks, size_hooks); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_plain_bufs, size_plains); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_result, size_results); /** * special buffers @@ -6775,22 +5711,22 @@ int main (int argc, char **argv) if (attack_kern == ATTACK_KERN_STRAIGHT) { - run_kernel_bzero (device_param, device_param->d_rules_c, size_rules_c); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_rules_c, size_rules_c); } else if (attack_kern == ATTACK_KERN_COMBI) { - run_kernel_bzero (device_param, device_param->d_combs, size_combs); - run_kernel_bzero (device_param, device_param->d_combs_c, size_combs); - run_kernel_bzero (device_param, device_param->d_root_css_buf, size_root_css); - run_kernel_bzero (device_param, device_param->d_markov_css_buf, size_markov_css); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs, size_combs); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs_c, size_combs); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_root_css_buf, size_root_css); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); } else if (attack_kern == ATTACK_KERN_BF) { - run_kernel_bzero (device_param, device_param->d_bfs, size_bfs); - run_kernel_bzero (device_param, device_param->d_bfs_c, size_bfs); - run_kernel_bzero (device_param, device_param->d_tm_c, size_tm); - run_kernel_bzero (device_param, device_param->d_root_css_buf, size_root_css); - run_kernel_bzero (device_param, device_param->d_markov_css_buf, size_markov_css); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_bfs, size_bfs); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_bfs_c, size_bfs); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_tm_c, size_tm); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_root_css_buf, size_root_css); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); } #if defined(HAVE_HWMON) @@ -6807,8 +5743,8 @@ int main (int argc, char **argv) if (data.hm_device[device_id].fan_get_supported == 1) { - const int fanspeed = hm_get_fanspeed_with_device_id (device_id); - const int fanpolicy = hm_get_fanpolicy_with_device_id (device_id); + const int fanspeed = hm_get_fanspeed_with_device_id (opencl_ctx, device_id); + const int fanpolicy = hm_get_fanpolicy_with_device_id (opencl_ctx, device_id); // we also set it to tell the OS we take control over the fan and it's automatic controller // if it was set to automatic. we do not control user-defined fanspeeds. @@ -7692,9 +6628,9 @@ int main (int argc, char **argv) { hc_device_param_t *device_param = NULL; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - device_param = &data.devices_param[device_id]; + device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -7705,7 +6641,7 @@ int main (int argc, char **argv) for (uint salt_pos = 0; salt_pos < salts_cnt; salt_pos++) { - weak_hash_check (device_param, hashconfig, salt_pos); + weak_hash_check (opencl_ctx, device_param, hashconfig, salt_pos); } // Display hack, guarantee that there is at least one \r before real start @@ -7717,9 +6653,9 @@ int main (int argc, char **argv) * status and monitor threads */ - if ((data.devices_status != STATUS_BYPASS) && (data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + if ((opencl_ctx->devices_status != STATUS_BYPASS) && (opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { - data.devices_status = STATUS_STARTING; + opencl_ctx->devices_status = STATUS_STARTING; } uint inner_threads_cnt = 0; @@ -7791,9 +6727,9 @@ int main (int argc, char **argv) for (uint maskpos = rd->maskpos; maskpos < maskcnt; maskpos++) { - if (data.devices_status == STATUS_CRACKED) continue; - if (data.devices_status == STATUS_ABORTED) continue; - if (data.devices_status == STATUS_QUIT) continue; + if (opencl_ctx->devices_status == STATUS_CRACKED) continue; + if (opencl_ctx->devices_status == STATUS_ABORTED) continue; + if (opencl_ctx->devices_status == STATUS_QUIT) continue; if (maskpos > rd->maskpos) { @@ -7954,9 +6890,9 @@ int main (int argc, char **argv) // args - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -7986,9 +6922,9 @@ int main (int argc, char **argv) cl_int CL_err = CL_SUCCESS; - for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp[i]); - for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp[i]); - for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp[i]); + for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp[i]); + for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp[i]); + for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp[i]); if (CL_err != CL_SUCCESS) { @@ -7997,8 +6933,8 @@ int main (int argc, char **argv) return -1; } - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -8095,9 +7031,9 @@ int main (int argc, char **argv) for (uint dictpos = rd->dictpos; dictpos < dictcnt; dictpos++) { - if (data.devices_status == STATUS_CRACKED) continue; - if (data.devices_status == STATUS_ABORTED) continue; - if (data.devices_status == STATUS_QUIT) continue; + if (opencl_ctx->devices_status == STATUS_CRACKED) continue; + if (opencl_ctx->devices_status == STATUS_ABORTED) continue; + if (opencl_ctx->devices_status == STATUS_QUIT) continue; rd->dictpos = dictpos; @@ -8107,9 +7043,9 @@ int main (int argc, char **argv) logfile_sub_msg ("START"); - if ((data.devices_status != STATUS_BYPASS) && (data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + if ((opencl_ctx->devices_status != STATUS_BYPASS) && (opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { - data.devices_status = STATUS_INIT; + opencl_ctx->devices_status = STATUS_INIT; } memset (data.words_progress_done, 0, data.salts_cnt * sizeof (u64)); @@ -8139,9 +7075,9 @@ int main (int argc, char **argv) data.words_cur = rd->words_cur; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -8487,9 +7423,9 @@ int main (int argc, char **argv) data.bfs_cnt = sp_get_sum (0, css_cnt_r, root_css_buf); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -8521,13 +7457,13 @@ int main (int argc, char **argv) cl_int CL_err = CL_SUCCESS; - for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); - for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); - for (uint i = 4; i < 9; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); + for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); + for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); + for (uint i = 4; i < 9; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); - for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); - for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); - for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (data.ocl, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); + for (uint i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); + for (uint i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); + for (uint i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); if (CL_err != CL_SUCCESS) { @@ -8536,8 +7472,8 @@ int main (int argc, char **argv) return -1; } - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, root_css_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, markov_css_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -8635,21 +7571,21 @@ int main (int argc, char **argv) * create autotune threads */ - hc_thread_t *c_threads = (hc_thread_t *) mycalloc (data.devices_cnt, sizeof (hc_thread_t)); + hc_thread_t *c_threads = (hc_thread_t *) mycalloc (opencl_ctx->devices_cnt, sizeof (hc_thread_t)); - if ((data.devices_status != STATUS_BYPASS) && (data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + if ((opencl_ctx->devices_status != STATUS_BYPASS) && (opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { - data.devices_status = STATUS_AUTOTUNE; + opencl_ctx->devices_status = STATUS_AUTOTUNE; } - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; hc_thread_create (c_threads[device_id], thread_autotune, device_param); } - hc_thread_wait (data.devices_cnt, c_threads); + hc_thread_wait (opencl_ctx->devices_cnt, c_threads); /* * Inform user about possible slow speeds @@ -8659,9 +7595,9 @@ int main (int argc, char **argv) uint kernel_power_all = 0; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; hardware_power_all += device_param->hardware_power; @@ -8694,14 +7630,14 @@ int main (int argc, char **argv) * create cracker threads */ - if ((data.devices_status != STATUS_BYPASS) && (data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + if ((opencl_ctx->devices_status != STATUS_BYPASS) && (opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { - data.devices_status = STATUS_RUNNING; + opencl_ctx->devices_status = STATUS_RUNNING; } if (initial_restore_done == 0) { - if (data.restore_disable == 0) cycle_restore (); + if (data.restore_disable == 0) cycle_restore (opencl_ctx); initial_restore_done = 1; } @@ -8729,9 +7665,9 @@ int main (int argc, char **argv) data.prepare_time += runtime_start - prepare_start; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (wordlist_mode == WL_MODE_STDIN) { @@ -8743,16 +7679,16 @@ int main (int argc, char **argv) } } - hc_thread_wait (data.devices_cnt, c_threads); + hc_thread_wait (opencl_ctx->devices_cnt, c_threads); local_free (c_threads); - if ((data.devices_status != STATUS_BYPASS) && (data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT)) + if ((opencl_ctx->devices_status != STATUS_BYPASS) && (opencl_ctx->devices_status != STATUS_CRACKED) && (opencl_ctx->devices_status != STATUS_ABORTED) && (opencl_ctx->devices_status != STATUS_QUIT)) { - data.devices_status = STATUS_EXHAUSTED; + opencl_ctx->devices_status = STATUS_EXHAUSTED; } - logfile_sub_var_uint ("status-after-work", data.devices_status); + logfile_sub_var_uint ("status-after-work", opencl_ctx->devices_status); data.restore = 0; @@ -8772,7 +7708,7 @@ int main (int argc, char **argv) if (benchmark == 1) { - status_benchmark (); + status_benchmark (opencl_ctx); if (machine_readable == 0) { @@ -8787,7 +7723,7 @@ int main (int argc, char **argv) log_info (""); - status_display (); + status_display (opencl_ctx); log_info (""); } @@ -8795,7 +7731,7 @@ int main (int argc, char **argv) { if (status == 1) { - status_display (); + status_display (opencl_ctx); } } } @@ -8835,31 +7771,31 @@ int main (int argc, char **argv) // from this point we handle bypass as running - if (data.devices_status == STATUS_BYPASS) + if (opencl_ctx->devices_status == STATUS_BYPASS) { - data.devices_status = STATUS_RUNNING; + opencl_ctx->devices_status = STATUS_RUNNING; } // and overwrite benchmark aborts as well if (data.benchmark == 1) { - if (data.devices_status == STATUS_ABORTED) + if (opencl_ctx->devices_status == STATUS_ABORTED) { - data.devices_status = STATUS_RUNNING; + opencl_ctx->devices_status = STATUS_RUNNING; } } // finalize task - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; } - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; } // problems could occur if already at startup everything was cracked (because of .pot file reading etc), we must set some variables here to avoid NULL pointers @@ -8927,14 +7863,14 @@ int main (int argc, char **argv) // we dont need restore file anymore if (data.restore_disable == 0) { - if ((data.devices_status == STATUS_EXHAUSTED) || (data.devices_status == STATUS_CRACKED)) + if ((opencl_ctx->devices_status == STATUS_EXHAUSTED) || (opencl_ctx->devices_status == STATUS_CRACKED)) { unlink (eff_restore_file); unlink (new_restore_file); } else { - cycle_restore (); + cycle_restore (opencl_ctx); } } @@ -8942,16 +7878,16 @@ int main (int argc, char **argv) if ((hashlist_mode == HL_MODE_FILE) && (remove == 1) && (data.digests_saved != data.digests_done)) { - save_hash (); + save_hash (opencl_ctx); } /** * Clean up */ - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -8966,37 +7902,37 @@ int main (int argc, char **argv) if (device_param->pws_buf) myfree (device_param->pws_buf); - if (device_param->d_pws_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_pws_buf); - if (device_param->d_pws_amp_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_pws_amp_buf); - if (device_param->d_rules) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_rules); - if (device_param->d_rules_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_rules_c); - if (device_param->d_combs) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_combs); - if (device_param->d_combs_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_combs_c); - if (device_param->d_bfs) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bfs); - if (device_param->d_bfs_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bfs_c); - if (device_param->d_bitmap_s1_a) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s1_a); - if (device_param->d_bitmap_s1_b) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s1_b); - if (device_param->d_bitmap_s1_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s1_c); - if (device_param->d_bitmap_s1_d) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s1_d); - if (device_param->d_bitmap_s2_a) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s2_a); - if (device_param->d_bitmap_s2_b) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s2_b); - if (device_param->d_bitmap_s2_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s2_c); - if (device_param->d_bitmap_s2_d) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_bitmap_s2_d); - if (device_param->d_plain_bufs) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_plain_bufs); - if (device_param->d_digests_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_digests_buf); - if (device_param->d_digests_shown) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_digests_shown); - if (device_param->d_salt_bufs) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_salt_bufs); - if (device_param->d_esalt_bufs) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_esalt_bufs); - if (device_param->d_tmps) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_tmps); - if (device_param->d_hooks) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_hooks); - if (device_param->d_result) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_result); - if (device_param->d_scryptV0_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_scryptV0_buf); - if (device_param->d_scryptV1_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_scryptV1_buf); - if (device_param->d_scryptV2_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_scryptV2_buf); - if (device_param->d_scryptV3_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_scryptV3_buf); - if (device_param->d_root_css_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_root_css_buf); - if (device_param->d_markov_css_buf) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_markov_css_buf); - if (device_param->d_tm_c) CL_err |= hc_clReleaseMemObject (data.ocl, device_param->d_tm_c); + if (device_param->d_pws_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_pws_buf); + if (device_param->d_pws_amp_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_pws_amp_buf); + if (device_param->d_rules) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_rules); + if (device_param->d_rules_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_rules_c); + if (device_param->d_combs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_combs); + if (device_param->d_combs_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_combs_c); + if (device_param->d_bfs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bfs); + if (device_param->d_bfs_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bfs_c); + if (device_param->d_bitmap_s1_a) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_a); + if (device_param->d_bitmap_s1_b) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_b); + if (device_param->d_bitmap_s1_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_c); + if (device_param->d_bitmap_s1_d) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_d); + if (device_param->d_bitmap_s2_a) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_a); + if (device_param->d_bitmap_s2_b) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_b); + if (device_param->d_bitmap_s2_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_c); + if (device_param->d_bitmap_s2_d) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_d); + if (device_param->d_plain_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_plain_bufs); + if (device_param->d_digests_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_digests_buf); + if (device_param->d_digests_shown) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_digests_shown); + if (device_param->d_salt_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_salt_bufs); + if (device_param->d_esalt_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_esalt_bufs); + if (device_param->d_tmps) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_tmps); + if (device_param->d_hooks) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_hooks); + if (device_param->d_result) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_result); + if (device_param->d_scryptV0_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV0_buf); + if (device_param->d_scryptV1_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV1_buf); + if (device_param->d_scryptV2_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV2_buf); + if (device_param->d_scryptV3_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV3_buf); + if (device_param->d_root_css_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_root_css_buf); + if (device_param->d_markov_css_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_markov_css_buf); + if (device_param->d_tm_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_tm_c); if (CL_err != CL_SUCCESS) { @@ -9005,17 +7941,17 @@ int main (int argc, char **argv) return -1; } - if (device_param->kernel1) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel1); - if (device_param->kernel12) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel12); - if (device_param->kernel2) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel2); - if (device_param->kernel23) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel23); - if (device_param->kernel3) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel3); - if (device_param->kernel_mp) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_mp); - if (device_param->kernel_mp_l) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_mp_l); - if (device_param->kernel_mp_r) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_mp_r); - if (device_param->kernel_tm) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_tm); - if (device_param->kernel_amp) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_amp); - if (device_param->kernel_memset) CL_err |= hc_clReleaseKernel (data.ocl, device_param->kernel_memset); + if (device_param->kernel1) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel1); + if (device_param->kernel12) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel12); + if (device_param->kernel2) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel2); + if (device_param->kernel23) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel23); + if (device_param->kernel3) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel3); + if (device_param->kernel_mp) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp); + if (device_param->kernel_mp_l) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp_l); + if (device_param->kernel_mp_r) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp_r); + if (device_param->kernel_tm) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_tm); + if (device_param->kernel_amp) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_amp); + if (device_param->kernel_memset) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_memset); if (CL_err != CL_SUCCESS) { @@ -9024,9 +7960,9 @@ int main (int argc, char **argv) return -1; } - if (device_param->program) CL_err |= hc_clReleaseProgram (data.ocl, device_param->program); - if (device_param->program_mp) CL_err |= hc_clReleaseProgram (data.ocl, device_param->program_mp); - if (device_param->program_amp) CL_err |= hc_clReleaseProgram (data.ocl, device_param->program_amp); + if (device_param->program) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program); + if (device_param->program_mp) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program_mp); + if (device_param->program_amp) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program_amp); if (CL_err != CL_SUCCESS) { @@ -9035,7 +7971,7 @@ int main (int argc, char **argv) return -1; } - if (device_param->command_queue) CL_err |= hc_clReleaseCommandQueue (data.ocl, device_param->command_queue); + if (device_param->command_queue) CL_err |= hc_clReleaseCommandQueue (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -9044,7 +7980,7 @@ int main (int argc, char **argv) return -1; } - if (device_param->context) CL_err |= hc_clReleaseContext (data.ocl, device_param->context); + if (device_param->context) CL_err |= hc_clReleaseContext (opencl_ctx->ocl, device_param->context); if (CL_err != CL_SUCCESS) { @@ -9063,9 +7999,9 @@ int main (int argc, char **argv) { hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -9102,13 +8038,13 @@ int main (int argc, char **argv) { hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_device[device_id].od_version == 6) { @@ -9157,7 +8093,7 @@ int main (int argc, char **argv) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { unsigned int limit = nvml_power_limit[device_id]; @@ -9248,7 +8184,7 @@ int main (int argc, char **argv) local_free (nvml_power_limit); #endif - global_free (devices_param); + opencl_ctx_devices_destroy (opencl_ctx); global_free (kernel_rules_buf); @@ -9268,7 +8204,7 @@ int main (int argc, char **argv) global_free (words_progress_rejected); global_free (words_progress_restored); - if (data.devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; } // wait for outer threads @@ -9367,13 +8303,13 @@ int main (int argc, char **argv) if (quiet == 0) log_info_nn ("Started: %s", ctime (&proc_start)); if (quiet == 0) log_info_nn ("Stopped: %s", ctime (&proc_stop)); - if (data.ocl) ocl_close (data.ocl); + opencl_ctx_destroy (opencl_ctx); - if (data.devices_status == STATUS_ABORTED) return 2; - if (data.devices_status == STATUS_QUIT) return 2; - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) return 2; - if (data.devices_status == STATUS_EXHAUSTED) return 1; - if (data.devices_status == STATUS_CRACKED) return 0; + if (opencl_ctx->devices_status == STATUS_ABORTED) return 2; + if (opencl_ctx->devices_status == STATUS_QUIT) return 2; + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) return 2; + if (opencl_ctx->devices_status == STATUS_EXHAUSTED) return 1; + if (opencl_ctx->devices_status == STATUS_CRACKED) return 0; return -1; } diff --git a/src/hlfmt.c b/src/hlfmt.c index f54771ade..4dc3f4acb 100644 --- a/src/hlfmt.c +++ b/src/hlfmt.c @@ -19,15 +19,16 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "filehandling.h" #include "rp_cpu.h" #include "inc_hash_constants.h" #include "shared.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/hwmon.c b/src/hwmon.c index 5531ac4e8..b297f9332 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -15,11 +15,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "outfile.h" #include "potfile.h" @@ -413,11 +414,11 @@ int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, return num_adl_adapters; } -int hm_get_threshold_slowdown_with_device_id (const uint device_id) +int hm_get_threshold_slowdown_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -439,7 +440,7 @@ int hm_get_threshold_slowdown_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { int target = 0; @@ -451,11 +452,11 @@ int hm_get_threshold_slowdown_with_device_id (const uint device_id) return -1; } -int hm_get_threshold_shutdown_with_device_id (const uint device_id) +int hm_get_threshold_shutdown_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -470,7 +471,7 @@ int hm_get_threshold_shutdown_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { int target = 0; @@ -482,11 +483,11 @@ int hm_get_threshold_shutdown_with_device_id (const uint device_id) return -1; } -int hm_get_temperature_with_device_id (const uint device_id) +int hm_get_temperature_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -511,7 +512,7 @@ int hm_get_temperature_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { int temperature = 0; @@ -523,13 +524,13 @@ int hm_get_temperature_with_device_id (const uint device_id) return -1; } -int hm_get_fanpolicy_with_device_id (const uint device_id) +int hm_get_fanpolicy_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; if (data.hm_device[device_id].fan_get_supported == 1) { - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -553,7 +554,7 @@ int hm_get_fanpolicy_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { return 1; } @@ -562,13 +563,13 @@ int hm_get_fanpolicy_with_device_id (const uint device_id) return -1; } -int hm_get_fanspeed_with_device_id (const uint device_id) +int hm_get_fanspeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; if (data.hm_device[device_id].fan_get_supported == 1) { - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -599,7 +600,7 @@ int hm_get_fanspeed_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { int speed = 0; @@ -612,11 +613,11 @@ int hm_get_fanspeed_with_device_id (const uint device_id) return -1; } -int hm_get_buslanes_with_device_id (const uint device_id) +int hm_get_buslanes_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -630,7 +631,7 @@ int hm_get_buslanes_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { unsigned int currLinkWidth; @@ -642,11 +643,11 @@ int hm_get_buslanes_with_device_id (const uint device_id) return -1; } -int hm_get_utilization_with_device_id (const uint device_id) +int hm_get_utilization_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -660,7 +661,7 @@ int hm_get_utilization_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { nvmlUtilization_t utilization; @@ -672,11 +673,11 @@ int hm_get_utilization_with_device_id (const uint device_id) return -1; } -int hm_get_memoryspeed_with_device_id (const uint device_id) +int hm_get_memoryspeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -690,7 +691,7 @@ int hm_get_memoryspeed_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { unsigned int clock; @@ -702,11 +703,11 @@ int hm_get_memoryspeed_with_device_id (const uint device_id) return -1; } -int hm_get_corespeed_with_device_id (const uint device_id) +int hm_get_corespeed_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { if (data.hm_adl) { @@ -720,7 +721,7 @@ int hm_get_corespeed_with_device_id (const uint device_id) } } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { unsigned int clock; @@ -732,16 +733,16 @@ int hm_get_corespeed_with_device_id (const uint device_id) return -1; } -int hm_get_throttle_with_device_id (const uint device_id) +int hm_get_throttle_with_device_id (opencl_ctx_t *opencl_ctx, const uint device_id) { - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1; - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_AMD) { } - if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV) + if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { unsigned long long clocksThrottleReasons = 0; unsigned long long supportedThrottleReasons = 0; diff --git a/src/logfile.c b/src/logfile.c index e8a182380..7c6e2d874 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -19,10 +19,11 @@ #include "ext_xnvctrl.h" #include "types.h" #include "memory.h" -#include "hwmon.h" #include "rp_cpu.h" #include "mpsp.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" #include "restore.h" #include "outfile.h" #include "potfile.h" diff --git a/src/monitor.c b/src/monitor.c index 5062c111b..30695cea1 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -15,11 +15,13 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" +#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -28,8 +30,6 @@ #include "status.h" #include "shared.h" #include "terminal.h" -#include "hwmon.h" -#include "thread.h" #include "monitor.h" #include "hash_management.h" @@ -49,6 +49,8 @@ void *thread_monitor (void *p) uint remove_left = data.remove_timer; uint status_left = data.status_timer; + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + #if defined (HAVE_HWMON) uint hwmon_check = 0; @@ -56,12 +58,12 @@ void *thread_monitor (void *p) // these variables are mainly used for fan control - int *fan_speed_chgd = (int *) mycalloc (data.devices_cnt, sizeof (int)); + int *fan_speed_chgd = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); // temperature controller "loopback" values - int *temp_diff_old = (int *) mycalloc (data.devices_cnt, sizeof (int)); - int *temp_diff_sum = (int *) mycalloc (data.devices_cnt, sizeof (int)); + int *temp_diff_old = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); + int *temp_diff_sum = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); int temp_threshold = 1; // degrees celcius @@ -114,7 +116,7 @@ void *thread_monitor (void *p) { hc_sleep (sleep_time); - if (data.devices_status != STATUS_RUNNING) continue; + if (opencl_ctx->devices_status != STATUS_RUNNING) continue; #if defined (HAVE_HWMON) @@ -122,9 +124,9 @@ void *thread_monitor (void *p) { hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -188,21 +190,21 @@ void *thread_monitor (void *p) if (Ta == 0) Ta = 1; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; - if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) continue; + if ((opencl_ctx->devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) continue; - const int temperature = hm_get_temperature_with_device_id (device_id); + const int temperature = hm_get_temperature_with_device_id (opencl_ctx, device_id); if (temperature > (int) data.gpu_temp_abort) { log_error ("ERROR: Temperature limit on GPU %d reached, aborting...", device_id + 1); - if (data.devices_status != STATUS_QUIT) myabort (); + if (opencl_ctx->devices_status != STATUS_QUIT) myabort (opencl_ctx); break; } @@ -233,7 +235,7 @@ void *thread_monitor (void *p) if (abs (fan_diff_required) >= temp_threshold) { - const int fan_speed_cur = hm_get_fanspeed_with_device_id (device_id); + const int fan_speed_cur = hm_get_fanspeed_with_device_id (opencl_ctx, device_id); int fan_speed_level = fan_speed_cur; @@ -286,7 +288,7 @@ void *thread_monitor (void *p) if (restore_left == 0) { - if (data.restore_disable == 0) cycle_restore (); + if (data.restore_disable == 0) cycle_restore (opencl_ctx); restore_left = data.restore_timer; } @@ -296,7 +298,7 @@ void *thread_monitor (void *p) { double ms_paused = data.ms_paused; - if (data.devices_status == STATUS_PAUSED) + if (opencl_ctx->devices_status == STATUS_PAUSED) { double ms_paused_tmp = 0; @@ -318,7 +320,7 @@ void *thread_monitor (void *p) if (data.quiet == 0) log_info ("\nNOTE: Runtime limit reached, aborting...\n"); } - if (data.devices_status != STATUS_QUIT) myabort (); + if (opencl_ctx->devices_status != STATUS_QUIT) myabort (opencl_ctx); } } @@ -351,7 +353,7 @@ void *thread_monitor (void *p) if (data.quiet == 0) log_info (""); - status_display (); + status_display (opencl_ctx); if (data.quiet == 0) log_info (""); diff --git a/src/mpsp.c b/src/mpsp.c index cb36d8bcf..ade9ec3ce 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -21,18 +21,18 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "filehandling.h" +#include "tuningdb.h" #include "opencl.h" -#include "thread.h" #include "hwmon.h" +#include "restore.h" +#include "thread.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" #include "loopback.h" #include "data.h" -//#include "shared.h" extern hc_global_data_t data; diff --git a/src/opencl.c b/src/opencl.c index da42c0509..2b5838a7f 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -6,41 +6,45 @@ #include "common.h" #include "types_int.h" #include "types.h" -#include "interface.h" -#include "convert.h" +#include "timer.h" #include "memory.h" #include "logging.h" #include "locking.h" -#include "ext_OpenCL.h" #include "ext_ADL.h" #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "rp_cpu.h" -#include "timer.h" +#include "ext_OpenCL.h" +#include "cpu_md5.h" +#include "interface.h" +#include "tuningdb.h" #include "opencl.h" -#include "shared.h" #include "hwmon.h" -#include "mpsp.h" +#include "restore.h" +#include "thread.h" #include "status.h" #include "stdout.h" -#include "restore.h" +#include "mpsp.h" +#include "rp_cpu.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" #include "loopback.h" -#include "thread.h" +#include "data.h" +#include "shared.h" +#include "filehandling.h" +#include "convert.h" #include "dictstat.h" #include "wordlist.h" -#include "filehandling.h" #include "hash_management.h" -#include "data.h" extern hc_global_data_t data; extern hc_thread_mutex_t mux_counter; -uint setup_opencl_platforms_filter (char *opencl_platforms) +extern const int comptime; + +static uint setup_opencl_platforms_filter (const char *opencl_platforms) { uint opencl_platforms_filter = 0; @@ -75,7 +79,7 @@ uint setup_opencl_platforms_filter (char *opencl_platforms) return opencl_platforms_filter; } -u32 setup_devices_filter (char *opencl_devices) +static u32 setup_devices_filter (const char *opencl_devices) { u32 devices_filter = 0; @@ -110,7 +114,7 @@ u32 setup_devices_filter (char *opencl_devices) return devices_filter; } -cl_device_type setup_device_types_filter (char *opencl_device_types) +static cl_device_type setup_device_types_filter (const char *opencl_device_types) { cl_device_type device_types_filter = 0; @@ -206,9 +210,9 @@ void writeProgramBin (char *dst, u8 *binary, size_t binary_size) } } -int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw) +int gidd_to_pw_t (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw) { - cl_int CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -220,13 +224,13 @@ int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw) return 0; } -int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration) +int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint attack_exec, const uint attack_mode, const uint opts_type, const salt_t *salt_buf, const uint highest_pw_len, const uint pws_cnt, const uint fast_iteration) { cl_int CL_err = CL_SUCCESS; if (hashconfig->hash_mode == 2000) { - process_stdout (device_param, pws_cnt); + process_stdout (opencl_ctx, device_param, pws_cnt); return 0; } @@ -239,11 +243,11 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co { const uint size_tm = 32 * sizeof (bs_word_t); - run_kernel_bzero (device_param, device_param->d_tm_c, size_tm); + run_kernel_bzero (opencl_ctx, device_param, device_param->d_tm_c, size_tm); - run_kernel_tm (device_param); + run_kernel_tm (opencl_ctx, device_param); - CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_tm_c, device_param->d_bfs_c, 0, 0, size_tm, 0, NULL, NULL); + CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_tm_c, device_param->d_bfs_c, 0, 0, size_tm, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -256,28 +260,28 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co if (highest_pw_len < 16) { - run_kernel (KERN_RUN_1, device_param, pws_cnt, true, fast_iteration, hashconfig); + run_kernel (KERN_RUN_1, opencl_ctx, device_param, pws_cnt, true, fast_iteration, hashconfig); } else if (highest_pw_len < 32) { - run_kernel (KERN_RUN_2, device_param, pws_cnt, true, fast_iteration, hashconfig); + run_kernel (KERN_RUN_2, opencl_ctx, device_param, pws_cnt, true, fast_iteration, hashconfig); } else { - run_kernel (KERN_RUN_3, device_param, pws_cnt, true, fast_iteration, hashconfig); + run_kernel (KERN_RUN_3, opencl_ctx, device_param, pws_cnt, true, fast_iteration, hashconfig); } } else { - run_kernel_amp (device_param, pws_cnt); + run_kernel_amp (opencl_ctx, device_param, pws_cnt); - run_kernel (KERN_RUN_1, device_param, pws_cnt, false, 0, hashconfig); + run_kernel (KERN_RUN_1, opencl_ctx, device_param, pws_cnt, false, 0, hashconfig); if (opts_type & OPTS_TYPE_HOOK12) { - run_kernel (KERN_RUN_12, device_param, pws_cnt, false, 0, hashconfig); + run_kernel (KERN_RUN_12, opencl_ctx, device_param, pws_cnt, false, 0, hashconfig); - CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -288,7 +292,7 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co // do something with data - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -311,12 +315,12 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co device_param->kernel_params_buf32[28] = loop_pos; device_param->kernel_params_buf32[29] = loop_left; - run_kernel (KERN_RUN_2, device_param, pws_cnt, true, slow_iteration, hashconfig); + run_kernel (KERN_RUN_2, opencl_ctx, device_param, pws_cnt, true, slow_iteration, hashconfig); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; /** * speed @@ -338,15 +342,15 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co if (data.benchmark == 1) { - if (speed_ms > 4096) data.devices_status = STATUS_ABORTED; + if (speed_ms > 4096) opencl_ctx->devices_status = STATUS_ABORTED; } } if (opts_type & OPTS_TYPE_HOOK23) { - run_kernel (KERN_RUN_23, device_param, pws_cnt, false, 0, hashconfig); + run_kernel (KERN_RUN_23, opencl_ctx, device_param, pws_cnt, false, 0, hashconfig); - CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -357,7 +361,7 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co // do something with data - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -367,13 +371,13 @@ int choose_kernel (hc_device_param_t *device_param, hashconfig_t *hashconfig, co } } - run_kernel (KERN_RUN_3, device_param, pws_cnt, false, 0, hashconfig); + run_kernel (KERN_RUN_3, opencl_ctx, device_param, pws_cnt, false, 0, hashconfig); } return 0; } -int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint num, const uint event_update, const uint iteration, hashconfig_t *hashconfig) +int run_kernel (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num, const uint event_update, const uint iteration, hashconfig_t *hashconfig) { cl_int CL_err = CL_SUCCESS; @@ -397,17 +401,17 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint case KERN_RUN_3: kernel = device_param->kernel3; break; } - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); if (CL_err != CL_SUCCESS) { @@ -423,7 +427,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint const size_t global_work_size[3] = { num_elements, 32, 1 }; const size_t local_work_size[3] = { kernel_threads / 32, 32, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, &event); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, &event); if (CL_err != CL_SUCCESS) { @@ -447,7 +451,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, &event); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, &event); if (CL_err != CL_SUCCESS) { @@ -457,7 +461,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint } } - CL_err = hc_clFlush (data.ocl, device_param->command_queue); + CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -468,7 +472,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint if (device_param->nvidia_spin_damp > 0) { - if (data.devices_status == STATUS_RUNNING) + if (opencl_ctx->devices_status == STATUS_RUNNING) { if (iteration < EXPECTED_ITERATIONS) { @@ -482,7 +486,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint } } - CL_err = hc_clWaitForEvents (data.ocl, 1, &event); + CL_err = hc_clWaitForEvents (opencl_ctx->ocl, 1, &event); if (CL_err != CL_SUCCESS) { @@ -494,8 +498,8 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint cl_ulong time_start; cl_ulong time_end; - CL_err |= hc_clGetEventProfilingInfo (data.ocl, event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL); - CL_err |= hc_clGetEventProfilingInfo (data.ocl, event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL); + CL_err |= hc_clGetEventProfilingInfo (opencl_ctx->ocl, event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL); + CL_err |= hc_clGetEventProfilingInfo (opencl_ctx->ocl, event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL); if (CL_err != CL_SUCCESS) { @@ -506,7 +510,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint const double exec_us = (double) (time_end - time_start) / 1000; - if (data.devices_status == STATUS_RUNNING) + if (opencl_ctx->devices_status == STATUS_RUNNING) { if (iteration < EXPECTED_ITERATIONS) { @@ -535,7 +539,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint device_param->exec_pos = exec_pos; } - CL_err = hc_clReleaseEvent (data.ocl, event); + CL_err = hc_clReleaseEvent (opencl_ctx->ocl, event); if (CL_err != CL_SUCCESS) { @@ -544,7 +548,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint return -1; } - CL_err = hc_clFinish (data.ocl, device_param->command_queue); + CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -556,7 +560,7 @@ int run_kernel (const uint kern_run, hc_device_param_t *device_param, const uint return 0; } -int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const uint num) +int run_kernel_mp (const uint kern_run, opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num) { cl_int CL_err = CL_SUCCESS; @@ -587,27 +591,27 @@ int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const u switch (kern_run) { - case KERN_RUN_MP: CL_err |= hc_clSetKernelArg (data.ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp[8]); + case KERN_RUN_MP: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp[8]); break; - case KERN_RUN_MP_R: CL_err |= hc_clSetKernelArg (data.ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_r[8]); + case KERN_RUN_MP_R: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_r[8]); break; - case KERN_RUN_MP_L: CL_err |= hc_clSetKernelArg (data.ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 9, sizeof (cl_uint), device_param->kernel_params_mp_l[9]); + case KERN_RUN_MP_L: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 9, sizeof (cl_uint), device_param->kernel_params_mp_l[9]); break; } @@ -621,7 +625,7 @@ int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const u const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -630,7 +634,7 @@ int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const u return -1; } - CL_err = hc_clFlush (data.ocl, device_param->command_queue); + CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -639,7 +643,7 @@ int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const u return -1; } - CL_err = hc_clFinish (data.ocl, device_param->command_queue); + CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -651,7 +655,7 @@ int run_kernel_mp (const uint kern_run, hc_device_param_t *device_param, const u return 0; } -int run_kernel_tm (hc_device_param_t *device_param) +int run_kernel_tm (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param) { cl_int CL_err = CL_SUCCESS; @@ -664,7 +668,7 @@ int run_kernel_tm (hc_device_param_t *device_param) const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -673,7 +677,7 @@ int run_kernel_tm (hc_device_param_t *device_param) return -1; } - CL_err = hc_clFlush (data.ocl, device_param->command_queue); + CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -682,7 +686,7 @@ int run_kernel_tm (hc_device_param_t *device_param) return -1; } - CL_err = hc_clFinish (data.ocl, device_param->command_queue); + CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -694,7 +698,7 @@ int run_kernel_tm (hc_device_param_t *device_param) return 0; } -int run_kernel_amp (hc_device_param_t *device_param, const uint num) +int run_kernel_amp (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint num) { cl_int CL_err = CL_SUCCESS; @@ -712,8 +716,8 @@ int run_kernel_amp (hc_device_param_t *device_param, const uint num) cl_kernel kernel = device_param->kernel_amp; - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_amp[6]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_amp[6]); if (CL_err != CL_SUCCESS) { @@ -725,7 +729,7 @@ int run_kernel_amp (hc_device_param_t *device_param, const uint num) const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -734,7 +738,7 @@ int run_kernel_amp (hc_device_param_t *device_param, const uint num) return -1; } - CL_err = hc_clFlush (data.ocl, device_param->command_queue); + CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -743,7 +747,7 @@ int run_kernel_amp (hc_device_param_t *device_param, const uint num) return -1; } - CL_err = hc_clFinish (data.ocl, device_param->command_queue); + CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -755,7 +759,7 @@ int run_kernel_amp (hc_device_param_t *device_param, const uint num) return 0; } -int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint value, const uint num) +int run_kernel_memset (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cl_mem buf, const uint value, const uint num) { cl_int CL_err = CL_SUCCESS; @@ -775,9 +779,9 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v cl_kernel kernel = device_param->kernel_memset; - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 0, sizeof (cl_mem), (void *) &buf); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); - CL_err |= hc_clSetKernelArg (data.ocl, kernel, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 0, sizeof (cl_mem), (void *) &buf); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); + CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); if (CL_err != CL_SUCCESS) { @@ -789,7 +793,7 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (data.ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -798,7 +802,7 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v return -1; } - CL_err = hc_clFlush (data.ocl, device_param->command_queue); + CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -807,7 +811,7 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v return -1; } - CL_err = hc_clFinish (data.ocl, device_param->command_queue); + CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); if (CL_err != CL_SUCCESS) { @@ -826,7 +830,7 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v tmp[2] = value; tmp[3] = value; - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, buf, CL_TRUE, num16d * 16, num16m, tmp, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, buf, CL_TRUE, num16d * 16, num16m, tmp, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -839,18 +843,18 @@ int run_kernel_memset (hc_device_param_t *device_param, cl_mem buf, const uint v return 0; } -int run_kernel_bzero (hc_device_param_t *device_param, cl_mem buf, const size_t size) +int run_kernel_bzero (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, cl_mem buf, const size_t size) { - return run_kernel_memset (device_param, buf, 0, size); + return run_kernel_memset (opencl_ctx, device_param, buf, 0, size); } -int run_copy (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt) +int run_copy (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt) { cl_int CL_err = CL_SUCCESS; if (data.attack_kern == ATTACK_KERN_STRAIGHT) { - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -915,7 +919,7 @@ int run_copy (hc_device_param_t *device_param, hashconfig_t *hashconfig, const u } } - CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -930,13 +934,13 @@ int run_copy (hc_device_param_t *device_param, hashconfig_t *hashconfig, const u device_param->kernel_params_mp_l_buf64[3] = off; - run_kernel_mp (KERN_RUN_MP_L, device_param, pws_cnt); + run_kernel_mp (KERN_RUN_MP_L, opencl_ctx, device_param, pws_cnt); } return 0; } -int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt) +int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint pws_cnt) { char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); @@ -980,7 +984,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons uint innerloop_cnt = 0; if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) innerloop_step = device_param->kernel_loops; - else innerloop_step = 1; + else innerloop_step = 1; if (data.attack_kern == ATTACK_KERN_STRAIGHT) innerloop_cnt = data.kernel_rules_cnt; else if (data.attack_kern == ATTACK_KERN_COMBI) innerloop_cnt = data.combs_cnt; @@ -990,14 +994,14 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons for (uint salt_pos = 0; salt_pos < data.salts_cnt; salt_pos++) { - while (data.devices_status == STATUS_PAUSED) hc_sleep (1); + while (opencl_ctx->devices_status == STATUS_PAUSED) hc_sleep (1); - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; salt_t *salt_buf = &data.salts_buf[salt_pos]; @@ -1016,14 +1020,14 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons for (uint innerloop_pos = 0; innerloop_pos < innerloop_cnt; innerloop_pos += innerloop_step) { - while (data.devices_status == STATUS_PAUSED) hc_sleep (1); + while (opencl_ctx->devices_status == STATUS_PAUSED) hc_sleep (1); - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; uint fast_iteration = 0; @@ -1145,7 +1149,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons device_param->kernel_params_mp_r_buf64[3] = off; - run_kernel_mp (KERN_RUN_MP_R, device_param, innerloop_left); + run_kernel_mp (KERN_RUN_MP_R, opencl_ctx, device_param, innerloop_left); } else if (data.attack_mode == ATTACK_MODE_HYBRID1) { @@ -1153,7 +1157,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons device_param->kernel_params_mp_buf64[3] = off; - run_kernel_mp (KERN_RUN_MP, device_param, innerloop_left); + run_kernel_mp (KERN_RUN_MP, opencl_ctx, device_param, innerloop_left); } else if (data.attack_mode == ATTACK_MODE_HYBRID2) { @@ -1161,14 +1165,14 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons device_param->kernel_params_mp_buf64[3] = off; - run_kernel_mp (KERN_RUN_MP, device_param, innerloop_left); + run_kernel_mp (KERN_RUN_MP, opencl_ctx, device_param, innerloop_left); } // copy amplifiers if (data.attack_mode == ATTACK_MODE_STRAIGHT) { - cl_int CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, innerloop_pos * sizeof (kernel_rule_t), 0, innerloop_left * sizeof (kernel_rule_t), 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, innerloop_pos * sizeof (kernel_rule_t), 0, innerloop_left * sizeof (kernel_rule_t), 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -1179,7 +1183,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons } else if (data.attack_mode == ATTACK_MODE_COMBI) { - cl_int CL_err = hc_clEnqueueWriteBuffer (data.ocl, device_param->command_queue, device_param->d_combs_c, CL_TRUE, 0, innerloop_left * sizeof (comb_t), device_param->combs_buf, 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs_c, CL_TRUE, 0, innerloop_left * sizeof (comb_t), device_param->combs_buf, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -1190,7 +1194,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons } else if (data.attack_mode == ATTACK_MODE_BF) { - cl_int CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_bfs, device_param->d_bfs_c, 0, 0, innerloop_left * sizeof (bf_t), 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bfs, device_param->d_bfs_c, 0, 0, innerloop_left * sizeof (bf_t), 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -1201,7 +1205,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons } else if (data.attack_mode == ATTACK_MODE_HYBRID1) { - cl_int CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -1212,7 +1216,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons } else if (data.attack_mode == ATTACK_MODE_HYBRID2) { - cl_int CL_err = hc_clEnqueueCopyBuffer (data.ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); + cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); if (CL_err != CL_SUCCESS) { @@ -1227,16 +1231,16 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons hc_timer_set (&device_param->timer_speed); } - int rc = choose_kernel (device_param, hashconfig, hashconfig->attack_exec, data.attack_mode, hashconfig->opts_type, salt_buf, highest_pw_len, pws_cnt, fast_iteration); + int rc = choose_kernel (opencl_ctx, device_param, hashconfig, hashconfig->attack_exec, data.attack_mode, hashconfig->opts_type, salt_buf, highest_pw_len, pws_cnt, fast_iteration); if (rc == -1) return -1; - if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (opencl_ctx->devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (opencl_ctx); - if (data.devices_status == STATUS_CRACKED) break; - if (data.devices_status == STATUS_ABORTED) break; - if (data.devices_status == STATUS_QUIT) break; - if (data.devices_status == STATUS_BYPASS) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_ABORTED) break; + if (opencl_ctx->devices_status == STATUS_QUIT) break; + if (opencl_ctx->devices_status == STATUS_BYPASS) break; /** * result @@ -1244,7 +1248,7 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons if (data.benchmark == 0) { - check_cracked (device_param, salt_pos, hashconfig); + check_cracked (opencl_ctx, device_param, salt_pos, hashconfig); } /** @@ -1300,3 +1304,1149 @@ int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfig, cons return 0; } + +int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, const char *opencl_devices, const char *opencl_device_types, const uint opencl_vector_width, const uint opencl_vector_width_chgd, const uint nvidia_spin_damp, const uint nvidia_spin_damp_chgd, const uint workload_profile, const uint kernel_accel, const uint kernel_accel_chgd, const uint kernel_loops, const uint kernel_loops_chgd, const uint keyspace, const uint stdout_flag) +{ + if (keyspace == 1) + { + opencl_ctx->disable = 1; + + return 0; + } + + opencl_ctx->opencl_vector_width_chgd = opencl_vector_width_chgd; + opencl_ctx->opencl_vector_width = opencl_vector_width; + opencl_ctx->nvidia_spin_damp_chgd = nvidia_spin_damp_chgd; + opencl_ctx->nvidia_spin_damp = nvidia_spin_damp; + opencl_ctx->kernel_accel_chgd = kernel_accel_chgd; + opencl_ctx->kernel_accel = kernel_accel; + opencl_ctx->kernel_loops_chgd = kernel_loops_chgd; + opencl_ctx->kernel_loops = kernel_loops; + opencl_ctx->workload_profile = workload_profile; + + opencl_ctx->ocl = (OCL_PTR *) mymalloc (sizeof (OCL_PTR)); + + hc_device_param_t *devices_param = (hc_device_param_t *) mycalloc (DEVICES_MAX, sizeof (hc_device_param_t)); + + opencl_ctx->devices_param = devices_param; + + /** + * Load and map OpenCL library calls + * TODO: remove exit() calls in there + */ + + ocl_init (opencl_ctx->ocl); + + /** + * OpenCL platform selection + */ + + u32 opencl_platforms_filter = setup_opencl_platforms_filter (opencl_platforms); + + opencl_ctx->opencl_platforms_filter = opencl_platforms_filter; + + /** + * OpenCL device selection + */ + + u32 devices_filter = setup_devices_filter (opencl_devices); + + opencl_ctx->devices_filter = devices_filter; + + /** + * OpenCL device type selection + */ + + cl_device_type device_types_filter = setup_device_types_filter (opencl_device_types); + + opencl_ctx->device_types_filter = device_types_filter; + + /** + * OpenCL platforms: detect + */ + + cl_uint platforms_cnt = 0; + cl_platform_id *platforms = (cl_platform_id *) mycalloc (CL_PLATFORMS_MAX, sizeof (cl_platform_id)); + cl_uint platform_devices_cnt = 0; + cl_device_id *platform_devices = (cl_device_id *) mycalloc (DEVICES_MAX, sizeof (cl_device_id)); + + cl_int CL_err = hc_clGetPlatformIDs (opencl_ctx->ocl, CL_PLATFORMS_MAX, platforms, &platforms_cnt); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetPlatformIDs(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (platforms_cnt == 0) + { + log_info (""); + log_info ("ATTENTION! No OpenCL compatible platform found"); + log_info (""); + log_info ("You're probably missing the OpenCL runtime installation"); + log_info (" AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); + log_info (" Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); + log_info (" NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); + log_info (""); + + return -1; + } + + if (opencl_platforms_filter != (uint) -1) + { + uint platform_cnt_mask = ~(((uint) -1 >> platforms_cnt) << platforms_cnt); + + if (opencl_platforms_filter > platform_cnt_mask) + { + log_error ("ERROR: The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%d)", platforms_cnt); + + return -1; + } + } + + if (opencl_device_types == NULL) + { + /** + * OpenCL device types: + * In case the user did not specify --opencl-device-types and the user runs hashcat in a system with only a CPU only he probably want to use that CPU. + */ + + cl_device_type device_types_all = 0; + + for (uint platform_id = 0; platform_id < platforms_cnt; platform_id++) + { + if ((opencl_platforms_filter & (1u << platform_id)) == 0) continue; + + cl_platform_id platform = platforms[platform_id]; + + cl_int CL_err = hc_clGetDeviceIDs (opencl_ctx->ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); + + if (CL_err != CL_SUCCESS) + { + //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); + + //return -1; + + // Silently ignore at this point, it will be reused later and create a note for the user at that point + + continue; + } + + for (uint platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) + { + cl_device_id device = platform_devices[platform_devices_id]; + + cl_device_type device_type; + + cl_int CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_types_all |= device_type; + } + } + + // In such a case, automatically enable CPU device type support, since it's disabled by default. + + if ((device_types_all & (CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR)) == 0) + { + device_types_filter |= CL_DEVICE_TYPE_CPU; + } + + // In another case, when the user uses --stdout, using CPU devices is much faster to setup + // If we have a CPU device, force it to be used + + if (stdout_flag == 1) + { + if (device_types_all & CL_DEVICE_TYPE_CPU) + { + device_types_filter = CL_DEVICE_TYPE_CPU; + } + } + } + + opencl_ctx->platforms_cnt = platforms_cnt; + opencl_ctx->platforms = platforms; + opencl_ctx->platform_devices_cnt = platform_devices_cnt; + opencl_ctx->platform_devices = platform_devices; + + return 0; +} + +void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) +{ + if (opencl_ctx->disable == 1) return; + + myfree (opencl_ctx->devices_param); + + ocl_close (opencl_ctx->ocl); + + myfree (opencl_ctx->ocl); + + myfree (opencl_ctx->platforms); + + myfree (opencl_ctx->platform_devices); + + myfree (opencl_ctx); +} + +int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const uint attack_mode, const uint quiet, const uint force, const uint benchmark, const uint machine_readable, const uint algorithm_pos) +{ + if (opencl_ctx->disable == 1) return 0; + + /** + * OpenCL devices: simply push all devices from all platforms into the same device array + */ + + cl_uint platforms_cnt = opencl_ctx->platforms_cnt; + cl_platform_id *platforms = opencl_ctx->platforms; + cl_uint platform_devices_cnt = opencl_ctx->platform_devices_cnt; + cl_device_id *platform_devices = opencl_ctx->platform_devices; + + int need_adl = 0; + int need_nvml = 0; + int need_nvapi = 0; + int need_xnvctrl = 0; + + u32 devices_cnt = 0; + + u32 devices_active = 0; + + for (uint platform_id = 0; platform_id < platforms_cnt; platform_id++) + { + cl_int CL_err = CL_SUCCESS; + + cl_platform_id platform = platforms[platform_id]; + + char platform_vendor[HCBUFSIZ_TINY] = { 0 }; + + CL_err = hc_clGetPlatformInfo (opencl_ctx->ocl, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + // find our own platform vendor because pocl and mesa are pushing original vendor_id through opencl + // this causes trouble with vendor id based macros + // we'll assign generic to those without special optimization available + + cl_uint platform_vendor_id = 0; + + if (strcmp (platform_vendor, CL_VENDOR_AMD) == 0) + { + platform_vendor_id = VENDOR_ID_AMD; + } + else if (strcmp (platform_vendor, CL_VENDOR_AMD_USE_INTEL) == 0) + { + platform_vendor_id = VENDOR_ID_AMD_USE_INTEL; + } + else if (strcmp (platform_vendor, CL_VENDOR_APPLE) == 0) + { + platform_vendor_id = VENDOR_ID_APPLE; + } + else if (strcmp (platform_vendor, CL_VENDOR_INTEL_BEIGNET) == 0) + { + platform_vendor_id = VENDOR_ID_INTEL_BEIGNET; + } + else if (strcmp (platform_vendor, CL_VENDOR_INTEL_SDK) == 0) + { + platform_vendor_id = VENDOR_ID_INTEL_SDK; + } + else if (strcmp (platform_vendor, CL_VENDOR_MESA) == 0) + { + platform_vendor_id = VENDOR_ID_MESA; + } + else if (strcmp (platform_vendor, CL_VENDOR_NV) == 0) + { + platform_vendor_id = VENDOR_ID_NV; + } + else if (strcmp (platform_vendor, CL_VENDOR_POCL) == 0) + { + platform_vendor_id = VENDOR_ID_POCL; + } + else + { + platform_vendor_id = VENDOR_ID_GENERIC; + } + + uint platform_skipped = ((opencl_ctx->opencl_platforms_filter & (1u << platform_id)) == 0); + + CL_err = hc_clGetDeviceIDs (opencl_ctx->ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); + + if (CL_err != CL_SUCCESS) + { + //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); + + //return -1; + + platform_skipped = 2; + } + + if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + { + if (machine_readable == 0) + { + if (platform_skipped == 0) + { + const int len = log_info ("OpenCL Platform #%u: %s", platform_id + 1, platform_vendor); + + char line[256] = { 0 }; + + for (int i = 0; i < len; i++) line[i] = '='; + + log_info (line); + } + else if (platform_skipped == 1) + { + log_info ("OpenCL Platform #%u: %s, skipped", platform_id + 1, platform_vendor); + log_info (""); + } + else if (platform_skipped == 2) + { + log_info ("OpenCL Platform #%u: %s, skipped! No OpenCL compatible devices found", platform_id + 1, platform_vendor); + log_info (""); + } + } + } + + if (platform_skipped == 1) continue; + if (platform_skipped == 2) continue; + + hc_device_param_t *devices_param = opencl_ctx->devices_param; + + for (uint platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) + { + size_t param_value_size = 0; + + const uint device_id = devices_cnt; + + hc_device_param_t *device_param = &devices_param[device_id]; + + device_param->platform_vendor_id = platform_vendor_id; + + device_param->device = platform_devices[platform_devices_id]; + + device_param->device_id = device_id; + + device_param->platform_devices_id = platform_devices_id; + + device_param->platform = platform; + + // device_type + + cl_device_type device_type; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_type &= ~CL_DEVICE_TYPE_DEFAULT; + + device_param->device_type = device_type; + + // device_name + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *device_name = (char *) mymalloc (param_value_size); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_name = device_name; + + // device_vendor + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *device_vendor = (char *) mymalloc (param_value_size); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_vendor = device_vendor; + + cl_uint device_vendor_id = 0; + + if (strcmp (device_vendor, CL_VENDOR_AMD) == 0) + { + device_vendor_id = VENDOR_ID_AMD; + } + else if (strcmp (device_vendor, CL_VENDOR_AMD_USE_INTEL) == 0) + { + device_vendor_id = VENDOR_ID_AMD_USE_INTEL; + } + else if (strcmp (device_vendor, CL_VENDOR_APPLE) == 0) + { + device_vendor_id = VENDOR_ID_APPLE; + } + else if (strcmp (device_vendor, CL_VENDOR_INTEL_BEIGNET) == 0) + { + device_vendor_id = VENDOR_ID_INTEL_BEIGNET; + } + else if (strcmp (device_vendor, CL_VENDOR_INTEL_SDK) == 0) + { + device_vendor_id = VENDOR_ID_INTEL_SDK; + } + else if (strcmp (device_vendor, CL_VENDOR_MESA) == 0) + { + device_vendor_id = VENDOR_ID_MESA; + } + else if (strcmp (device_vendor, CL_VENDOR_NV) == 0) + { + device_vendor_id = VENDOR_ID_NV; + } + else if (strcmp (device_vendor, CL_VENDOR_POCL) == 0) + { + device_vendor_id = VENDOR_ID_POCL; + } + else + { + device_vendor_id = VENDOR_ID_GENERIC; + } + + device_param->device_vendor_id = device_vendor_id; + + // device_version + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *device_version = (char *) mymalloc (param_value_size); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_version = device_version; + + // device_opencl_version + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *device_opencl_version = (char *) mymalloc (param_value_size); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, device_opencl_version, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->opencl_v12 = device_opencl_version[9] > '1' || device_opencl_version[11] >= '2'; + + myfree (device_opencl_version); + + // vector_width + + cl_uint vector_width; + + if (opencl_ctx->opencl_vector_width_chgd == 0) + { + // tuning db + + tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, attack_mode, hashconfig->hash_mode); + + if (tuningdb_entry == NULL || tuningdb_entry->vector_width == -1) + { + if (hashconfig->opti_type & OPTI_TYPE_USES_BITS_64) + { + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + } + else + { + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + } + } + else + { + vector_width = (cl_uint) tuningdb_entry->vector_width; + } + } + else + { + vector_width = opencl_ctx->opencl_vector_width; + } + + if (vector_width > 16) vector_width = 16; + + device_param->vector_width = vector_width; + + // max_compute_units + + cl_uint device_processors; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_processors = device_processors; + + // device_maxmem_alloc + // note we'll limit to 2gb, otherwise this causes all kinds of weird errors because of possible integer overflows in opencl runtimes + + cl_ulong device_maxmem_alloc; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_maxmem_alloc = MIN (device_maxmem_alloc, 0x7fffffff); + + // device_global_mem + + cl_ulong device_global_mem; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_global_mem = device_global_mem; + + // max_work_group_size + + size_t device_maxworkgroup_size; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_maxworkgroup_size = device_maxworkgroup_size; + + // max_clock_frequency + + cl_uint device_maxclock_frequency; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->device_maxclock_frequency = device_maxclock_frequency; + + // device_endian_little + + cl_bool device_endian_little; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (device_endian_little == CL_FALSE) + { + log_info ("- Device #%u: WARNING: Not a little endian device", device_id + 1); + + device_param->skipped = 1; + } + + // device_available + + cl_bool device_available; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (device_available == CL_FALSE) + { + log_info ("- Device #%u: WARNING: Device not available", device_id + 1); + + device_param->skipped = 1; + } + + // device_compiler_available + + cl_bool device_compiler_available; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (device_compiler_available == CL_FALSE) + { + log_info ("- Device #%u: WARNING: No compiler available for device", device_id + 1); + + device_param->skipped = 1; + } + + // device_execution_capabilities + + cl_device_exec_capabilities device_execution_capabilities; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if ((device_execution_capabilities & CL_EXEC_KERNEL) == 0) + { + log_info ("- Device #%u: WARNING: Device does not support executing kernels", device_id + 1); + + device_param->skipped = 1; + } + + // device_extensions + + size_t device_extensions_size; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *device_extensions = mymalloc (device_extensions_size + 1); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (strstr (device_extensions, "base_atomics") == 0) + { + log_info ("- Device #%u: WARNING: Device does not support base atomics", device_id + 1); + + device_param->skipped = 1; + } + + if (strstr (device_extensions, "byte_addressable_store") == 0) + { + log_info ("- Device #%u: WARNING: Device does not support byte addressable store", device_id + 1); + + device_param->skipped = 1; + } + + myfree (device_extensions); + + // device_local_mem_size + + cl_ulong device_local_mem_size; + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + if (device_local_mem_size < 32768) + { + log_info ("- Device #%u: WARNING: Device local mem size is too small", device_id + 1); + + device_param->skipped = 1; + } + + // If there's both an Intel CPU and an AMD OpenCL runtime it's a tricky situation + // Both platforms support CPU device types and therefore both will try to use 100% of the physical resources + // This results in both utilizing it for 50% + // However, Intel has much better SIMD control over their own hardware + // It makes sense to give them full control over their own hardware + + if (device_type & CL_DEVICE_TYPE_CPU) + { + if (device_param->device_vendor_id == VENDOR_ID_AMD_USE_INTEL) + { + if (force == 0) + { + if (algorithm_pos == 0) + { + log_info ("- Device #%u: WARNING: Not a native Intel OpenCL runtime, expect massive speed loss", device_id + 1); + log_info (" You can use --force to override this but do not post error reports if you do so"); + } + + device_param->skipped = 1; + } + } + } + + // skipped + + device_param->skipped |= ((opencl_ctx->devices_filter & (1u << device_id)) == 0); + device_param->skipped |= ((opencl_ctx->device_types_filter & (device_type)) == 0); + + // driver_version + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + char *driver_version = (char *) mymalloc (param_value_size); + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->driver_version = driver_version; + + // device_name_chksum + + char *device_name_chksum = (char *) mymalloc (HCBUFSIZ_TINY); + + #if defined (__x86_64__) + snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%u-%u-%u-%s-%s-%s-%u", 64, device_param->platform_vendor_id, device_param->vector_width, device_param->device_name, device_param->device_version, device_param->driver_version, comptime); + #else + snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%u-%u-%u-%s-%s-%s-%u", 32, device_param->platform_vendor_id, device_param->vector_width, device_param->device_name, device_param->device_version, device_param->driver_version, comptime); + #endif + + uint device_name_digest[4] = { 0 }; + + md5_64 ((uint *) device_name_chksum, device_name_digest); + + snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%08x", device_name_digest[0]); + + device_param->device_name_chksum = device_name_chksum; + + // vendor specific + + if (device_param->device_type & CL_DEVICE_TYPE_GPU) + { + if ((device_param->platform_vendor_id == VENDOR_ID_AMD) && (device_param->device_vendor_id == VENDOR_ID_AMD)) + { + need_adl = 1; + } + + if ((device_param->platform_vendor_id == VENDOR_ID_NV) && (device_param->device_vendor_id == VENDOR_ID_NV)) + { + need_nvml = 1; + + #if defined (__linux__) + need_xnvctrl = 1; + #endif + + #if defined (_WIN) + need_nvapi = 1; + #endif + } + } + + if (device_type & CL_DEVICE_TYPE_GPU) + { + if (device_vendor_id == VENDOR_ID_NV) + { + cl_uint kernel_exec_timeout = 0; + + #define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->kernel_exec_timeout = kernel_exec_timeout; + + cl_uint sm_minor = 0; + cl_uint sm_major = 0; + + #define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 + #define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + device_param->sm_minor = sm_minor; + device_param->sm_major = sm_major; + + // CPU burning loop damper + // Value is given as number between 0-100 + // By default 100% + + device_param->nvidia_spin_damp = (double) opencl_ctx->nvidia_spin_damp; + + if (opencl_ctx->nvidia_spin_damp_chgd == 0) + { + if (attack_mode == ATTACK_MODE_STRAIGHT) + { + /** + * the workaround is not a friend of rule based attacks + * the words from the wordlist combined with fast and slow rules cause + * fluctuations which cause inaccurate wait time estimations + * using a reduced damping percentage almost compensates this + */ + + device_param->nvidia_spin_damp = 64; + } + } + + device_param->nvidia_spin_damp /= 100; + } + } + + // display results + + if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + { + if (machine_readable == 0) + { + if (device_param->skipped == 0) + { + log_info ("- Device #%u: %s, %lu/%lu MB allocatable, %uMCU", + device_id + 1, + device_name, + (unsigned int) (device_maxmem_alloc / 1024 / 1024), + (unsigned int) (device_global_mem / 1024 / 1024), + (unsigned int) device_processors); + } + else + { + log_info ("- Device #%u: %s, skipped", + device_id + 1, + device_name); + } + } + } + + // common driver check + + if (device_param->skipped == 0) + { + if (device_type & CL_DEVICE_TYPE_GPU) + { + if (platform_vendor_id == VENDOR_ID_AMD) + { + int catalyst_check = (force == 1) ? 0 : 1; + + int catalyst_warn = 0; + + int catalyst_broken = 0; + + if (catalyst_check == 1) + { + catalyst_warn = 1; + + // v14.9 and higher + if (atoi (device_param->driver_version) >= 1573) + { + catalyst_warn = 0; + } + + catalyst_check = 0; + } + + if (catalyst_broken == 1) + { + log_info (""); + log_info ("ATTENTION! The Catalyst driver installed on your system is known to be broken!"); + log_info ("It passes over cracked hashes and will not report them as cracked"); + log_info ("You are STRONGLY encouraged not to use it"); + log_info ("You can use --force to override this but do not post error reports if you do so"); + log_info (""); + + return -1; + } + + if (catalyst_warn == 1) + { + log_info (""); + log_info ("ATTENTION! Unsupported or incorrectly installed Catalyst driver detected!"); + log_info ("You are STRONGLY encouraged to use the official supported catalyst driver"); + log_info ("See hashcat's homepage for official supported catalyst drivers"); + #if defined (_WIN) + log_info ("Also see: http://hashcat.net/wiki/doku.php?id=upgrading_amd_drivers_how_to"); + #endif + log_info ("You can use --force to override this but do not post error reports if you do so"); + log_info (""); + + return -1; + } + } + else if (platform_vendor_id == VENDOR_ID_NV) + { + if (device_param->kernel_exec_timeout != 0) + { + if (quiet == 0) log_info ("- Device #%u: WARNING! Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); + if (quiet == 0) log_info (" See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); + } + } + } + + /* turns out pocl still creates segfaults (because of llvm) + if (device_type & CL_DEVICE_TYPE_CPU) + { + if (platform_vendor_id == VENDOR_ID_AMD) + { + if (force == 0) + { + log_info (""); + log_info ("ATTENTION! OpenCL support for CPU of catalyst driver is not reliable."); + log_info ("You are STRONGLY encouraged not to use it"); + log_info ("You can use --force to override this but do not post error reports if you do so"); + log_info ("A good alternative is the free pocl >= v0.13, but make sure to use a LLVM >= v3.8"); + log_info (""); + + return -1; + } + } + } + */ + + /** + * kernel accel and loops tuning db adjustment + */ + + device_param->kernel_accel_min = 1; + device_param->kernel_accel_max = 1024; + + device_param->kernel_loops_min = 1; + device_param->kernel_loops_max = 1024; + + tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, attack_mode, hashconfig->hash_mode); + + if (tuningdb_entry != NULL) + { + u32 _kernel_accel = tuningdb_entry->kernel_accel; + u32 _kernel_loops = tuningdb_entry->kernel_loops; + + if (_kernel_accel) + { + device_param->kernel_accel_min = _kernel_accel; + device_param->kernel_accel_max = _kernel_accel; + } + + if (_kernel_loops) + { + if (opencl_ctx->workload_profile == 1) + { + _kernel_loops = (_kernel_loops > 8) ? _kernel_loops / 8 : 1; + } + else if (opencl_ctx->workload_profile == 2) + { + _kernel_loops = (_kernel_loops > 4) ? _kernel_loops / 4 : 1; + } + + device_param->kernel_loops_min = _kernel_loops; + device_param->kernel_loops_max = _kernel_loops; + } + } + + // commandline parameters overwrite tuningdb entries + + if (opencl_ctx->kernel_accel_chgd == 1) + { + device_param->kernel_accel_min = opencl_ctx->kernel_accel; + device_param->kernel_accel_max = opencl_ctx->kernel_accel; + } + + if (opencl_ctx->kernel_loops_chgd == 1) + { + device_param->kernel_loops_min = opencl_ctx->kernel_loops; + device_param->kernel_loops_max = opencl_ctx->kernel_loops; + } + + /** + * activate device + */ + + devices_active++; + } + + // next please + + devices_cnt++; + } + + if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + { + if (machine_readable == 0) + { + log_info (""); + } + } + } + + if (devices_active == 0) + { + log_error ("ERROR: No devices found/left"); + + return -1; + } + + // additional check to see if the user has chosen a device that is not within the range of available devices (i.e. larger than devices_cnt) + + if (opencl_ctx->devices_filter != (uint) -1) + { + const uint devices_cnt_mask = ~(((uint) -1 >> devices_cnt) << devices_cnt); + + if (opencl_ctx->devices_filter > devices_cnt_mask) + { + log_error ("ERROR: The device specified by the --opencl-devices parameter is larger than the number of available devices (%d)", devices_cnt); + + return -1; + } + } + + opencl_ctx->devices_cnt = devices_cnt; + opencl_ctx->devices_active = devices_active; + + opencl_ctx->need_adl = need_adl; + opencl_ctx->need_nvml = need_nvml; + opencl_ctx->need_nvapi = need_nvapi; + opencl_ctx->need_xnvctrl = need_xnvctrl; + + return 0; +} + +void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx) +{ + opencl_ctx->devices_cnt = 0; + opencl_ctx->devices_active = 0; + + opencl_ctx->need_adl = 0; + opencl_ctx->need_nvml = 0; + opencl_ctx->need_nvapi = 0; + opencl_ctx->need_xnvctrl = 0; +} diff --git a/src/outfile_check.c b/src/outfile_check.c index 9a96ae811..b9322d099 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -15,11 +15,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -37,6 +38,8 @@ void *thread_outfile_remove (void *p) { // some hash-dependent constants + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + hashconfig_t *hashconfig = data.hashconfig; uint dgst_size = hashconfig->dgst_size; @@ -72,7 +75,7 @@ void *thread_outfile_remove (void *p) { hc_sleep (1); - if (data.devices_status != STATUS_RUNNING) continue; + if (opencl_ctx->devices_status != STATUS_RUNNING) continue; check_left--; @@ -278,23 +281,23 @@ void *thread_outfile_remove (void *p) data.salts_done++; - if (data.salts_done == data.salts_cnt) data.devices_status = STATUS_CRACKED; + if (data.salts_done == data.salts_cnt) opencl_ctx->devices_status = STATUS_CRACKED; } } } - if (data.devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; } } if (found) break; - if (data.devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; iter--; } - if (data.devices_status == STATUS_CRACKED) break; + if (opencl_ctx->devices_status == STATUS_CRACKED) break; } myfree (line_buf); diff --git a/src/restore.c b/src/restore.c index 5392d5610..0d8a005f5 100644 --- a/src/restore.c +++ b/src/restore.c @@ -15,12 +15,13 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "rp_cpu.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -39,13 +40,13 @@ static void fsync (int fd) } #endif -u64 get_lowest_words_done () +u64 get_lowest_words_done (opencl_ctx_t *opencl_ctx) { u64 words_cur = -1llu; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -238,9 +239,9 @@ void read_restore (const char *eff_restore_file, restore_data_t *rd) } } -void write_restore (const char *new_restore_file, restore_data_t *rd) +void write_restore (opencl_ctx_t *opencl_ctx, const char *new_restore_file, restore_data_t *rd) { - u64 words_cur = get_lowest_words_done (); + u64 words_cur = get_lowest_words_done (opencl_ctx); rd->words_cur = words_cur; @@ -275,14 +276,14 @@ void write_restore (const char *new_restore_file, restore_data_t *rd) fclose (fp); } -void cycle_restore () +void cycle_restore (opencl_ctx_t *opencl_ctx) { const char *eff_restore_file = data.eff_restore_file; const char *new_restore_file = data.new_restore_file; restore_data_t *rd = data.rd; - write_restore (new_restore_file, rd); + write_restore (opencl_ctx, new_restore_file, rd); struct stat st; @@ -302,23 +303,23 @@ void cycle_restore () } } -void check_checkpoint () +void check_checkpoint (opencl_ctx_t *opencl_ctx) { // if (data.restore_disable == 1) break; (this is already implied by previous checks) - u64 words_cur = get_lowest_words_done (); + u64 words_cur = get_lowest_words_done (opencl_ctx); if (words_cur != data.checkpoint_cur_words) { - myabort (); + myabort (opencl_ctx); } } -void stop_at_checkpoint () +void stop_at_checkpoint (opencl_ctx_t *opencl_ctx) { - if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) + if (opencl_ctx->devices_status != STATUS_STOP_AT_CHECKPOINT) { - if (data.devices_status != STATUS_RUNNING) return; + if (opencl_ctx->devices_status != STATUS_RUNNING) return; } // this feature only makes sense if --restore-disable was not specified @@ -332,19 +333,19 @@ void stop_at_checkpoint () // check if monitoring of Restore Point updates should be enabled or disabled - if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) + if (opencl_ctx->devices_status != STATUS_STOP_AT_CHECKPOINT) { - data.devices_status = STATUS_STOP_AT_CHECKPOINT; + opencl_ctx->devices_status = STATUS_STOP_AT_CHECKPOINT; // save the current restore point value - data.checkpoint_cur_words = get_lowest_words_done (); + data.checkpoint_cur_words = get_lowest_words_done (opencl_ctx); log_info ("Checkpoint enabled: Will quit at next Restore Point update"); } else { - data.devices_status = STATUS_RUNNING; + opencl_ctx->devices_status = STATUS_RUNNING; // reset the global value for checkpoint checks diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 92d952793..2247349d3 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -20,14 +20,15 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "convert.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/status.c b/src/status.c index 6781938da..71243b5aa 100644 --- a/src/status.c +++ b/src/status.c @@ -15,19 +15,19 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" #include "loopback.h" #include "data.h" -//#include "shared.h" #include "status.h" static const char ST_0000[] = "Initializing"; @@ -170,11 +170,11 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_en return exec_ms_sum / exec_ms_cnt; } -void status_display_machine_readable () +void status_display_machine_readable (opencl_ctx_t *opencl_ctx) { FILE *out = stdout; - fprintf (out, "STATUS\t%u\t", data.devices_status); + fprintf (out, "STATUS\t%u\t", opencl_ctx->devices_status); /** * speed new @@ -182,9 +182,9 @@ void status_display_machine_readable () fprintf (out, "SPEED\t"); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -209,9 +209,9 @@ void status_display_machine_readable () fprintf (out, "EXEC_RUNTIME\t"); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -224,7 +224,7 @@ void status_display_machine_readable () * words_cur */ - u64 words_cur = get_lowest_words_done (); + u64 words_cur = get_lowest_words_done (opencl_ctx); fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); @@ -291,13 +291,13 @@ void status_display_machine_readable () hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; - int temp = hm_get_temperature_with_device_id (device_id); + int temp = hm_get_temperature_with_device_id (opencl_ctx, device_id); fprintf (out, "%d\t", temp); } @@ -314,10 +314,10 @@ void status_display_machine_readable () fflush (out); } -void status_display () +void status_display (opencl_ctx_t *opencl_ctx) { - if (data.devices_status == STATUS_INIT) return; - if (data.devices_status == STATUS_STARTING) return; + if (opencl_ctx->devices_status == STATUS_INIT) return; + if (opencl_ctx->devices_status == STATUS_STARTING) return; hashconfig_t *hashconfig = data.hashconfig; void *digests_buf = data.digests_buf; @@ -331,7 +331,7 @@ void status_display () if (data.machine_readable == 1) { - status_display_machine_readable (); + status_display_machine_readable (opencl_ctx); return; } @@ -342,7 +342,7 @@ void status_display () log_info ("Session.Name...: %s", data.session); - char *status_type = strstatus (data.devices_status); + char *status_type = strstatus (opencl_ctx->devices_status); uint hash_mode = hashconfig->hash_mode; @@ -609,9 +609,9 @@ void status_display () u64 speed_cnt[DEVICES_MAX] = { 0 }; double speed_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -632,9 +632,9 @@ void status_display () double hashes_dev_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -654,9 +654,9 @@ void status_display () double exec_all_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -675,7 +675,7 @@ void status_display () double ms_paused = data.ms_paused; - if (data.devices_status == STATUS_PAUSED) + if (opencl_ctx->devices_status == STATUS_PAUSED) { double ms_paused_tmp = 0; @@ -795,7 +795,7 @@ void status_display () if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) { - if (data.devices_status != STATUS_CRACKED) + if (opencl_ctx->devices_status != STATUS_CRACKED) { #if defined (_WIN) __time64_t sec_etc = 0; @@ -899,9 +899,9 @@ void status_display () } } - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -920,7 +920,7 @@ void status_display () format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - if (data.devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); + if (opencl_ctx->devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); const double digests_percent = (double) data.digests_done / data.digests_cnt; const double salts_percent = (double) data.salts_done / data.salts_cnt; @@ -1002,7 +1002,7 @@ void status_display () // Restore point - u64 restore_point = get_lowest_words_done (); + u64 restore_point = get_lowest_words_done (opencl_ctx); u64 restore_total = data.words_base; @@ -1062,28 +1062,28 @@ void status_display () #if defined (HAVE_HWMON) - if (data.devices_status == STATUS_EXHAUSTED) return; - if (data.devices_status == STATUS_CRACKED) return; - if (data.devices_status == STATUS_ABORTED) return; - if (data.devices_status == STATUS_QUIT) return; + if (opencl_ctx->devices_status == STATUS_EXHAUSTED) return; + if (opencl_ctx->devices_status == STATUS_CRACKED) return; + if (opencl_ctx->devices_status == STATUS_ABORTED) return; + if (opencl_ctx->devices_status == STATUS_QUIT) return; if (data.gpu_temp_disable == 0) { hc_thread_mutex_lock (mux_hwmon); - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; - const int num_temperature = hm_get_temperature_with_device_id (device_id); - const int num_fanspeed = hm_get_fanspeed_with_device_id (device_id); - const int num_utilization = hm_get_utilization_with_device_id (device_id); - const int num_corespeed = hm_get_corespeed_with_device_id (device_id); - const int num_memoryspeed = hm_get_memoryspeed_with_device_id (device_id); - const int num_buslanes = hm_get_buslanes_with_device_id (device_id); - const int num_throttle = hm_get_throttle_with_device_id (device_id); + const int num_temperature = hm_get_temperature_with_device_id (opencl_ctx, device_id); + const int num_fanspeed = hm_get_fanspeed_with_device_id (opencl_ctx, device_id); + const int num_utilization = hm_get_utilization_with_device_id (opencl_ctx, device_id); + const int num_corespeed = hm_get_corespeed_with_device_id (opencl_ctx, device_id); + const int num_memoryspeed = hm_get_memoryspeed_with_device_id (opencl_ctx, device_id); + const int num_buslanes = hm_get_buslanes_with_device_id (opencl_ctx, device_id); + const int num_throttle = hm_get_throttle_with_device_id (opencl_ctx, device_id); char output_buf[256] = { 0 }; @@ -1154,16 +1154,16 @@ void status_display () #endif // HAVE_HWMON } -void status_benchmark_automate () +void status_benchmark_automate (opencl_ctx_t *opencl_ctx) { hashconfig_t *hashconfig = data.hashconfig; u64 speed_cnt[DEVICES_MAX] = { 0 }; double speed_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1173,9 +1173,9 @@ void status_benchmark_automate () double hashes_dev_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1187,9 +1187,9 @@ void status_benchmark_automate () } } - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1197,16 +1197,16 @@ void status_benchmark_automate () } } -void status_benchmark () +void status_benchmark (opencl_ctx_t *opencl_ctx) { - if (data.devices_status == STATUS_INIT) return; - if (data.devices_status == STATUS_STARTING) return; + if (opencl_ctx->devices_status == STATUS_INIT) return; + if (opencl_ctx->devices_status == STATUS_STARTING) return; if (data.shutdown_inner == 1) return; if (data.machine_readable == 1) { - status_benchmark_automate (); + status_benchmark_automate (opencl_ctx); return; } @@ -1214,9 +1214,9 @@ void status_benchmark () u64 speed_cnt[DEVICES_MAX] = { 0 }; double speed_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1228,9 +1228,9 @@ void status_benchmark () double hashes_dev_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1250,9 +1250,9 @@ void status_benchmark () double exec_all_ms[DEVICES_MAX] = { 0 }; - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1261,9 +1261,9 @@ void status_benchmark () exec_all_ms[device_id] = exec_ms_avg; } - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &data.devices_param[device_id]; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; if (device_param->skipped) continue; @@ -1273,7 +1273,7 @@ void status_benchmark () format_speed_display (hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - if (data.devices_active >= 10) + if (opencl_ctx->devices_active >= 10) { log_info ("Speed.Dev.#%d: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); } @@ -1289,5 +1289,5 @@ void status_benchmark () format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - if (data.devices_active > 1) log_info ("Speed.Dev.#*.: %9sH/s", display_all_cur); + if (opencl_ctx->devices_active > 1) log_info ("Speed.Dev.#*.: %9sH/s", display_all_cur); } diff --git a/src/stdout.c b/src/stdout.c index 87c240f57..6ec690c62 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -17,15 +17,16 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" #include "shared.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -58,7 +59,7 @@ static void out_push (out_t *out, const u8 *pw_buf, const int pw_len) } } -void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) +void process_stdout (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const uint pws_cnt) { out_t out; @@ -98,7 +99,7 @@ void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); const uint pos = device_param->innerloop_pos; @@ -125,7 +126,7 @@ void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (uint il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -191,7 +192,7 @@ void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (uint il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -221,7 +222,7 @@ void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (device_param, gidvid, &pw); + gidd_to_pw_t (opencl_ctx, device_param, gidvid, &pw); for (uint il_pos = 0; il_pos < il_cnt; il_pos++) { diff --git a/src/terminal.c b/src/terminal.c index 30bcf701f..1623d08a1 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -14,17 +14,18 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" +#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" #include "loopback.h" #include "data.h" -#include "thread.h" #include "status.h" #include "terminal.h" @@ -57,6 +58,8 @@ void clear_prompt () void *thread_keypress (void *p) { + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + uint quiet = data.quiet; tty_break(); @@ -86,7 +89,7 @@ void *thread_keypress (void *p) log_info (""); - status_display (); + status_display (opencl_ctx); log_info (""); @@ -98,7 +101,7 @@ void *thread_keypress (void *p) log_info (""); - bypass (); + bypass (opencl_ctx); log_info (""); @@ -110,7 +113,7 @@ void *thread_keypress (void *p) log_info (""); - SuspendThreads (); + SuspendThreads (opencl_ctx); log_info (""); @@ -122,7 +125,7 @@ void *thread_keypress (void *p) log_info (""); - ResumeThreads (); + ResumeThreads (opencl_ctx); log_info (""); @@ -134,7 +137,7 @@ void *thread_keypress (void *p) log_info (""); - stop_at_checkpoint (); + stop_at_checkpoint (opencl_ctx); log_info (""); @@ -146,7 +149,7 @@ void *thread_keypress (void *p) log_info (""); - myabort (); + myabort (opencl_ctx); break; } diff --git a/src/thread.c b/src/thread.c index 1c267871c..6767546e6 100644 --- a/src/thread.c +++ b/src/thread.c @@ -16,13 +16,14 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" -#include "hwmon.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -50,7 +51,7 @@ BOOL WINAPI sigHandler_default (DWORD sig) * function otherwise it is too late (e.g. after returning from this function) */ - myabort (); + myabort (data.opencl_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -62,7 +63,7 @@ BOOL WINAPI sigHandler_default (DWORD sig) case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: - myabort (); + myabort (data.opencl_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -78,7 +79,7 @@ BOOL WINAPI sigHandler_benchmark (DWORD sig) { case CTRL_CLOSE_EVENT: - myquit (); + myquit (data.opencl_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -90,7 +91,7 @@ BOOL WINAPI sigHandler_benchmark (DWORD sig) case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: - myquit (); + myquit (data.opencl_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -116,14 +117,14 @@ void hc_signal (BOOL WINAPI (callback) (DWORD)) void sigHandler_default (int sig) { - myabort (); + myabort (data.opencl_ctx); signal (sig, NULL); } void sigHandler_benchmark (int sig) { - myquit (); + myquit (data.opencl_ctx); signal (sig, NULL); } @@ -139,30 +140,30 @@ void hc_signal (void (callback) (int)) #endif -void myabort () +void myabort (opencl_ctx_t *opencl_ctx) { - data.devices_status = STATUS_ABORTED; + opencl_ctx->devices_status = STATUS_ABORTED; } -void myquit () +void myquit (opencl_ctx_t *opencl_ctx) { - data.devices_status = STATUS_QUIT; + opencl_ctx->devices_status = STATUS_QUIT; } -void SuspendThreads () +void SuspendThreads (opencl_ctx_t *opencl_ctx) { - if (data.devices_status != STATUS_RUNNING) return; + if (opencl_ctx->devices_status != STATUS_RUNNING) return; hc_timer_set (&data.timer_paused); - data.devices_status = STATUS_PAUSED; + opencl_ctx->devices_status = STATUS_PAUSED; log_info ("Paused"); } -void ResumeThreads () +void ResumeThreads (opencl_ctx_t *opencl_ctx) { - if (data.devices_status != STATUS_PAUSED) return; + if (opencl_ctx->devices_status != STATUS_PAUSED) return; double ms_paused; @@ -170,14 +171,14 @@ void ResumeThreads () data.ms_paused += ms_paused; - data.devices_status = STATUS_RUNNING; + opencl_ctx->devices_status = STATUS_RUNNING; log_info ("Resumed"); } -void bypass () +void bypass (opencl_ctx_t *opencl_ctx) { - data.devices_status = STATUS_BYPASS; + opencl_ctx->devices_status = STATUS_BYPASS; log_info ("Next dictionary / mask in queue selected, bypassing current one"); } diff --git a/src/tuningdb.c b/src/tuningdb.c index 6d035f6a9..7430083ef 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -12,8 +12,8 @@ #include "memory.h" #include "filehandling.h" #include "ext_OpenCL.h" -#include "opencl.h" #include "tuningdb.h" +#include "opencl.h" static int sort_by_tuning_db_alias (const void *v1, const void *v2) { @@ -255,13 +255,13 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file) 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) +tuning_db_entry_t *tuning_db_search (const tuning_db_t *tuning_db, const char *device_name, const cl_device_type device_type, int attack_mode, const 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); + char *device_name_nospace = mystrdup (device_name); int device_name_length = strlen (device_name_nospace); @@ -324,15 +324,15 @@ tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t * // or by device type - if (device_param->device_type & CL_DEVICE_TYPE_CPU) + if (device_type & CL_DEVICE_TYPE_CPU) { s.device_name = "DEVICE_TYPE_CPU"; } - else if (device_param->device_type & CL_DEVICE_TYPE_GPU) + else if (device_type & CL_DEVICE_TYPE_GPU) { s.device_name = "DEVICE_TYPE_GPU"; } - else if (device_param->device_type & CL_DEVICE_TYPE_ACCELERATOR) + else if (device_type & CL_DEVICE_TYPE_ACCELERATOR) { s.device_name = "DEVICE_TYPE_ACCELERATOR"; } diff --git a/src/weak_hash.c b/src/weak_hash.c index 40fda5adf..ea9539bcb 100644 --- a/src/weak_hash.c +++ b/src/weak_hash.c @@ -14,11 +14,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "restore.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" @@ -29,7 +30,7 @@ extern hc_global_data_t data; -void weak_hash_check (hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint salt_pos) +void weak_hash_check (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const uint salt_pos) { if (device_param == NULL) { @@ -63,11 +64,11 @@ void weak_hash_check (hc_device_param_t *device_param, hashconfig_t *hashconfig, if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { - run_kernel (KERN_RUN_1, device_param, 1, false, 0, hashconfig); + run_kernel (KERN_RUN_1, opencl_ctx, device_param, 1, false, 0, hashconfig); } else { - run_kernel (KERN_RUN_1, device_param, 1, false, 0, hashconfig); + run_kernel (KERN_RUN_1, opencl_ctx, device_param, 1, false, 0, hashconfig); uint loop_step = 16; @@ -82,17 +83,17 @@ void weak_hash_check (hc_device_param_t *device_param, hashconfig_t *hashconfig, device_param->kernel_params_buf32[28] = loop_pos; device_param->kernel_params_buf32[29] = loop_left; - run_kernel (KERN_RUN_2, device_param, 1, false, 0, hashconfig); + run_kernel (KERN_RUN_2, opencl_ctx, device_param, 1, false, 0, hashconfig); } - run_kernel (KERN_RUN_3, device_param, 1, false, 0, hashconfig); + run_kernel (KERN_RUN_3, opencl_ctx, device_param, 1, false, 0, hashconfig); } /** * result */ - check_cracked (device_param, salt_pos, hashconfig); + check_cracked (opencl_ctx, device_param, salt_pos, hashconfig); /** * cleanup diff --git a/src/wordlist.c b/src/wordlist.c index 2c02bea78..3e1572ee2 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -17,17 +17,17 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "tuningdb.h" #include "opencl.h" +#include "hwmon.h" +#include "restore.h" #include "thread.h" #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" #include "shared.h" -#include "hwmon.h" -#include "thread.h" #include "dictstat.h" #include "mpsp.h" -#include "restore.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h"