From 1f6c82b6d1146785318c460927f48cf797fcf204 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Sat, 1 Jun 2019 07:47:30 +0200 Subject: [PATCH] Add hc_cuModuleLoadDataExLog wrapper function for more detailed error logging from CUDA --- include/backend.h | 1 + src/backend.c | 56 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/include/backend.h b/include/backend.h index c74faa84d..0508ef4dd 100644 --- a/include/backend.h +++ b/include/backend.h @@ -67,6 +67,7 @@ int hc_cuMemcpyHtoD (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dstDev int hc_cuMemFree (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dptr); int hc_cuModuleGetFunction (hashcat_ctx_t *hashcat_ctx, CUfunction *hfunc, CUmodule hmod, const char *name); int hc_cuModuleLoadDataEx (hashcat_ctx_t *hashcat_ctx, CUmodule *module, const void *image, unsigned int numOptions, CUjit_option *options, void **optionValues); +int hc_cuModuleLoadDataExLog (hashcat_ctx_t *hashcat_ctx, CUmodule *module, const void *image); int hc_cuModuleUnload (hashcat_ctx_t *hashcat_ctx, CUmodule hmod); int hc_cuStreamCreate (hashcat_ctx_t *hashcat_ctx, CUstream *phStream, unsigned int Flags); int hc_cuStreamDestroy (hashcat_ctx_t *hashcat_ctx, CUstream hStream); diff --git a/src/backend.c b/src/backend.c index 2b4604ac3..4c19b24fa 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1274,6 +1274,50 @@ int hc_cuModuleLoadDataEx (hashcat_ctx_t *hashcat_ctx, CUmodule *module, const v return 0; } +int hc_cuModuleLoadDataExLog (hashcat_ctx_t *hashcat_ctx, CUmodule *module, const void *image) +{ + #define LOG_SIZE 8192 + + char *info_log = hcmalloc (LOG_SIZE); + char *error_log = hcmalloc (LOG_SIZE); + + CUjit_option opts[6]; + + opts[0] = CU_JIT_TARGET_FROM_CUCONTEXT; + opts[1] = CU_JIT_LOG_VERBOSE; + opts[2] = CU_JIT_INFO_LOG_BUFFER; + opts[3] = CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES; + opts[4] = CU_JIT_ERROR_LOG_BUFFER; + opts[5] = CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES; + + void *vals[6]; + + vals[0] = (void *) 0; + vals[1] = (void *) 1; + vals[2] = (void *) info_log; + vals[3] = (void *) LOG_SIZE; + vals[4] = (void *) error_log; + vals[5] = (void *) LOG_SIZE; + + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, module, image, 6, opts, vals); + + #if defined (DEBUG) + printf ("cuModuleLoadDataEx() Info Log (%ld):\n%s\n\n", strlen (info_log), info_log); + printf ("cuModuleLoadDataEx() Error Log (%ld):\n%s\n\n", strlen (error_log), error_log); + #else + if (rc_cuModuleLoadDataEx == -1) + { + printf ("cuModuleLoadDataEx() Info Log (%ld):\n%s\n\n", strlen (info_log), info_log); + printf ("cuModuleLoadDataEx() Error Log (%ld):\n%s\n\n", strlen (error_log), error_log); + } + #endif + + hcfree (info_log); + hcfree (error_log); + + return rc_cuModuleLoadDataEx; +} + int hc_cuModuleUnload (hashcat_ctx_t *hashcat_ctx, CUmodule hmod) { backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; @@ -7674,7 +7718,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) // tbd: check for some useful options - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module, binary, 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module, binary); if (rc_cuModuleLoadDataEx == -1) return -1; @@ -7760,7 +7804,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (device_param->is_cuda == true) { - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module, kernel_sources[0], 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module, kernel_sources[0]); if (rc_cuModuleLoadDataEx == -1) return -1; } @@ -7927,7 +7971,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) // tbd: check for some useful options - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module_mp, binary, 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module_mp, binary); if (rc_cuModuleLoadDataEx == -1) return -1; @@ -8011,7 +8055,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (device_param->is_cuda == true) { - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module_mp, kernel_sources[0], 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module_mp, kernel_sources[0]); if (rc_cuModuleLoadDataEx == -1) return -1; } @@ -8181,7 +8225,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) // tbd: check for some useful options - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module_amp, binary, 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module_amp, binary); if (rc_cuModuleLoadDataEx == -1) return -1; @@ -8265,7 +8309,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (device_param->is_cuda == true) { - const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataEx (hashcat_ctx, &device_param->cuda_module_amp, kernel_sources[0], 0, NULL, NULL); + const int rc_cuModuleLoadDataEx = hc_cuModuleLoadDataExLog (hashcat_ctx, &device_param->cuda_module_amp, kernel_sources[0]); if (rc_cuModuleLoadDataEx == -1) return -1; }