Permalink
Browse files

Change common-opencl functions in order to allow multi-gpu running an…

…d management. OpenCL devices information are initialized once and saved in memory during all runtime.

- it is not a problem is command line accepts -pla:1 and -de:0 or --devices=1,2,3 (although a decision now is good thing).
  • Loading branch information...
Claudio André
Claudio André committed Jan 13, 2013
1 parent d24a49d commit bcde5f7ddbc3686a346274d6c6ec5a05183bfdd3
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -34,7 +34,14 @@
//#define REPORT_OPENCL_WARNINGS
/* Common OpenCL variables */
int ocl_gpu_id, platform_id;
int ocl_gpu_id, platform_id, device_id;
typedef struct {
cl_platform_id platform;
int num_devices;
} cl_plataform;
cl_plataform platforms[MAX_PLATFORMS];
cl_platform_id platform[MAX_PLATFORMS];
cl_device_id devices[MAXGPUS];
cl_context context[MAXGPUS];
@@ -52,32 +59,36 @@ int cores_per_MP[MAXGPUS];
cl_int oclGetDevCap(cl_device_id device, cl_int *iComputeCapMajor, cl_int *iComputeCapMinor);
void start_opencl_devices();
void clean_opencl_devices();
int get_available_devices();
int get_platform_id(int sequencial_id);
int get_device_id(int sequencial_id);
int get_sequencial_id(unsigned int dev_id, unsigned int platform_id);
void opencl_init_dev(unsigned int dev_id, unsigned int platform_id);
void opencl_init(char *kernel_filename, unsigned int dev_id,
unsigned int platform_id);
void opencl_init_opt(char *kernel_filename, unsigned int dev_id,
unsigned int platform_id, char *options);
void opencl_init_from_binary(char *kernel_filename, unsigned int dev_id,
unsigned int platform_id);
void opencl_build_kernel(char *kernel_filename, unsigned int dev_id);
void opencl_build_kernel_from_binary(char *kernel_filename, unsigned int dev_id);
void opencl_build_kernel_save(char *kernel_filename, unsigned int dev_id, char *options, int save, int warn);
void opencl_build_kernel(char *kernel_filename, unsigned int sequencial_id);
void opencl_build_kernel_save(char *kernel_filename, unsigned int sequencial_id, char *options, int save, int warn);
void opencl_find_best_workgroup(struct fmt_main *self);
void opencl_find_best_workgroup_limit(struct fmt_main *self, size_t group_size_limit);
cl_device_type get_device_type(int dev_id);
cl_ulong get_local_memory_size(int dev_id);
cl_ulong get_global_memory_size(int dev_id);
size_t get_max_work_group_size(int dev_id);
cl_ulong get_max_mem_alloc_size(int dev_id);
size_t get_current_work_group_size(int dev_id, cl_kernel crypt_kernel);
cl_uint get_max_compute_units(int dev_id);
cl_uint get_processors_count(int dev_id);
cl_uint get_processor_family(int dev_id);
int get_vendor_id(int dev_id);
cl_device_type get_device_type(int sequencial_id);
cl_ulong get_local_memory_size(int sequencial_id);
cl_ulong get_global_memory_size(int sequencial_id);
size_t get_max_work_group_size(int sequencial_id);
cl_ulong get_max_mem_alloc_size(int sequencial_id);
size_t get_current_work_group_size(int sequencial_id, cl_kernel crypt_kernel);
cl_uint get_max_compute_units(int sequencial_id);
cl_uint get_processors_count(int sequencial_id);
cl_uint get_processor_family(int sequencial_id);
int get_vendor_id(int sequencial_id);
int get_platform_vendor_id(int platform_id);
int get_device_version(int dev_id);
int get_byte_addressable(int dev_id);
int get_device_version(int sequencial_id);
int get_byte_addressable(int sequencial_id);
char *get_error_name(cl_int cl_error);
View
@@ -324,7 +324,7 @@ static void john_register_all(void)
john_register_one(&fmt_opencl_rawsha512);
john_register_one(&fmt_opencl_rawsha512_ng);
john_register_one(&fmt_opencl_rawsha256);
john_register_one(&fmt_opencl_bf);
//TODO john_register_one(&fmt_opencl_bf);
john_register_one(&fmt_opencl_pwsafe);
//TODO john_register_one(&fmt_opencl_DES);
john_register_one(&fmt_opencl_office2007);
@@ -1193,6 +1193,11 @@ static void john_init(char *name, int argc, char **argv)
}
if (platform_id == -1 || ocl_gpu_id == -1)
opencl_find_gpu(&ocl_gpu_id, &platform_id);
//Use the sequential number on ocl_gpu_id.
start_opencl_devices();
device_id = ocl_gpu_id;
ocl_gpu_id = get_sequencial_id(device_id, platform_id);
#endif
common_init();
@@ -1304,7 +1309,7 @@ static void john_run(void)
static void john_done(void)
{
if ((options.flags & (FLG_CRACKING_CHK | FLG_STDOUT)) ==
FLG_CRACKING_CHK) {
FLG_CRACKING_CHK) {
if (event_abort)
log_event(timer_abort ?
"Session aborted" :
@@ -120,7 +120,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
@@ -394,7 +394,7 @@ static void init(struct fmt_main *self)
if ((temp = getenv("GWS")))
global_work_size = atoi(temp);
opencl_init_opt("$JOHN/kernels/cryptmd5_kernel.cl", ocl_gpu_id, platform_id, NULL);
opencl_init_opt("$JOHN/kernels/cryptmd5_kernel.cl", device_id, platform_id, NULL);
///Create Kernel
crypt_kernel = clCreateKernel(program[ocl_gpu_id], KERNEL_NAME, &ret_code);
@@ -551,7 +551,7 @@ static void init(struct fmt_main * self) {
char * tmp_value;
char * task = "$JOHN/kernels/cryptsha256_kernel_DEFAULT.cl";
opencl_init_dev(ocl_gpu_id, platform_id);
opencl_init_dev(device_id, platform_id);
source_in_use = device_info[ocl_gpu_id];
if ((tmp_value = getenv("_TYPE")))
@@ -543,7 +543,7 @@ static void init(struct fmt_main * self) {
char * tmp_value;
char * task = "$JOHN/kernels/cryptsha512_kernel_DEFAULT.cl";
opencl_init_dev(ocl_gpu_id, platform_id);
opencl_init_dev(device_id, platform_id);
source_in_use = device_info[ocl_gpu_id];
if ((tmp_value = getenv("_TYPE")))
View
@@ -191,7 +191,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
View
@@ -268,7 +268,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
View
@@ -195,7 +195,7 @@ static void init(struct fmt_main *self)
"-DPLAINTEXT_LENGTH=%d",
PLAINTEXT_LENGTH);
opencl_init_opt("$JOHN/kernels/gpg_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
global_work_size = MAX_KEYS_PER_CRYPT;
@@ -108,7 +108,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
global_work_size = MAX_KEYS_PER_CRYPT;
@@ -422,7 +422,7 @@ static void init(struct fmt_main *self)
HASH_LOOPS, ITERATIONS, PLAINTEXT_LENGTH,
(options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
(options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_kernel.cl", device_id, platform_id, build_opts);
if ((options.flags & FLG_VECTORIZE) ||
((!(options.flags & FLG_SCALAR)) &&
@@ -187,7 +187,7 @@ static void init(struct fmt_main *self){
snprintf(build_opts, sizeof(build_opts),
"-DKEY_LENGTH=%d", PLAINTEXT_LENGTH);
opencl_init_opt("$JOHN/kernels/msha_kernel.cl", ocl_gpu_id,
opencl_init_opt("$JOHN/kernels/msha_kernel.cl", device_id,
platform_id, build_opts);
// create kernel to execute
View
@@ -235,7 +235,7 @@ static void fmt_ssha_init(struct fmt_main *self)
snprintf(build_opts, sizeof(build_opts),
"-DPLAINTEXT_LENGTH=%d", PLAINTEXT_LENGTH);
opencl_init_opt("$JOHN/kernels/ssha_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/ssha_kernel.cl", device_id, platform_id, build_opts);
// create kernel to execute
crypt_kernel = clCreateKernel(program[ocl_gpu_id], "sha1_crypt_kernel", &ret_code);
View
@@ -175,7 +175,7 @@ static void crypt_all(int count)
static void init(struct fmt_main *self){
int argIndex = 0;
opencl_init("$JOHN/kernels/nt_kernel.cl", ocl_gpu_id, platform_id);
opencl_init("$JOHN/kernels/nt_kernel.cl", device_id, platform_id);
crypt_kernel = clCreateKernel( program[ocl_gpu_id], "nt_crypt", &ret_code );
HANDLE_CLERROR(ret_code,"Error creating kernel");
View
@@ -382,7 +382,7 @@ static void init(struct fmt_main *self)
}
snprintf(build_opts, sizeof(build_opts),
"-DKEYBUF_SIZE=%u -DENC_%s -DENCODING=%s", keybuf_size, encoding, encoding);
opencl_init_opt("$JOHN/kernels/ntlmv2_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/ntlmv2_kernel.cl", device_id, platform_id, build_opts);
if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG)))
local_work_size = atoi(temp);
View
@@ -115,7 +115,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
View
@@ -116,7 +116,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
@@ -412,7 +412,7 @@ static void init(struct fmt_main *self)
UNICODE_LENGTH,
(options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
(options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
opencl_init_opt("$JOHN/kernels/office2007_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/office2007_kernel.cl", device_id, platform_id, build_opts);
if ((options.flags & FLG_VECTORIZE) ||
((!(options.flags & FLG_SCALAR)) &&
@@ -414,7 +414,7 @@ static void init(struct fmt_main *self)
UNICODE_LENGTH,
(options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
(options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
opencl_init_opt("$JOHN/kernels/office2010_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/office2010_kernel.cl", device_id, platform_id, build_opts);
if ((options.flags & FLG_VECTORIZE) ||
((!(options.flags & FLG_SCALAR)) &&
@@ -416,7 +416,7 @@ static void init(struct fmt_main *self)
UNICODE_LENGTH,
(options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
(options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
opencl_init_opt("$JOHN/kernels/office2013_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/office2013_kernel.cl", device_id, platform_id, build_opts);
if ((options.flags & FLG_VECTORIZE) ||
((!(options.flags & FLG_SCALAR)) &&
View
@@ -152,7 +152,7 @@ static void init(struct fmt_main *self)
{
cl_int cl_error;
global_work_size = KEYS_PER_CRYPT / 8;
opencl_init("$JOHN/kernels/phpass_kernel.cl", ocl_gpu_id, platform_id);
opencl_init("$JOHN/kernels/phpass_kernel.cl", device_id, platform_id);
/// Allocate memory
inbuffer =
View
@@ -107,7 +107,7 @@ static void init(struct fmt_main *self)
host_hash = mem_calloc(KEYS_PER_CRYPT * sizeof(pwsafe_hash));
host_salt = mem_calloc(sizeof(pwsafe_salt));
opencl_init("$JOHN/kernels/pwsafe_kernel.cl", ocl_gpu_id, platform_id);
opencl_init("$JOHN/kernels/pwsafe_kernel.cl", device_id, platform_id);
///Allocate memory on the GPU
View
@@ -637,7 +637,7 @@ static void init(struct fmt_main *self)
global_work_size = 0;
snprintf(build_opts, sizeof(build_opts), "-DHASH_LOOPS=%u -DPLAINTEXT_LENGTH=%u", HASH_LOOPS, PLAINTEXT_LENGTH);
opencl_init_opt("$JOHN/kernels/rar_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/rar_kernel.cl", device_id, platform_id, build_opts);
// create kernels to execute
RarInit = clCreateKernel(program[ocl_gpu_id], "RarInit", &ret_code);
View
@@ -242,7 +242,7 @@ static void init(struct fmt_main *self)
}
snprintf(build_opts, sizeof(build_opts),
"-DKEY_LENGTH=%d", keybuf_size);
opencl_init_opt("$JOHN/kernels/md4_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/md4_kernel.cl", device_id, platform_id, build_opts);
crypt_kernel = clCreateKernel(program[ocl_gpu_id], "md4", &ret_code);
HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");
View
@@ -239,7 +239,7 @@ static void init(struct fmt_main *self)
}
snprintf(build_opts, sizeof(build_opts),
"-DKEY_LENGTH=%d", keybuf_size);
opencl_init_opt("$JOHN/kernels/md5_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/md5_kernel.cl", device_id, platform_id, build_opts);
crypt_kernel = clCreateKernel(program[ocl_gpu_id], "md5", &ret_code);
HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?");
View
@@ -194,7 +194,7 @@ static void fmt_rawsha1_init(struct fmt_main *self) {
}
snprintf(build_opts, sizeof(build_opts),
"-DKEY_LENGTH=%d", keybuf_size);
opencl_init_opt("$JOHN/kernels/sha1_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/sha1_kernel.cl", device_id, platform_id, build_opts);
// create kernel to execute
crypt_kernel = clCreateKernel(program[ocl_gpu_id], "sha1_crypt_kernel", &ret_code);
@@ -392,7 +392,7 @@ static void init(struct fmt_main * self) {
char * tmp_value;
char * task = "$JOHN/kernels/sha256_kernel.cl";
opencl_init_dev(ocl_gpu_id, platform_id);
opencl_init_dev(device_id, platform_id);
opencl_build_kernel_save(task, ocl_gpu_id, NULL, 1, 1);
// create kernel(s) to execute
@@ -406,7 +406,7 @@ static void init(struct fmt_main * self) {
char * tmp_value;
char * task = "$JOHN/kernels/sha512-ng_kernel.cl";
opencl_init_dev(ocl_gpu_id, platform_id);
opencl_init_dev(device_id, platform_id);
source_in_use = device_info[ocl_gpu_id];
if ((tmp_value = getenv("_TYPE")))
@@ -165,7 +165,7 @@ static void init(struct fmt_main *self)
global_work_size = MAX_KEYS_PER_CRYPT;
opencl_init("$JOHN/kernels/sha512_kernel.cl", ocl_gpu_id, platform_id);
opencl_init("$JOHN/kernels/sha512_kernel.cl", device_id, platform_id);
///Allocate memory on the GPU
mem_in =
View
@@ -113,7 +113,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
global_work_size = MAX_KEYS_PER_CRYPT;
View
@@ -119,7 +119,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);
View
@@ -328,7 +328,7 @@ static void init(struct fmt_main *self)
HASH_LOOPS, ITERATIONS, PLAINTEXT_LENGTH,
(options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" :
(options.flags & FLG_SCALAR) ? "-DSCALAR" : "");
opencl_init_opt("$JOHN/kernels/wpapsk_kernel.cl", ocl_gpu_id, platform_id, build_opts);
opencl_init_opt("$JOHN/kernels/wpapsk_kernel.cl", device_id, platform_id, build_opts);
if ((options.flags & FLG_VECTORIZE) ||
((!(options.flags & FLG_SCALAR)) &&
@@ -447,7 +447,7 @@ static void init(struct fmt_main * self) {
char * tmp_value;
char * task = "$JOHN/kernels/xsha512-ng_kernel.cl";
opencl_init_dev(ocl_gpu_id, platform_id);
opencl_init_dev(device_id, platform_id);
opencl_build_kernel_save(task, ocl_gpu_id, NULL, 1, 1);
// create kernel(s) to execute
View
@@ -170,7 +170,7 @@ static void init(struct fmt_main *self)
global_work_size = MAX_KEYS_PER_CRYPT;
opencl_init("$JOHN/kernels/xsha512_kernel.cl", ocl_gpu_id, platform_id);
opencl_init("$JOHN/kernels/xsha512_kernel.cl", device_id, platform_id);
///Allocate memory on the GPU
mem_salt =
View
@@ -118,7 +118,7 @@ static void init(struct fmt_main *self)
(int)sizeof(currentsalt.salt),
(int)sizeof(outbuffer->v));
opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
ocl_gpu_id, platform_id, build_opts);
device_id, platform_id, build_opts);
if ((temp = getenv("LWS")))
local_work_size = atoi(temp);

0 comments on commit bcde5f7

Please sign in to comment.