Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 18 Dec 2012 12:39:13 -0200
From: Claudio André <claudioandre.br@...il.com>
To: john-dev@...ts.openwall.com
Subject: Re: Opencl build from binary

2012/7/5 SAYANTAN DATTA <std2048@...il.com>:
> magnum,solar and all,
>
> I want to make a patch for JtR for building opencl programs from binaries.
> So should I make  a seperate file or should I modify the common-opencl.c ?
> If I am given the permission to modify the common-opencl.c, I will ensure
> that it doesn't create any problems for the current build.
>
> Regards,
> Sayantan

Hi, i created a new patch using this. Unfortunately, i had to change 
common-opencl a little. Please check if the change is acceptable.
- it doesn't impact or hurt legacy code.
- if anyone want to use it, only code inside the format xxx_fmt.c file 
has to be created.
- everything seems fine, but more tests are needed. Specially on 
different platforms (i mean OSX).

Patch attached (also at: 
https://github.com/claudioandre/magnum-jumbo/commit/20051ce33d52ff8c40777c86567f441cb24484ee).


BTW: should we move the .cl files to a new folder, e,g. "../run/kernels" 
and save binary files there? We have dozens of OpenCL files now.

Claudio








diff --git a/src/common-opencl.c b/src/common-opencl.c
index b4afb4f..9c62607 100644
--- a/src/common-opencl.c
+++ b/src/common-opencl.c
@@ -121,7 +121,7 @@ static char *include_source(char *pathname, int dev_id, char *options)
 	return include;
 }
 
-static void build_kernel(int dev_id, char *options)
+static void build_kernel(int dev_id, char *options, int save, char * file_name)
 {
 	cl_int build_code;
         char * build_log; size_t log_size;
@@ -156,28 +156,33 @@ static void build_kernel(int dev_id, char *options)
 		fprintf(stderr, "Compilation log: %s\n", build_log);
 #endif
         MEM_FREE(build_log);
-#if 0
-	FILE *file;
-	size_t source_size;
-	char *source;
-
-	HANDLE_CLERROR(clGetProgramInfo(program[dev_id],
-		CL_PROGRAM_BINARY_SIZES,
-		sizeof(size_t), &source_size, NULL), "error");
-	fprintf(stderr, "source size %zu\n", source_size);
-	source = malloc(source_size);
-
-	HANDLE_CLERROR(clGetProgramInfo(program[dev_id],
-		CL_PROGRAM_BINARIES, sizeof(char *), &source, NULL), "error");
-
-	file = fopen("program.bin", "w");
-	if (file == NULL)
-		fprintf(stderr, "Error opening binary file\n");
-	else if (fwrite(source, source_size, 1, file) != 1)
-		fprintf(stderr, "error writing binary\n");
-	fclose(file);
-	MEM_FREE(source);
+
+	if (save) {
+		FILE *file;
+		size_t source_size;
+		char *source;
+
+		HANDLE_CLERROR(clGetProgramInfo(program[dev_id],
+			CL_PROGRAM_BINARY_SIZES,
+			sizeof(size_t), &source_size, NULL), "error");
+#if DEBUG
+		fprintf(stderr, "source size %zu\n", source_size);
 #endif
+		source = malloc(source_size);
+
+		HANDLE_CLERROR(clGetProgramInfo(program[dev_id],
+			CL_PROGRAM_BINARIES, sizeof(char *), &source, NULL), "error");
+
+		file = fopen(file_name, "w");
+
+		if (file == NULL)
+			fprintf(stderr, "Error creating binary file %s\n", file_name);
+		else if (fwrite(source, source_size, 1, file) != 1) {
+			fprintf(stderr, "error writing binary\n");
+			fclose(file);
+		}
+		MEM_FREE(source);
+	}
 }
 
 static void build_kernel_from_binary(int dev_id)
@@ -461,7 +466,7 @@ void opencl_init_dev(unsigned int dev_id, unsigned int platform_id)
 void opencl_build_kernel_opt(char *kernel_filename, unsigned int dev_id, char *options)
 {
 	read_kernel_source(kernel_filename);
-	build_kernel(dev_id, options);
+	build_kernel(dev_id, options, 0, NULL);
 }
 
 void opencl_build_kernel(char *kernel_filename, unsigned int dev_id)
@@ -470,6 +475,13 @@ void opencl_build_kernel(char *kernel_filename, unsigned int dev_id)
 	opencl_build_kernel_opt(kernel_filename, dev_id, NULL);
 }
 
+void opencl_build_kernel_save(char *kernel_filename, unsigned int dev_id, char *options, char *kernel_binary)
+{
+	kernel_loaded=0;
+	read_kernel_source(kernel_filename);
+	build_kernel(dev_id, options, 1, kernel_binary);
+}
+
 void opencl_build_kernel_from_binary(char *kernel_filename, unsigned int dev_id)
 {
 	read_kernel_source(kernel_filename);
diff --git a/src/common-opencl.h b/src/common-opencl.h
index f143929..748d50d 100644
--- a/src/common-opencl.h
+++ b/src/common-opencl.h
@@ -58,6 +58,8 @@ void opencl_init_opt(char *kernel_filename, unsigned int dev_id,
 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, char *kernel_binary);
 void opencl_find_best_workgroup(struct fmt_main *self);
 void opencl_find_best_workgroup_limit(struct fmt_main *self, size_t group_size_limit);


Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