Пример #1
0
static size_t get_task_max_work_group_size(){
    size_t max_available;

    if (use_local(source_in_use))
        max_available = get_local_memory_size(ocl_gpu_id) /
                (sizeof(sha512_password) + sizeof(sha512_ctx) +
                 sizeof(sha512_buffers)) - 1;
    else if (gpu(source_in_use))
        max_available = get_local_memory_size(ocl_gpu_id) /
                sizeof(sha512_password);
    else
        max_available = get_max_work_group_size(ocl_gpu_id);

    if (max_available > get_current_work_group_size(ocl_gpu_id, crypt_kernel))
        return get_current_work_group_size(ocl_gpu_id, crypt_kernel);

    return max_available;
}
Пример #2
0
/* Can be used to select a 'good' default lws size */
size_t common_get_task_max_work_group_size(int use_local_memory,
	int local_memory_size, cl_kernel crypt_kernel) {

	size_t max_available;

	if (use_local_memory)
		max_available = get_local_memory_size(ocl_gpu_id) /
				(local_memory_size);
	else
		max_available = get_max_work_group_size(ocl_gpu_id);

	if (max_available > get_current_work_group_size(ocl_gpu_id, crypt_kernel))
		return get_current_work_group_size(ocl_gpu_id, crypt_kernel);

	return max_available;
}
Пример #3
0
/* Can be used to select a 'good' default lws size */
size_t autotune_get_task_max_work_group_size(int use_local_memory,
                                           int local_memory_size,
                                           cl_kernel crypt_kernel)
{

	size_t max_available;

	if (use_local_memory)
		max_available = get_local_memory_size(gpu_id) /
			(local_memory_size);
	else
		max_available = get_device_max_lws(gpu_id);

	if (max_available > get_kernel_max_lws(gpu_id, crypt_kernel))
		return get_kernel_max_lws(gpu_id, crypt_kernel);

	return max_available;
}
Пример #4
0
static void init(struct fmt_main *self)
{
#ifdef CL_VERSION_1_0
	char *temp;
	cl_ulong maxsize;

	global_work_size = 0;

	opencl_init("$JOHN/rar_kernel.cl", ocl_gpu_id, platform_id);

	// create kernel to execute
	crypt_kernel = clCreateKernel(program[ocl_gpu_id], "SetCryptKeys", &ret_code);
	HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");

	/* We mimic the lengths of cRARk for comparisons */
	if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_GPU) {
#ifndef DEBUG
		self->params.benchmark_comment = " (6 characters)";
#endif
		self->params.tests = gpu_tests;
#if defined(DEBUG) && !defined(ALWAYS_OPENCL)
		fprintf(stderr, "Note: will use CPU for some self-tests, and Single mode.\n");
#endif
	}

	if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG)))
		local_work_size = atoi(temp);

	if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG)))
		global_work_size = atoi(temp);

	if ((temp = getenv("LWS")))
		local_work_size = atoi(temp);

	if ((temp = getenv("GWS")))
		global_work_size = atoi(temp);

	/* Note: we ask for this kernel's max size, not the device's! */
	HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size");

#ifdef DEBUG
	fprintf(stderr, "Max allowed local work size %d\n", (int)maxsize);
#endif

	if (!local_work_size) {
		if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_CPU) {
			if (get_platform_vendor_id(platform_id) == INTEL)
				local_work_size = 8;
			else
				local_work_size = 1;
		} else {
			local_work_size = 64;
		}
	}

	if (local_work_size > maxsize) {
		fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize);
		local_work_size = maxsize;
	}

	if (!global_work_size)
		find_best_gws(temp == NULL ? 0 : 1);

	if (global_work_size < local_work_size)
		global_work_size = local_work_size;

	fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size);

	create_clobj(global_work_size);

#ifdef DEBUG
	{
		cl_ulong loc_mem_size;
		HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_LOCAL_MEM_SIZE, sizeof(loc_mem_size), &loc_mem_size, NULL), "Query local memory usage");
		fprintf(stderr, "Kernel using %lu bytes of local memory out of %lu available\n", loc_mem_size, get_local_memory_size(ocl_gpu_id));
	}
#endif

	atexit(release_clobj);

	*mkpc = VF * global_work_size;

#endif	/* OpenCL */

#if defined (_OPENMP)
	omp_t = omp_get_max_threads();
	self->params.min_keys_per_crypt *= omp_t;
#ifndef CL_VERSION_1_0	/* OpenCL gets to decide */
	*mkpc = omp_t * OMP_SCALE * MAX_KEYS_PER_CRYPT;
#endif
	init_locks();
