2016-09-11 09:42:19 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-11 09:42:19 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-14 18:06:27 +00:00
|
|
|
#include "types.h"
|
2016-10-08 21:44:05 +00:00
|
|
|
#include "event.h"
|
2019-04-25 12:45:17 +00:00
|
|
|
#include "backend.h"
|
2016-09-14 18:06:27 +00:00
|
|
|
#include "status.h"
|
2016-09-11 09:42:19 +00:00
|
|
|
#include "autotune.h"
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2016-10-06 07:53:24 +00:00
|
|
|
static double try_run (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kernel_accel, const u32 kernel_loops)
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2020-09-29 13:56:32 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-06 07:53:24 +00:00
|
|
|
|
2016-09-14 18:06:27 +00:00
|
|
|
device_param->kernel_params_buf32[28] = 0;
|
|
|
|
device_param->kernel_params_buf32[29] = kernel_loops; // not a bug, both need to be set
|
|
|
|
device_param->kernel_params_buf32[30] = kernel_loops; // because there's two variables for inner iters for slow and fast hashes
|
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
u32 kernel_power_try = device_param->hardware_power * kernel_accel;
|
|
|
|
|
|
|
|
if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
|
|
|
|
{
|
|
|
|
hashes_t *hashes = hashcat_ctx->hashes;
|
|
|
|
|
|
|
|
const u32 salts_cnt = hashes->salts_cnt;
|
|
|
|
|
|
|
|
if (kernel_power_try > salts_cnt)
|
|
|
|
{
|
|
|
|
kernel_power_try = salts_cnt;
|
|
|
|
}
|
|
|
|
}
|
2018-02-11 20:29:57 +00:00
|
|
|
|
2019-04-19 10:26:37 +00:00
|
|
|
const double spin_damp_sav = device_param->spin_damp;
|
2018-11-20 11:32:24 +00:00
|
|
|
|
|
|
|
device_param->spin_damp = 0;
|
|
|
|
|
2016-09-14 18:06:27 +00:00
|
|
|
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
|
|
|
|
{
|
2017-07-18 12:45:15 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
2017-06-29 10:19:05 +00:00
|
|
|
{
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 0, kernel_power_try, true, 0);
|
2017-06-29 10:19:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_4, 0, kernel_power_try, true, 0);
|
2017-06-29 10:19:05 +00:00
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-19 09:07:24 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 0, kernel_power_try, true, 0);
|
|
|
|
|
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_LOOP_PREPARE)
|
|
|
|
{
|
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_2P, 0, kernel_power_try, true, 0);
|
|
|
|
}
|
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 0, kernel_power_try, true, 0);
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 11:32:24 +00:00
|
|
|
device_param->spin_damp = spin_damp_sav;
|
|
|
|
|
2016-10-17 11:44:07 +00:00
|
|
|
const double exec_msec_prev = get_avg_exec_time (device_param, 1);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2016-10-17 11:44:07 +00:00
|
|
|
return exec_msec_prev;
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-11 21:15:58 +00:00
|
|
|
/*
|
2019-05-11 09:58:18 +00:00
|
|
|
static double try_run_preferred (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kernel_accel, const u32 kernel_loops)
|
|
|
|
{
|
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
|
|
|
device_param->kernel_params_buf32[28] = 0;
|
|
|
|
device_param->kernel_params_buf32[29] = kernel_loops; // not a bug, both need to be set
|
|
|
|
device_param->kernel_params_buf32[30] = kernel_loops; // because there's two variables for inner iters for slow and fast hashes
|
|
|
|
|
|
|
|
const u32 kernel_power_try = device_param->hardware_power * kernel_accel;
|
|
|
|
|
|
|
|
const u32 kernel_threads_sav = device_param->kernel_threads;
|
|
|
|
|
|
|
|
const double spin_damp_sav = device_param->spin_damp;
|
|
|
|
|
|
|
|
device_param->spin_damp = 0;
|
|
|
|
|
|
|
|
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
|
|
|
|
{
|
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
device_param->kernel_threads = device_param->kernel_preferred_wgs_multiple1;
|
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 0, kernel_power_try, true, 0);
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device_param->kernel_threads = device_param->kernel_preferred_wgs_multiple4;
|
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_4, 0, kernel_power_try, true, 0);
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
device_param->kernel_threads = device_param->kernel_preferred_wgs_multiple2;
|
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 0, kernel_power_try, true, 0);
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_param->kernel_threads = kernel_threads_sav;
|
|
|
|
|
|
|
|
device_param->spin_damp = spin_damp_sav;
|
|
|
|
|
|
|
|
const double exec_msec_prev = get_avg_exec_time (device_param, 1);
|
|
|
|
|
|
|
|
return exec_msec_prev;
|
|
|
|
}
|
2019-05-11 21:15:58 +00:00
|
|
|
*/
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2016-09-30 20:52:44 +00:00
|
|
|
static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2017-10-28 10:19:21 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2019-04-25 12:45:17 +00:00
|
|
|
const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
|
2017-10-28 10:19:21 +00:00
|
|
|
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
2018-09-01 10:31:17 +00:00
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2016-09-30 20:52:44 +00:00
|
|
|
|
2019-04-25 12:45:17 +00:00
|
|
|
const double target_msec = backend_ctx->target_msec;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
|
|
|
const u32 kernel_accel_min = device_param->kernel_accel_min;
|
|
|
|
const u32 kernel_accel_max = device_param->kernel_accel_max;
|
|
|
|
|
|
|
|
const u32 kernel_loops_min = device_param->kernel_loops_min;
|
|
|
|
const u32 kernel_loops_max = device_param->kernel_loops_max;
|
|
|
|
|
|
|
|
u32 kernel_accel = kernel_accel_min;
|
|
|
|
u32 kernel_loops = kernel_loops_min;
|
|
|
|
|
2016-10-26 22:51:26 +00:00
|
|
|
// in this case the user specified a fixed -n and -u on the commandline
|
2016-09-14 18:06:27 +00:00
|
|
|
// no way to tune anything
|
|
|
|
// but we need to run a few caching rounds
|
|
|
|
|
2016-10-26 22:51:26 +00:00
|
|
|
if ((kernel_accel_min == kernel_accel_max) && (kernel_loops_min == kernel_loops_max))
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2016-10-26 22:51:26 +00:00
|
|
|
#if defined (DEBUG)
|
|
|
|
|
|
|
|
// don't do any autotune in debug mode in this case
|
|
|
|
// we're propably during kernel development
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-12-17 17:49:07 +00:00
|
|
|
if (hashconfig->warmup_disable == false)
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2016-10-06 07:53:24 +00:00
|
|
|
try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
|
|
|
try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
|
|
|
try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
|
|
|
try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 22:51:26 +00:00
|
|
|
#endif
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
2020-05-20 10:44:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// from here it's clear we are allowed to autotune
|
|
|
|
// so let's init some fake words
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const u32 kernel_power_max = device_param->hardware_power * kernel_accel_max;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
int CU_rc;
|
2021-07-11 10:38:59 +00:00
|
|
|
int HIP_rc;
|
|
|
|
int CL_rc;
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (device_param->is_cuda == true)
|
|
|
|
{
|
|
|
|
CU_rc = run_cuda_kernel_atinit (hashcat_ctx, device_param, device_param->cuda_d_pws_buf, kernel_power_max);
|
2019-05-04 19:52:00 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2021-07-11 10:38:59 +00:00
|
|
|
if (device_param->is_hip == true)
|
|
|
|
{
|
|
|
|
HIP_rc = run_hip_kernel_atinit (hashcat_ctx, device_param, device_param->hip_d_pws_buf, kernel_power_max);
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (device_param->is_opencl == true)
|
|
|
|
{
|
|
|
|
CL_rc = run_opencl_kernel_atinit (hashcat_ctx, device_param, device_param->opencl_d_pws_buf, kernel_power_max);
|
2019-05-04 19:52:00 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (user_options->slow_candidates == true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
|
2018-09-01 10:31:17 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
if (straight_ctx->kernel_rules_cnt > 1)
|
2019-05-04 19:52:00 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
if (device_param->is_cuda == true)
|
|
|
|
{
|
|
|
|
CU_rc = hc_cuMemcpyDtoD (hashcat_ctx, device_param->cuda_d_rules_c, device_param->cuda_d_rules, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t));
|
2019-05-04 19:52:00 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2021-07-11 10:38:59 +00:00
|
|
|
if (device_param->is_hip == true)
|
|
|
|
{
|
|
|
|
HIP_rc = hc_hipMemcpyDtoD (hashcat_ctx, device_param->hip_d_rules_c, device_param->hip_d_rules, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t));
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (device_param->is_opencl == true)
|
|
|
|
{
|
|
|
|
CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_rules, device_param->opencl_d_rules_c, 0, 0, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t), 0, NULL, NULL);
|
2019-05-04 19:52:00 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
}
|
2019-05-04 19:52:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// Do a pre-autotune test run to find out if kernel runtime is above some TDR limit
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
u32 kernel_loops_max_reduced = kernel_loops_max;
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (true)
|
2017-10-17 07:07:59 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops_min);
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (exec_msec > 2000)
|
|
|
|
{
|
|
|
|
event_log_error (hashcat_ctx, "Kernel minimum runtime larger than default TDR");
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2019-05-13 15:25:33 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops_min);
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const u32 mm = kernel_loops_max / kernel_loops_min;
|
|
|
|
|
|
|
|
if ((exec_msec * mm) > target_msec)
|
|
|
|
{
|
|
|
|
const u32 loops_valid = (const u32) (target_msec / exec_msec);
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
kernel_loops_max_reduced = kernel_loops_min * loops_valid;
|
|
|
|
}
|
2017-10-17 07:07:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// first find out highest kernel-loops that stays below target_msec
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_loops_min < kernel_loops_max)
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
for (kernel_loops = kernel_loops_max; kernel_loops > kernel_loops_min; kernel_loops >>= 1)
|
|
|
|
{
|
|
|
|
if (kernel_loops > kernel_loops_max_reduced) continue;
|
2017-10-17 07:07:59 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (exec_msec < target_msec) break;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// now the same for kernel-accel but with the new kernel-loops from previous loop set
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
#define STEPS_CNT 16
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_accel_min < kernel_accel_max)
|
2016-09-14 18:06:27 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
for (int i = 0; i < STEPS_CNT; i++)
|
|
|
|
{
|
|
|
|
const u32 kernel_accel_try = 1U << i;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_accel_try < kernel_accel_min) continue;
|
|
|
|
if (kernel_accel_try > kernel_accel_max) break;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (exec_msec > target_msec) break;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
kernel_accel = kernel_accel_try;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// now find the middle balance between kernel_accel and kernel_loops
|
|
|
|
// while respecting allowed ranges at the same time
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_accel < kernel_loops)
|
|
|
|
{
|
|
|
|
const u32 kernel_accel_orig = kernel_accel;
|
|
|
|
const u32 kernel_loops_orig = kernel_loops;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
double exec_msec_prev = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
for (int i = 1; i < STEPS_CNT; i++)
|
|
|
|
{
|
|
|
|
const u32 kernel_accel_try = kernel_accel_orig * (1U << i);
|
|
|
|
const u32 kernel_loops_try = kernel_loops_orig / (1U << i);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_accel_try < kernel_accel_min) continue;
|
|
|
|
if (kernel_accel_try > kernel_accel_max) break;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_loops_try > kernel_loops_max) continue;
|
|
|
|
if (kernel_loops_try < kernel_loops_min) break;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// do a real test
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops_try);
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (exec_msec_prev < exec_msec) break;
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
exec_msec_prev = exec_msec;
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// so far, so good! save
|
2019-05-11 21:15:58 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
kernel_accel = kernel_accel_try;
|
|
|
|
kernel_loops = kernel_loops_try;
|
2018-02-03 18:01:11 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// too much if the next test is true
|
2018-02-03 18:01:11 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_loops_try < kernel_accel_try) break;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
double exec_msec_pre_final = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
2018-02-03 18:01:11 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const u32 exec_left = (const u32) (target_msec / exec_msec_pre_final);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const u32 accel_left = kernel_accel_max / kernel_accel;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
const u32 exec_accel_min = MIN (exec_left, accel_left); // we want that to be int
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (exec_accel_min >= 1)
|
|
|
|
{
|
|
|
|
// this is safe to not overflow kernel_accel_max because of accel_left
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
kernel_accel *= exec_accel_min;
|
|
|
|
}
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
// start finding best thread count is easier.
|
|
|
|
// it's either the preferred or the maximum thread count
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
/*
|
|
|
|
const u32 kernel_threads_min = device_param->kernel_threads_min;
|
|
|
|
const u32 kernel_threads_max = device_param->kernel_threads_max;
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (kernel_threads_min < kernel_threads_max)
|
|
|
|
{
|
|
|
|
const double exec_msec_max = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
u32 preferred_threads = 0;
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
|
2019-05-11 09:58:18 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
preferred_threads = device_param->kernel_preferred_wgs_multiple1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preferred_threads = device_param->kernel_preferred_wgs_multiple4;
|
|
|
|
}
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
preferred_threads = device_param->kernel_preferred_wgs_multiple2;
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:44:04 +00:00
|
|
|
if ((preferred_threads >= kernel_threads_min) && (preferred_threads <= kernel_threads_max))
|
2019-05-11 09:58:18 +00:00
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
const double exec_msec_preferred = try_run_preferred (hashcat_ctx, device_param, kernel_accel, kernel_loops);
|
|
|
|
|
|
|
|
if (exec_msec_preferred < exec_msec_max)
|
|
|
|
{
|
|
|
|
device_param->kernel_threads = preferred_threads;
|
|
|
|
}
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 10:44:04 +00:00
|
|
|
*/
|
2019-05-11 09:58:18 +00:00
|
|
|
}
|
2020-05-20 10:44:04 +00:00
|
|
|
|
|
|
|
// reset them fake words
|
|
|
|
// reset other buffers in case autotune cracked something
|
2019-05-11 09:58:18 +00:00
|
|
|
|
2019-05-04 19:52:00 +00:00
|
|
|
if (device_param->is_cuda == true)
|
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
int CU_rc;
|
2019-05-04 19:52:00 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
CU_rc = run_cuda_kernel_memset (hashcat_ctx, device_param, device_param->cuda_d_pws_buf, 0, device_param->size_pws);
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
2016-10-15 17:44:31 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
CU_rc = run_cuda_kernel_memset (hashcat_ctx, device_param, device_param->cuda_d_plain_bufs, 0, device_param->size_plains);
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
CU_rc = run_cuda_kernel_memset (hashcat_ctx, device_param, device_param->cuda_d_digests_shown, 0, device_param->size_shown);
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
CU_rc = run_cuda_kernel_memset (hashcat_ctx, device_param, device_param->cuda_d_result, 0, device_param->size_results);
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-05 09:57:54 +00:00
|
|
|
if (CU_rc == -1) return -1;
|
2019-05-04 19:52:00 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 10:38:59 +00:00
|
|
|
if (device_param->is_hip == true)
|
|
|
|
{
|
|
|
|
int HIP_rc;
|
|
|
|
|
|
|
|
HIP_rc = run_hip_kernel_memset (hashcat_ctx, device_param, device_param->hip_d_pws_buf, 0, device_param->size_pws);
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
|
|
|
|
HIP_rc = run_hip_kernel_memset (hashcat_ctx, device_param, device_param->hip_d_plain_bufs, 0, device_param->size_plains);
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
|
|
|
|
HIP_rc = run_hip_kernel_memset (hashcat_ctx, device_param, device_param->hip_d_digests_shown, 0, device_param->size_shown);
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
|
|
|
|
HIP_rc = run_hip_kernel_memset (hashcat_ctx, device_param, device_param->hip_d_result, 0, device_param->size_results);
|
|
|
|
|
|
|
|
if (HIP_rc == -1) return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-04 19:52:00 +00:00
|
|
|
if (device_param->is_opencl == true)
|
|
|
|
{
|
2020-05-20 10:44:04 +00:00
|
|
|
int CL_rc;
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2019-05-04 19:52:00 +00:00
|
|
|
CL_rc = run_opencl_kernel_memset (hashcat_ctx, device_param, device_param->opencl_d_pws_buf, 0, device_param->size_pws);
|
|
|
|
|
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
|
|
|
|
CL_rc = run_opencl_kernel_memset (hashcat_ctx, device_param, device_param->opencl_d_plain_bufs, 0, device_param->size_plains);
|
|
|
|
|
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
|
|
|
|
CL_rc = run_opencl_kernel_memset (hashcat_ctx, device_param, device_param->opencl_d_digests_shown, 0, device_param->size_shown);
|
|
|
|
|
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
|
|
|
|
CL_rc = run_opencl_kernel_memset (hashcat_ctx, device_param, device_param->opencl_d_result, 0, device_param->size_results);
|
|
|
|
|
|
|
|
if (CL_rc == -1) return -1;
|
|
|
|
}
|
2016-11-30 16:51:59 +00:00
|
|
|
|
2016-09-14 18:06:27 +00:00
|
|
|
// reset timer
|
|
|
|
|
|
|
|
device_param->exec_pos = 0;
|
|
|
|
|
2016-10-17 11:44:07 +00:00
|
|
|
memset (device_param->exec_msec, 0, EXEC_CACHE * sizeof (double));
|
2016-09-14 18:06:27 +00:00
|
|
|
|
2017-01-26 20:16:29 +00:00
|
|
|
memset (device_param->exec_us_prev1, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev2, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev3, 0, EXPECTED_ITERATIONS * sizeof (double));
|
2017-06-29 10:19:05 +00:00
|
|
|
memset (device_param->exec_us_prev4, 0, EXPECTED_ITERATIONS * sizeof (double));
|
2017-01-26 20:16:29 +00:00
|
|
|
memset (device_param->exec_us_prev_init2, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev_loop2, 0, EXPECTED_ITERATIONS * sizeof (double));
|
2018-02-13 08:13:35 +00:00
|
|
|
memset (device_param->exec_us_prev_aux1, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev_aux2, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev_aux3, 0, EXPECTED_ITERATIONS * sizeof (double));
|
|
|
|
memset (device_param->exec_us_prev_aux4, 0, EXPECTED_ITERATIONS * sizeof (double));
|
2016-09-14 18:06:27 +00:00
|
|
|
|
|
|
|
// store
|
|
|
|
|
|
|
|
device_param->kernel_accel = kernel_accel;
|
|
|
|
device_param->kernel_loops = kernel_loops;
|
|
|
|
|
2018-02-11 20:29:57 +00:00
|
|
|
const u32 kernel_power = device_param->hardware_power * device_param->kernel_accel;
|
2016-09-14 18:06:27 +00:00
|
|
|
|
|
|
|
device_param->kernel_power = kernel_power;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-15 02:00:47 +00:00
|
|
|
|
2018-09-18 21:37:30 +00:00
|
|
|
HC_API_CALL void *thread_autotune (void *p)
|
2016-09-15 02:00:47 +00:00
|
|
|
{
|
2016-09-30 20:52:44 +00:00
|
|
|
thread_param_t *thread_param = (thread_param_t *) p;
|
2016-09-15 02:00:47 +00:00
|
|
|
|
2016-09-30 20:52:44 +00:00
|
|
|
hashcat_ctx_t *hashcat_ctx = thread_param->hashcat_ctx;
|
|
|
|
|
2019-04-25 12:45:17 +00:00
|
|
|
backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
|
2016-09-15 02:00:47 +00:00
|
|
|
|
2019-04-25 12:45:17 +00:00
|
|
|
if (backend_ctx->enabled == false) return NULL;
|
2016-09-30 20:52:44 +00:00
|
|
|
|
2019-04-25 12:45:17 +00:00
|
|
|
hc_device_param_t *device_param = backend_ctx->devices_param + thread_param->tid;
|
2016-09-30 20:52:44 +00:00
|
|
|
|
2016-10-15 19:34:38 +00:00
|
|
|
if (device_param->skipped == true) return NULL;
|
2016-09-15 14:02:52 +00:00
|
|
|
|
2019-03-04 09:29:57 +00:00
|
|
|
if (device_param->skipped_warning == true) return NULL;
|
|
|
|
|
2019-05-04 19:52:00 +00:00
|
|
|
if (device_param->is_cuda == true)
|
|
|
|
{
|
2021-07-12 07:28:26 +00:00
|
|
|
if (hc_cuCtxPushCurrent (hashcat_ctx, device_param->cuda_context) == -1) return NULL;
|
2019-05-04 19:52:00 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 10:38:59 +00:00
|
|
|
if (device_param->is_hip == true)
|
|
|
|
{
|
|
|
|
if (hc_hipCtxPushCurrent (hashcat_ctx, device_param->hip_context) == -1) return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:44:05 +00:00
|
|
|
const int rc_autotune = autotune (hashcat_ctx, device_param);
|
|
|
|
|
|
|
|
if (rc_autotune == -1)
|
|
|
|
{
|
|
|
|
// we should do something here, tell hashcat main that autotune failed to abort
|
|
|
|
}
|
2016-09-15 02:00:47 +00:00
|
|
|
|
2021-07-12 07:28:26 +00:00
|
|
|
if (device_param->is_cuda == true)
|
|
|
|
{
|
|
|
|
if (hc_cuCtxPopCurrent (hashcat_ctx, &device_param->cuda_context) == -1) return NULL;
|
|
|
|
}
|
|
|
|
|
2021-07-11 10:38:59 +00:00
|
|
|
if (device_param->is_hip == true)
|
|
|
|
{
|
|
|
|
if (hc_hipCtxPopCurrent (hashcat_ctx, &device_param->hip_context) == -1) return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-15 02:00:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|