From 76a3e3f7aff25c12ed25936bf0c8e24b80539a41 Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 1 Feb 2018 16:57:59 +0100 Subject: [PATCH] OpenCL Runtime: Add current timestamp to OpenCL kernel source in order to force OpenCL JiT compiler to recompile and not use the cache --- docs/changes.txt | 1 + src/opencl.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3ee8bad58..1af053a08 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -53,6 +53,7 @@ - OpenCL Devices: Fixed several memory leaks in shutdown phase - OpenCL Runtime: Updated rocm detection - OpenCL Runtime: Enforce to use OpenCL version 1.2 to restrain OpenCL runtimes to make use of the __generic address space qualifier +- OpenCL Runtime: Add current timestamp to OpenCL kernel source in order to force OpenCL JiT compiler to recompile and not use the cache - OpenCL Kernels: Replace variables from uXX to uXXa if used in __constant space - OpenCL Kernels: Use a special kernel to initialize the password buffer used during autotune measurements, to reduce startup time - OpenCL Kernels: Use static declaraction for uXXa variables used in __constant space diff --git a/src/opencl.c b/src/opencl.c index f8c77581d..e43109180 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -239,7 +239,7 @@ static int setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *op return 0; } -static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, size_t *kernel_lengths, char **kernel_sources) +static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, size_t *kernel_lengths, char **kernel_sources, const bool force_recompile) { FILE *fp = fopen (kernel_file, "rb"); @@ -254,7 +254,9 @@ static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_fi return -1; } - char *buf = (char *) hcmalloc (st.st_size + 1); + #define EXTRASZ 100 + + char *buf = (char *) hcmalloc (st.st_size + 1 + EXTRASZ); size_t num_read = hc_fread (buf, sizeof (char), st.st_size, fp); @@ -271,6 +273,19 @@ static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_fi buf[st.st_size] = 0; + if (force_recompile == true) + { + // this adds some hopefully unique data to the opencl kernel source + // the effect should be that opencl kernel compiler caching see this as new "uncached" source + // we have to do this since they do not check for the changes only in the #include source + + time_t tlog = time (NULL); + + const int extra_len = snprintf (buf + st.st_size, EXTRASZ, "\n//%lu\n", tlog); + + st.st_size += extra_len; + } + kernel_lengths[0] = (size_t) st.st_size; kernel_sources[0] = buf; @@ -4428,7 +4443,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); #endif - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources, true); if (rc_read_kernel == -1) return -1; @@ -4492,7 +4507,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) } else { - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources, false); if (rc_read_kernel == -1) return -1; @@ -4507,7 +4522,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) } else { - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources, true); if (rc_read_kernel == -1) return -1; @@ -4631,7 +4646,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); #endif - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources, true); if (rc_read_kernel == -1) return -1; @@ -4693,7 +4708,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) } else { - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources, false); if (rc_read_kernel == -1) return -1; @@ -4772,7 +4787,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); #endif - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources, true); if (rc_read_kernel == -1) return -1; @@ -4834,7 +4849,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) } else { - const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources, false); if (rc_read_kernel == -1) return -1;