mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 16:18:09 +00:00
Limit evaluate available memory check to nvidia runtime
This commit is contained in:
parent
86fc587182
commit
f9b13035f2
41
src/opencl.c
41
src/opencl.c
@ -4261,6 +4261,15 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
if (CL_rc == -1) return -1;
|
||||
|
||||
// device_available_mem
|
||||
|
||||
#define MAX_ALLOC_CHECKS_CNT 8192
|
||||
#define MAX_ALLOC_CHECKS_SIZE (64 * 1024 * 1024)
|
||||
|
||||
device_param->device_available_mem = device_param->device_global_mem - MAX_ALLOC_CHECKS_SIZE;
|
||||
|
||||
if (device_param->platform_vendor_id == VENDOR_ID_NV)
|
||||
{
|
||||
// OK, so the problem here is the following:
|
||||
// There's just CL_DEVICE_GLOBAL_MEM_SIZE to ask OpenCL about the total memory on the device,
|
||||
// but there's no way to ask for available memory on the device.
|
||||
@ -4273,9 +4282,6 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
// The best way to workaround this problem is if we would be able to ask for available memory,
|
||||
// The idea here is to try to evaluate available memory by allocating it till it errors
|
||||
|
||||
#define MAX_ALLOC_CHECKS_CNT 8192
|
||||
#define MAX_ALLOC_CHECKS_SIZE (64 * 1024 * 1024)
|
||||
|
||||
cl_mem *tmp_device = (cl_mem *) hccalloc (MAX_ALLOC_CHECKS_CNT, sizeof (cl_mem));
|
||||
|
||||
char *tmp_host = (char *) hcmalloc (MAX_ALLOC_CHECKS_SIZE);
|
||||
@ -4284,31 +4290,31 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
for (c = 0; c < MAX_ALLOC_CHECKS_CNT; c++)
|
||||
{
|
||||
if (((c + 1) * MAX_ALLOC_CHECKS_SIZE) >= device_param->device_global_mem) break;
|
||||
if (((c + 1 + 1) * MAX_ALLOC_CHECKS_SIZE) >= device_param->device_global_mem) break;
|
||||
|
||||
cl_int CL_err;
|
||||
|
||||
OCL_PTR *ocl = opencl_ctx->ocl;
|
||||
|
||||
tmp_device[c] = ocl->clCreateBuffer (device_param->context, CL_MEM_READ_ONLY, MAX_ALLOC_CHECKS_SIZE, NULL, &CL_err);
|
||||
tmp_device[c] = ocl->clCreateBuffer (device_param->context, CL_MEM_READ_WRITE, MAX_ALLOC_CHECKS_SIZE, NULL, &CL_err);
|
||||
|
||||
if (CL_err != CL_SUCCESS)
|
||||
{
|
||||
c--;
|
||||
|
||||
break;
|
||||
}
|
||||
if (CL_err != CL_SUCCESS) break;
|
||||
|
||||
CL_err = ocl->clEnqueueReadBuffer (device_param->command_queue, tmp_device[c], CL_TRUE, 0, MAX_ALLOC_CHECKS_SIZE, tmp_host, 0, NULL, NULL);
|
||||
|
||||
if (CL_err != CL_SUCCESS)
|
||||
{
|
||||
c--;
|
||||
if (CL_err != CL_SUCCESS) break;
|
||||
|
||||
break;
|
||||
}
|
||||
CL_err = ocl->clEnqueueWriteBuffer (device_param->command_queue, tmp_device[c], CL_TRUE, 0, MAX_ALLOC_CHECKS_SIZE, tmp_host, 0, NULL, NULL);
|
||||
|
||||
if (CL_err != CL_SUCCESS) break;
|
||||
}
|
||||
|
||||
if (c >= 1) c--;
|
||||
|
||||
device_param->device_available_mem = c * MAX_ALLOC_CHECKS_SIZE;
|
||||
|
||||
// clean up
|
||||
|
||||
u64 r;
|
||||
|
||||
for (r = 0; r < c; r++)
|
||||
@ -4321,8 +4327,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
hcfree (tmp_host);
|
||||
|
||||
hcfree (tmp_device);
|
||||
|
||||
device_param->device_available_mem = c * MAX_ALLOC_CHECKS_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* create input buffers on device : calculate size of fixed memory buffers
|
||||
|
Loading…
Reference in New Issue
Block a user