#endif /* _OPENMP */

	if (options.utf8)
		self->params.plaintext_length = PLAINTEXT_LENGTH * 3;

	unpack_data = mem_calloc_tiny(sizeof(unpack_data_t) * omp_t, MEM_ALIGN_WORD);
	cracked = mem_calloc_tiny(sizeof(*cracked) * *mkpc, MEM_ALIGN_WORD);
#ifndef CL_VERSION_1_0
	saved_key = mem_calloc_tiny(UNICODE_LENGTH * *mkpc, MEM_ALIGN_NONE);
	saved_len = mem_calloc_tiny(sizeof(*saved_len) * *mkpc, MEM_ALIGN_WORD);
	saved_salt = mem_calloc_tiny(8, MEM_ALIGN_NONE);
	aes_key = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE);
	aes_iv = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE);
#endif

	/* OpenSSL init */
	init_aesni();
	SSL_load_error_strings();
	SSL_library_init();
	OpenSSL_add_all_algorithms();
#ifndef __APPLE__
	atexit(openssl_cleanup);
#endif
	/* CRC-32 table init, do it before we start multithreading */
	{
		CRC32_t crc;
		CRC32_Init(&crc);
	}
}
Пример #5
0
static void init(struct fmt_main *self)
{
    char *temp;
    cl_ulong maxsize, maxsize2;
    char build_opts[64];

    global_work_size = 0;

    snprintf(build_opts, sizeof(build_opts),
             "-DHASH_LOOPS=%u -DUNICODE_LENGTH=%u %s",
             HASH_LOOPS,
             UNICODE_LENGTH,
             (options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
             (options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
    opencl_init_opt("$JOHN/office2007_kernel.cl", ocl_gpu_id, platform_id, build_opts);

    // create kernel to execute
    GenerateSHA1pwhash = clCreateKernel(program[ocl_gpu_id], "GenerateSHA1pwhash", &ret_code);
    HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");
    crypt_kernel = clCreateKernel(program[ocl_gpu_id], "HashLoop", &ret_code);
    HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");
    Generate2007key = clCreateKernel(program[ocl_gpu_id], "Generate2007key", &ret_code);
    HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");

    if (options.flags & FLG_VECTORIZE) {
        /* Run vectorized code */
        VF = 4;
        self->params.algorithm_name = "OpenCL 4x";
    }

    if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG)))
        local_work_size = atoi(temp);

    if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG)))
        global_work_size = atoi(temp);

    if ((temp = getenv("LWS")))
        local_work_size = atoi(temp);

    if ((temp = getenv("GWS")))
        global_work_size = atoi(temp);

    /* Note: we ask for the kernels' max sizes, not the device's! */
    HANDLE_CLERROR(clGetKernelWorkGroupInfo(GenerateSHA1pwhash, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size");
    HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize2), &maxsize2, NULL), "Query max work group size");
    if (maxsize2 < maxsize) maxsize = maxsize2;
    HANDLE_CLERROR(clGetKernelWorkGroupInfo(Generate2007key, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize2), &maxsize2, NULL), "Query max work group size");
    if (maxsize2 < maxsize) maxsize = maxsize2;

#if 0
    /* Our use of local memory sets a limit for LWS */
    maxsize2 = get_local_memory_size(ocl_gpu_id) / (24 * VF);
    while (maxsize > maxsize2)
        maxsize >>= 1;
#endif

    /* maxsize is the lowest figure from the three different kernels */
    if (!local_work_size) {
        if (getenv("LWS")) {
            /* LWS was explicitly set to 0 */
            int temp = global_work_size;
            local_work_size = maxsize;
            global_work_size = global_work_size ? global_work_size : 4 * maxsize;
            create_clobj(global_work_size, self);
            opencl_find_best_workgroup_limit(self, maxsize);
            release_clobj();
            global_work_size = temp;
        } else {
            if (cpu(device_info[ocl_gpu_id])) {
                if (get_platform_vendor_id(platform_id) == DEV_INTEL)
                    local_work_size = MIN(maxsize, 8);
                else
                    local_work_size = 1;
            } else
                local_work_size = MIN(maxsize, 64);
        }
    }

    if (local_work_size > maxsize) {
        fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize);
        local_work_size = maxsize;
    }

    if (!global_work_size)
        find_best_gws(getenv("GWS") == NULL ? 0 : 1, self);

    if (global_work_size < local_work_size)
        global_work_size = local_work_size;

    fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size);
    create_clobj(global_work_size, self);
    atexit(release_clobj);

    if (options.utf8)
        self->params.plaintext_length = MIN(125, 3 * PLAINTEXT_LENGTH);
}