[GH-ISSUE #1136] Shared-code OpenCL auto-tune w/ GPU-side mask #711

Closed
opened 2026-10-14 03:21:01 +07:00 by bsakaguchi · 20 comments
Owner

Originally created by @magnumripper on GitHub (Mar 22, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1136

This is something we need to look into. Shouldn't this be pretty easy? If this run is indeed using a mask, just "use" it. If the mode in question doesn't implement it on GPU-side it will have no effect so we can do this (whatever "do this" means) anyway.

I see we are currently calling format's init() before mask_init(). That probably needs to be changed.

Once we have this in place, having benchmark test GPU-mask speed should be easy too.

Originally created by @magnumripper on GitHub (Mar 22, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1136 This is something we need to look into. Shouldn't this be pretty easy? If this run is indeed using a mask, just "use" it. If the mode in question doesn't implement it on GPU-side it will have no effect so we can do this (whatever "do this" means) anyway. I see we are currently calling format's init() before mask_init(). That probably needs to be changed. Once we have this in place, having benchmark test GPU-mask speed should be easy too.
bsakaguchi 2026-10-14 03:21:01 +07:00
Author
Owner

@magnumripper commented on GitHub (Mar 22, 2015):

In #1131, @claudioandre said

In order to get the best we can, we probably need to tune mask_int_cand_target (since this is the important number in a pure mask run).

Can we tune that at all? I though mask mode would pick the highest possible that does not exceed some upper limit. If mask is only made of ?d it will pick four of them on GPU side resulting in an "accelleration" of 10,000x. A mask consiting of ?a will only get two of them on GPU side, for 16,129x. A mask consisting of just ?l or ?u will get three of them, for 17,576x.

Maybe what you are saying is that mask_int_cand_target will set that thing I thought was "some upper limit"?

<!-- gh-comment-id:84601258 --> @magnumripper commented on GitHub (Mar 22, 2015): In #1131, @claudioandre said > In order to get the best we can, we probably need to tune mask_int_cand_target (since this is the important number in a pure mask run). Can we tune that at all? I though mask mode would pick the highest possible that does not exceed some upper limit. If mask is only made of ?d it will pick four of them on GPU side resulting in an "accelleration" of 10,000x. A mask consiting of ?a will only get two of them on GPU side, for 16,129x. A mask consisting of just ?l or ?u will get three of them, for 17,576x. Maybe what you are saying is that mask_int_cand_target will **set** that thing I thought was "some upper limit"?
Author
Owner

@ghost commented on GitHub (Mar 23, 2015):

set that thing I thought was "some upper limit"?

Yes, I was talking about this limit. But some tests showed the gain is small and the possible damage isn't.

<!-- gh-comment-id:84750755 --> @ghost commented on GitHub (Mar 23, 2015): > set that thing I thought was "some upper limit"? Yes, I was talking about this limit. But some tests showed the gain is small and the possible damage isn't.
Author
Owner

@sayan1an commented on GitHub (Mar 23, 2015):

some info on mask_int_cand_target- it is a target, not the actual number of candidates generated internally. Actual number of internal candidates generated could be higher or lower, depending on whichever is closer to the target. It is not necessary that we'd always select 4 placeholders; always a minimum number of placeholders that meets the target is chosen.

Since the target is used inside mask init to do the necessary setup of GPU and CPU part, you are not allowed to vary the target during benchmark sessions. If you do so, you'll have to invoke mask_init again!!

<!-- gh-comment-id:84768510 --> @sayan1an commented on GitHub (Mar 23, 2015): some info on mask_int_cand_target- it is a target, not the actual number of candidates generated internally. Actual number of internal candidates generated could be higher or lower, depending on whichever is closer to the target. It is not necessary that we'd always select 4 placeholders; always a minimum number of placeholders that meets the target is chosen. Since the target is used inside mask init to do the necessary setup of GPU and CPU part, you are not allowed to vary the target during benchmark sessions. If you do so, you'll have to invoke mask_init again!!
Author
Owner

@ghost commented on GitHub (Mar 23, 2015):

we are currently calling format's init() before mask_init(). That probably needs to be changed.

  • Maybe not.
    • It is possible to move auto tune code to reset(), if the other way is too complicated or undesired.
    • In fact, a fast test showed no problems and init() became lean (I guess this is good)
  • Also, auto-tune code itself (since it calls set_key() to provide data to test).
    • Has to be able to provide mask data, intervals, offsets, ... (provided by a mask helper method[?]).
    • This can be done using a default selected mask or using the real mask to be used.
<!-- gh-comment-id:85098395 --> @ghost commented on GitHub (Mar 23, 2015): > we are currently calling format's init() before mask_init(). That probably needs to be changed. - Maybe not. - It is possible to move auto tune code to reset(), if the other way is too complicated or undesired. - In fact, a fast test showed no problems and init() became lean (I guess this is good) - Also, auto-tune code itself (since it calls set_key() to provide data to test). - Has to be able to provide mask data, intervals, offsets, ... (provided by a mask helper method[?]). - This can be done using a default selected mask or using the real mask to be used.
Author
Owner

@ghost commented on GitHub (Mar 23, 2015):

6a49ab7089

<!-- gh-comment-id:85105713 --> @ghost commented on GitHub (Mar 23, 2015): 6a49ab7089ed829d45d1c0ca42da230da03f9c43
Author
Owner

@magnumripper commented on GitHub (Mar 23, 2015):

It is possible to move auto tune code to reset(), if the other way is too complicated or undesired.

This is very appealing! It has several other good effects (eg. we can get rid of kludges for --list=format-details and things like that).

<!-- gh-comment-id:85112367 --> @magnumripper commented on GitHub (Mar 23, 2015): > It is possible to move auto tune code to reset(), if the other way is too complicated or undesired. This is very appealing! It has several other good effects (eg. we can get rid of kludges for --list=format-details and things like that).
Author
Owner

@magnumripper commented on GitHub (Mar 23, 2015):

/* Called whenever the set of password hashes being cracked changes, such as
 * after self-test, but before actual cracking starts.  When called before a
 * self-test or benchmark rather than before actual cracking, db may be NULL.
 * Normally, this is a no-op since a format implementation shouldn't mess with
 * the database unnecessarily.  However, when there is a good reason to do so
 * this may e.g. transfer the salts and hashes onto a GPU card. */
        void (*reset)(struct db_main *db);

I think the above allows us to do this with no change to the spec.

Apparently reset() is called once during self-test (with no db) and once right before a crack session starts (this time with a db). Your PoC implementation only auto-tunes when reset is called with db == NULL so this is probably fine and dandy already. I think we should do a similar change to raw-md4 right away.

<!-- gh-comment-id:85159199 --> @magnumripper commented on GitHub (Mar 23, 2015): ``` C /* Called whenever the set of password hashes being cracked changes, such as * after self-test, but before actual cracking starts. When called before a * self-test or benchmark rather than before actual cracking, db may be NULL. * Normally, this is a no-op since a format implementation shouldn't mess with * the database unnecessarily. However, when there is a good reason to do so * this may e.g. transfer the salts and hashes onto a GPU card. */ void (*reset)(struct db_main *db); ``` I think the above allows us to do this with no change to the spec. Apparently reset() is called once during self-test (with no db) and once right before a crack session starts (this time with a db). Your PoC implementation only auto-tunes when reset is called with db == NULL so this is probably fine and dandy already. I think we should do a similar change to raw-md4 right away.
Author
Owner

@magnumripper commented on GitHub (Mar 23, 2015):

  • Also, auto-tune code itself (since it calls set_key() to provide data to test).
    • Has to be able to provide mask data, intervals, offsets, ... (provided by a mask helper method[?]).
    • This can be done using a default selected mask or using the real mask to be used.

For a real crack run, we should auto-tune for GPU-mask only if a mask is given (and then of course with that very mask). For a benchmark-only run, I think we should use some standard mask. I'm not sure whether we should replace the normal figures with GPU-side-mask ones, or show both figures.

<!-- gh-comment-id:85162827 --> @magnumripper commented on GitHub (Mar 23, 2015): > - Also, auto-tune code itself (since it calls set_key() to provide data to test). > - Has to be able to provide mask data, intervals, offsets, ... (provided by a mask helper method[?]). > - This can be done using a default selected mask or using the real mask to be used. For a real crack run, we should auto-tune for GPU-mask only if a mask is given (and then of course with that very mask). For a benchmark-only run, I think we should use some standard mask. I'm not sure whether we should replace the normal figures with GPU-side-mask ones, or show both figures.
Author
Owner

@ghost commented on GitHub (Mar 23, 2015):

reset() is called once during self-test (with no db)

Even if --skip-self-test is provided.

<!-- gh-comment-id:85166608 --> @ghost commented on GitHub (Mar 23, 2015): > reset() is called once during self-test (with no db) Even if --skip-self-test is provided.
Author
Owner

@magnumripper commented on GitHub (Mar 24, 2015):

I think we should do a similar change to raw-md4 right away.

ef4b3dbb does it to all OpenCL formats, bar DES, BF and mscash2 (they already did not auto-tune in init()). And kludges in listconf.c was removed.

<!-- gh-comment-id:85705784 --> @magnumripper commented on GitHub (Mar 24, 2015): > I think we should do a similar change to raw-md4 right away. ef4b3dbb does it to all OpenCL formats, bar DES, BF and mscash2 (they already did not auto-tune in init()). And kludges in listconf.c was removed.
Author
Owner

@magnumripper commented on GitHub (Mar 24, 2015):

Tried some quick'n'dirty hacks for GPU-mask auto-tune & benchmark.

diff --git a/src/bench.c b/src/bench.c
index 1ba53de..d49f358 100644
--- a/src/bench.c
+++ b/src/bench.c
@@ -57,6 +57,7 @@
 #include "unicode.h"
 #include "config.h"
 #include "common-gpu.h"
+#include "mask.h"

 #ifndef BENCH_BUILD
 #include "options.h"
@@ -494,6 +495,7 @@ int benchmark_all(void)
    int ompt;
    int ompt_start = omp_get_max_threads();
 #endif
+   struct db_main db = { 0 };

 #if defined(HAVE_OPENCL) || defined(HAVE_CUDA)
    if (!benchmark_time) {
@@ -574,6 +576,9 @@ AGAIN:
        ompt = omp_get_max_threads();
 #endif /* _OPENMP */

+       db.format = format;
+       options.flags |= FLG_MASK_STACKED;
+       mask_init(&db, NULL);
 #ifdef HAVE_MPI
        if (john_main_process)
 #endif

The above will pick the default stacked mask ?w?d?d?d?d (from john.conf). But auto-tune failed (crashed) because it's not prepared to the change of the &count argument to crypt_all(). Something like this is a minimum (just keeps resetting the count variable so we don't feed next call with the returned value of last call)...

diff --git a/src/common-opencl.c b/src/common-opencl.c
index 5d97188..bc9927a 100644
--- a/src/common-opencl.c
+++ b/src/common-opencl.c
@@ -1192,6 +1192,7 @@ void opencl_find_best_workgroup_limit(struct fmt_main *self,
                  self->params.max_keys_per_crypt - 1);

    // Timing run
+   count = self->params.max_keys_per_crypt;
    self->methods.crypt_all(&count, NULL);

    if (*lastEvent == NULL)
@@ -1243,6 +1244,7 @@ void opencl_find_best_workgroup_limit(struct fmt_main *self,
                self->params.tests[0].plaintext,
                self->params.max_keys_per_crypt - 1);

+           count = self->params.max_keys_per_crypt;
            if (self->methods.crypt_all(&count, NULL) < 0) {
                startTime = endTime = 0;
                if (options.verbosity > 3)
@@ -1592,6 +1594,7 @@ void opencl_find_best_lws(
        multi_profilingEvent[i] = &benchEvent[i];

    // Timing run
+   count = global_work_size * opencl_v_width;
    self->methods.crypt_all(&count, NULL);

    HANDLE_CLERROR(
@@ -1637,6 +1640,7 @@ void opencl_find_best_lws(
            for (j = 0; j < MAX_EVENTS; j++)
                multi_profilingEvent[j] = &benchEvent[j];

+           count = global_work_size * opencl_v_width;
            if (self->methods.crypt_all(&count, NULL) < 0) {
                startTime = endTime = 0;

...this almost works, but not quite... The real fix is slightly more complicated - we'd want to use the changed &count for showing speeds.

<!-- gh-comment-id:85730509 --> @magnumripper commented on GitHub (Mar 24, 2015): Tried some quick'n'dirty hacks for GPU-mask auto-tune & benchmark. ``` diff diff --git a/src/bench.c b/src/bench.c index 1ba53de..d49f358 100644 --- a/src/bench.c +++ b/src/bench.c @@ -57,6 +57,7 @@ #include "unicode.h" #include "config.h" #include "common-gpu.h" +#include "mask.h" #ifndef BENCH_BUILD #include "options.h" @@ -494,6 +495,7 @@ int benchmark_all(void) int ompt; int ompt_start = omp_get_max_threads(); #endif + struct db_main db = { 0 }; #if defined(HAVE_OPENCL) || defined(HAVE_CUDA) if (!benchmark_time) { @@ -574,6 +576,9 @@ AGAIN: ompt = omp_get_max_threads(); #endif /* _OPENMP */ + db.format = format; + options.flags |= FLG_MASK_STACKED; + mask_init(&db, NULL); #ifdef HAVE_MPI if (john_main_process) #endif ``` The above will pick the default stacked mask `?w?d?d?d?d` (from john.conf). But auto-tune failed (crashed) because it's not prepared to the change of the &count argument to crypt_all(). Something like this is a minimum (just keeps resetting the count variable so we don't feed next call with the returned value of last call)... ``` diff diff --git a/src/common-opencl.c b/src/common-opencl.c index 5d97188..bc9927a 100644 --- a/src/common-opencl.c +++ b/src/common-opencl.c @@ -1192,6 +1192,7 @@ void opencl_find_best_workgroup_limit(struct fmt_main *self, self->params.max_keys_per_crypt - 1); // Timing run + count = self->params.max_keys_per_crypt; self->methods.crypt_all(&count, NULL); if (*lastEvent == NULL) @@ -1243,6 +1244,7 @@ void opencl_find_best_workgroup_limit(struct fmt_main *self, self->params.tests[0].plaintext, self->params.max_keys_per_crypt - 1); + count = self->params.max_keys_per_crypt; if (self->methods.crypt_all(&count, NULL) < 0) { startTime = endTime = 0; if (options.verbosity > 3) @@ -1592,6 +1594,7 @@ void opencl_find_best_lws( multi_profilingEvent[i] = &benchEvent[i]; // Timing run + count = global_work_size * opencl_v_width; self->methods.crypt_all(&count, NULL); HANDLE_CLERROR( @@ -1637,6 +1640,7 @@ void opencl_find_best_lws( for (j = 0; j < MAX_EVENTS; j++) multi_profilingEvent[j] = &benchEvent[j]; + count = global_work_size * opencl_v_width; if (self->methods.crypt_all(&count, NULL) < 0) { startTime = endTime = 0; ``` ...this almost works, but not quite... The real fix is slightly more complicated - we'd want to use the changed `&count` for showing speeds.
Author
Owner

@magnumripper commented on GitHub (Mar 24, 2015):

M'kay, that mask_init() is too early, it will cause the self-test to fail. For this quick'n'dirty test I wanted self-test to run without mask, and benchmark with a mask. And putting it later, in benchmark_format(), sort of works, but there seem to be more code (in that function) not handling the fact &count is changed...

<!-- gh-comment-id:85735223 --> @magnumripper commented on GitHub (Mar 24, 2015): M'kay, that mask_init() is too early, it will cause the self-test to fail. For this quick'n'dirty test I wanted self-test to run without mask, and benchmark with a mask. And putting it later, in `benchmark_format()`, sort of works, but there seem to be more code (in that function) not handling the fact &count is changed...
Author
Owner

@magnumripper commented on GitHub (Mar 25, 2015):

This version auto-tunes correctly (except it does twice, first without mask, then with) but then segfaults

diff --git a/src/formats.c b/src/formats.c
index 88c5d68..de9d70c 100644
--- a/src/formats.c
+++ b/src/formats.c
@@ -31,6 +31,7 @@ typedef unsigned int ARCH_WORD_32;
 #include "cuda_common.h"
 #endif
 #include "jumbo.h"
+#include "mask.h"
 #include "memdbg.h"

 struct fmt_main *fmt_list = NULL;
@@ -179,6 +180,7 @@ static char *fmt_self_test_body(struct fmt_main *format,
        int extra_tests = 0;
 #endif
        int ml;
+       static struct db_main nodb;

        // validate that there are no NULL function pointers
        if (format->methods.prepare == NULL)    return "method prepare NULL";
@@ -659,6 +662,13 @@ static char *fmt_self_test_body(struct fmt_main *format,

        MemDbg_Validate_msg(MEMDBG_VALIDATE_DEEPEST, "At end of self-test:");

+       format->methods.done();
+       local_work_size = global_work_size = 0;
+       format->methods.init(format);
+       nodb.format = format;
+       options.flags |= FLG_MASK_STACKED;
+       mask_init(&nodb, NULL);
+       format->methods.reset(NULL);
        return NULL;
 }

Device 2: GeForce GT 650M
Benchmarking: Raw-MD4-opencl [MD4 OpenCL]... Calculating best global worksize (GWS); max. 1s total for crypt_all()
Raw speed figures including buffer transfers:
pass xfer: 5.664us, crypt: 26.784us
gws:      1024    31558185 c/s    31558185 rounds/s  32.448us per crypt_all()!
pass xfer: 7.040us, crypt: 25.952us
gws:      2048    62075654 c/s    62075654 rounds/s  32.992us per crypt_all()+
pass xfer: 9.888us, crypt: 41.696us
gws:      4096    79404466 c/s    79404466 rounds/s  51.584us per crypt_all()+
pass xfer: 15.072us, crypt: 76.960us
gws:      8192    89012517 c/s    89012517 rounds/s  92.032us per crypt_all()+
pass xfer: 25.728us, crypt: 147.232us
gws:     16384    94727104 c/s    94727104 rounds/s 172.960us per crypt_all()+
pass xfer: 49.120us, crypt: 276.672us
gws:     32768   100579510 c/s   100579510 rounds/s 325.792us per crypt_all()+
pass xfer: 93.920us, crypt: 529.984us
gws:     65536   105041801 c/s   105041801 rounds/s 623.904us per crypt_all()+
pass xfer: 175.360us, crypt: 1.076ms
gws:    131072   104690095 c/s   104690095 rounds/s   1.252ms per crypt_all()
pass xfer: 348us, crypt: 1.839ms
gws:    262144   119853694 c/s   119853694 rounds/s   2.187ms per crypt_all()+
pass xfer: 733.440us, crypt: 3.541ms
gws:    524288   122647582 c/s   122647582 rounds/s   4.274ms per crypt_all()+
pass xfer: 1.425ms, crypt: 7.158ms
gws:   1048576   122156983 c/s   122156983 rounds/s   8.583ms per crypt_all()
pass xfer: 5.509ms, crypt: 17.371ms
gws:   2097152    91652972 c/s    91652972 rounds/s  22.881ms per crypt_all()
pass xfer: 10.808ms, crypt: 31.254ms
gws:   4194304    99715244 c/s    99715244 rounds/s  42.062ms per crypt_all()
Hardware resources exhausted
Max local worksize 1024, Local worksize (LWS) 128, global worksize (GWS) 524288
Device 2: GeForce GT 650M
mask_init()
Calculating best global worksize (GWS); max. 1s total for crypt_all()
Raw speed figures including buffer transfers:
pass xfer: 5.632us, crypt: 157.762ms
gws:      1024        6490 c/s        6490 rounds/s 157.767ms per crypt_all()!
pass xfer: 6.752us, crypt: 151.603ms
gws:      2048       13508 c/s       13508 rounds/s 151.610ms per crypt_all()!
pass xfer: 9.824us, crypt: 205.838ms
gws:      4096       19898 c/s       19898 rounds/s 205.847ms per crypt_all()+
pass xfer: 15.040us, crypt: 374.670ms
gws:      8192       21863 c/s       21863 rounds/s 374.685ms per crypt_all()+
pass xfer: 32.896us, crypt: 689.918ms
gws:     16384       23746 c/s       23746 rounds/s 689.950ms per crypt_all()+
pass xfer: 49.216us, crypt: 1.374s
gws:     32768       23843 c/s       23843 rounds/s    1.374s per crypt_all() - too slow
Max local worksize 1024, Segmentation fault: 11

Notice how the second auto-tune shows much lower c/s (they should be multiplied with 10K so are actually higher) and longer durations, and ends up at 16K instead of 4M. Not yet sure why it segfaults.

<!-- gh-comment-id:85886631 --> @magnumripper commented on GitHub (Mar 25, 2015): This version auto-tunes correctly (except it does twice, first without mask, then with) but then segfaults ``` diff diff --git a/src/formats.c b/src/formats.c index 88c5d68..de9d70c 100644 --- a/src/formats.c +++ b/src/formats.c @@ -31,6 +31,7 @@ typedef unsigned int ARCH_WORD_32; #include "cuda_common.h" #endif #include "jumbo.h" +#include "mask.h" #include "memdbg.h" struct fmt_main *fmt_list = NULL; @@ -179,6 +180,7 @@ static char *fmt_self_test_body(struct fmt_main *format, int extra_tests = 0; #endif int ml; + static struct db_main nodb; // validate that there are no NULL function pointers if (format->methods.prepare == NULL) return "method prepare NULL"; @@ -659,6 +662,13 @@ static char *fmt_self_test_body(struct fmt_main *format, MemDbg_Validate_msg(MEMDBG_VALIDATE_DEEPEST, "At end of self-test:"); + format->methods.done(); + local_work_size = global_work_size = 0; + format->methods.init(format); + nodb.format = format; + options.flags |= FLG_MASK_STACKED; + mask_init(&nodb, NULL); + format->methods.reset(NULL); return NULL; } ``` ``` Device 2: GeForce GT 650M Benchmarking: Raw-MD4-opencl [MD4 OpenCL]... Calculating best global worksize (GWS); max. 1s total for crypt_all() Raw speed figures including buffer transfers: pass xfer: 5.664us, crypt: 26.784us gws: 1024 31558185 c/s 31558185 rounds/s 32.448us per crypt_all()! pass xfer: 7.040us, crypt: 25.952us gws: 2048 62075654 c/s 62075654 rounds/s 32.992us per crypt_all()+ pass xfer: 9.888us, crypt: 41.696us gws: 4096 79404466 c/s 79404466 rounds/s 51.584us per crypt_all()+ pass xfer: 15.072us, crypt: 76.960us gws: 8192 89012517 c/s 89012517 rounds/s 92.032us per crypt_all()+ pass xfer: 25.728us, crypt: 147.232us gws: 16384 94727104 c/s 94727104 rounds/s 172.960us per crypt_all()+ pass xfer: 49.120us, crypt: 276.672us gws: 32768 100579510 c/s 100579510 rounds/s 325.792us per crypt_all()+ pass xfer: 93.920us, crypt: 529.984us gws: 65536 105041801 c/s 105041801 rounds/s 623.904us per crypt_all()+ pass xfer: 175.360us, crypt: 1.076ms gws: 131072 104690095 c/s 104690095 rounds/s 1.252ms per crypt_all() pass xfer: 348us, crypt: 1.839ms gws: 262144 119853694 c/s 119853694 rounds/s 2.187ms per crypt_all()+ pass xfer: 733.440us, crypt: 3.541ms gws: 524288 122647582 c/s 122647582 rounds/s 4.274ms per crypt_all()+ pass xfer: 1.425ms, crypt: 7.158ms gws: 1048576 122156983 c/s 122156983 rounds/s 8.583ms per crypt_all() pass xfer: 5.509ms, crypt: 17.371ms gws: 2097152 91652972 c/s 91652972 rounds/s 22.881ms per crypt_all() pass xfer: 10.808ms, crypt: 31.254ms gws: 4194304 99715244 c/s 99715244 rounds/s 42.062ms per crypt_all() Hardware resources exhausted Max local worksize 1024, Local worksize (LWS) 128, global worksize (GWS) 524288 Device 2: GeForce GT 650M mask_init() Calculating best global worksize (GWS); max. 1s total for crypt_all() Raw speed figures including buffer transfers: pass xfer: 5.632us, crypt: 157.762ms gws: 1024 6490 c/s 6490 rounds/s 157.767ms per crypt_all()! pass xfer: 6.752us, crypt: 151.603ms gws: 2048 13508 c/s 13508 rounds/s 151.610ms per crypt_all()! pass xfer: 9.824us, crypt: 205.838ms gws: 4096 19898 c/s 19898 rounds/s 205.847ms per crypt_all()+ pass xfer: 15.040us, crypt: 374.670ms gws: 8192 21863 c/s 21863 rounds/s 374.685ms per crypt_all()+ pass xfer: 32.896us, crypt: 689.918ms gws: 16384 23746 c/s 23746 rounds/s 689.950ms per crypt_all()+ pass xfer: 49.216us, crypt: 1.374s gws: 32768 23843 c/s 23843 rounds/s 1.374s per crypt_all() - too slow Max local worksize 1024, Segmentation fault: 11 ``` Notice how the second auto-tune shows much lower c/s (they should be multiplied with 10K so are actually higher) and longer durations, and ends up at 16K instead of 4M. Not yet sure why it segfaults.
Author
Owner

@magnumripper commented on GitHub (Mar 25, 2015):

OK, for some reason there's no segfault if I supply the LWS. Same patch as above

$ LWS=64 ../run/john -test -form:raw-md4-opencl -verb=5 -dev=2
(...)
mask_init()
Calculating best global worksize (GWS); max. 1s total for crypt_all()
Raw speed figures including buffer transfers:
pass xfer: 6.464us, crypt: 167.953ms
gws:      1024        6096 c/s        6096 rounds/s 167.959ms per crypt_all()!
pass xfer: 9.120us, crypt: 185.083ms
gws:      2048       11064 c/s       11064 rounds/s 185.092ms per crypt_all()+
pass xfer: 14.432us, crypt: 323.612ms
gws:      4096       12656 c/s       12656 rounds/s 323.626ms per crypt_all()+
pass xfer: 15.456us, crypt: 579.930ms
gws:      8192       14125 c/s       14125 rounds/s 579.945ms per crypt_all()+
pass xfer: 33.120us, crypt: 977.655ms
gws:     16384       16757 c/s       16757 rounds/s 977.688ms per crypt_all()+
pass xfer: 49.312us, crypt: 1.894s
gws:     32768       17293 c/s       17293 rounds/s    1.894s per crypt_all() - too slow
Local worksize (LWS) 64, global worksize (GWS) 16384
DONE
Raw:    169782K c/s real, 32768M c/s virtual
<!-- gh-comment-id:85903479 --> @magnumripper commented on GitHub (Mar 25, 2015): OK, for some reason there's no segfault if I supply the LWS. Same patch as above ``` $ LWS=64 ../run/john -test -form:raw-md4-opencl -verb=5 -dev=2 (...) mask_init() Calculating best global worksize (GWS); max. 1s total for crypt_all() Raw speed figures including buffer transfers: pass xfer: 6.464us, crypt: 167.953ms gws: 1024 6096 c/s 6096 rounds/s 167.959ms per crypt_all()! pass xfer: 9.120us, crypt: 185.083ms gws: 2048 11064 c/s 11064 rounds/s 185.092ms per crypt_all()+ pass xfer: 14.432us, crypt: 323.612ms gws: 4096 12656 c/s 12656 rounds/s 323.626ms per crypt_all()+ pass xfer: 15.456us, crypt: 579.930ms gws: 8192 14125 c/s 14125 rounds/s 579.945ms per crypt_all()+ pass xfer: 33.120us, crypt: 977.655ms gws: 16384 16757 c/s 16757 rounds/s 977.688ms per crypt_all()+ pass xfer: 49.312us, crypt: 1.894s gws: 32768 17293 c/s 17293 rounds/s 1.894s per crypt_all() - too slow Local worksize (LWS) 64, global worksize (GWS) 16384 DONE Raw: 169782K c/s real, 32768M c/s virtual ```
Author
Owner

@ghost commented on GitHub (Mar 25, 2015):

This is a side effect of init() called twice. Easy to fix, but notice that there are other inconvenient that has to be handled:

$ ../run/john -test -form:raw-sha256-opencl 
Device 0: Juniper [AMD Radeon HD 6700 Series]
Building the kernel, this could take a while
Benchmarking: Raw-SHA256-opencl [SHA256 OpenCL]... Device 0: Juniper [AMD Radeon HD 6700 Series]
DONE
Raw:    175229K c/s real, 10922M c/s virtual

$ ../run/john -test -form:raw-sha256-opencl 
Device 0: Juniper [AMD Radeon HD 6700 Series]
Benchmarking: Raw-SHA256-opencl [SHA256 OpenCL]... Device 0: Juniper [AMD Radeon HD 6700 Series]
DONE
Raw:    176172K c/s real, 10922M c/s virtual
<!-- gh-comment-id:86105751 --> @ghost commented on GitHub (Mar 25, 2015): This is a side effect of init() called twice. Easy to fix, but notice that there are other inconvenient that has to be handled: ``` $ ../run/john -test -form:raw-sha256-opencl Device 0: Juniper [AMD Radeon HD 6700 Series] Building the kernel, this could take a while Benchmarking: Raw-SHA256-opencl [SHA256 OpenCL]... Device 0: Juniper [AMD Radeon HD 6700 Series] DONE Raw: 175229K c/s real, 10922M c/s virtual $ ../run/john -test -form:raw-sha256-opencl Device 0: Juniper [AMD Radeon HD 6700 Series] Benchmarking: Raw-SHA256-opencl [SHA256 OpenCL]... Device 0: Juniper [AMD Radeon HD 6700 Series] DONE Raw: 176172K c/s real, 10922M c/s virtual ```
Author
Owner

@magnumripper commented on GitHub (Mar 25, 2015):

I have some alternate code that works slightly better but it's just a PoC nevertheless. Anyway this is pretty cool, it quickly auto-tunes to good sizes for GPU-side mask. We need to decide what we really want to do. For example, maybe we actually want/need to actually self-test mask mode as opposed to just benchmarking it? At least when a mask is supplied.

<!-- gh-comment-id:86126266 --> @magnumripper commented on GitHub (Mar 25, 2015): I have some alternate code that works slightly better but it's just a PoC nevertheless. Anyway this is pretty cool, it quickly auto-tunes to good sizes for GPU-side mask. We need to decide what we really want to do. For example, maybe we actually want/need to actually self-test mask mode as opposed to just benchmarking it? At least when a mask is supplied.
Author
Owner

@ghost commented on GitHub (Mar 25, 2015):

In fact, mask has to have a formal test. But, I prefer TS for this task. I like self-test, but I dislike when it becomes too complicated for a regular run.


Anyway, this is not hard to be implemented:

static struct fmt_tests tests[] = {
    {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", "?l?l?l..."},

Or, much easier, parse a new global/parameter array set by each format (or the default NULL):

{
  {0, "?l?l?l..."}, //tests[0]
  {1, "?w?d?d..."}, //tests[1] 
}
<!-- gh-comment-id:86134657 --> @ghost commented on GitHub (Mar 25, 2015): In fact, mask has to have a formal test. But, I prefer TS for this task. I like self-test, but I dislike when it becomes too complicated for a regular run. --- Anyway, this is not hard to be implemented: ``` static struct fmt_tests tests[] = { {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", "?l?l?l..."}, ``` Or, much easier, parse a new global/parameter array set by each format (or the default NULL): ``` { {0, "?l?l?l..."}, //tests[0] {1, "?w?d?d..."}, //tests[1] } ```
Author
Owner

@magnumripper commented on GitHub (Mar 26, 2015):

The current tests struct is (few formats use the *fields[10])

struct fmt_tests {
        char *ciphertext, *plaintext;
        char *fields[10];
};

So if we add a mask

struct fmt_tests {
        char *ciphertext, *plaintext;
        char *fields[10];
        char *mask;
};

I suppose syntax when using mask but not fields[10] would be something like (is this correct?)

static struct fmt_tests tests[] = {
    {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", { NULL }, "?w?l?l?l"},

...and formats not using it would need no change.

Anyway so with that test-vector, we'd just supply test-vectors with plaintexts that are incomplete unless you add that mask, right? So for "?w?l?l?l" we should change "epixoip" to "epix". Perhaps better is to introduce yet another field for a mask-plaintext

struct fmt_tests {
        char *ciphertext, *plaintext;
        char *fields[10];
        char *mask_plain;
        char *mask;
};

And supply both

static struct fmt_tests tests[] = {
    {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", { NULL }, "epix", "?w?l?l?l"},
<!-- gh-comment-id:86374339 --> @magnumripper commented on GitHub (Mar 26, 2015): The current tests struct is (few formats use the `*fields[10]`) ``` C struct fmt_tests { char *ciphertext, *plaintext; char *fields[10]; }; ``` So if we add a mask ``` C struct fmt_tests { char *ciphertext, *plaintext; char *fields[10]; char *mask; }; ``` I suppose syntax when using mask but not fields[10] would be something like (is this correct?) ``` C static struct fmt_tests tests[] = { {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", { NULL }, "?w?l?l?l"}, ``` ...and formats not using it would need no change. Anyway so with that test-vector, we'd just supply test-vectors with plaintexts that are incomplete unless you add that mask, right? So for "?w?l?l?l" we should change "epixoip" to "epix". Perhaps better is to introduce yet another field for a mask-plaintext ``` C struct fmt_tests { char *ciphertext, *plaintext; char *fields[10]; char *mask_plain; char *mask; }; ``` And supply both ``` C static struct fmt_tests tests[] = { {"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip", { NULL }, "epix", "?w?l?l?l"}, ```
Author
Owner

@ghost commented on GitHub (Apr 1, 2015):

To be used for tune latter (notice, util is 80%):

GWS=262144 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:1234?a?a?a?a?a?a --skip
0g 0:00:01:05 N/A 0g/s 837146Kp/s 837146Kc/s 14231MC/s GPU:77°C util:82% fan:46% 1234  J&#'
GWS=524288 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:1234?a?a?a?a?a?a --skip
0g 0:00:01:13 N/A 0g/s 77774Kp/s 77774Kc/s 1322MC/s GPU:77°C util:80% fan:47% 1234  `3z'..1234  N<U(
GWS=131126 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:j?l?l?l?l?l?l?lr -max-run=40 --skip
Device 0: Tahiti [AMD Radeon HD 7900 Series]
[...]
0g 0:00:00:08 N/A 0g/s 1003Mp/s 1003Mc/s 17067MC/s GPU:52°C util:96% fan:20% jaaasrjwr..jaaasrjwr
<!-- gh-comment-id:88624085 --> @ghost commented on GitHub (Apr 1, 2015): To be used for tune latter (notice, util is 80%): ``` GWS=262144 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:1234?a?a?a?a?a?a --skip 0g 0:00:01:05 N/A 0g/s 837146Kp/s 837146Kc/s 14231MC/s GPU:77°C util:82% fan:46% 1234 J&#' ``` ``` GWS=524288 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:1234?a?a?a?a?a?a --skip 0g 0:00:01:13 N/A 0g/s 77774Kp/s 77774Kc/s 1322MC/s GPU:77°C util:80% fan:47% 1234 `3z'..1234 N<U( ``` ``` GWS=131126 ../run/john ~/testhashes -form=raw-sha256-opencl -mask:j?l?l?l?l?l?l?lr -max-run=40 --skip Device 0: Tahiti [AMD Radeon HD 7900 Series] [...] 0g 0:00:00:08 N/A 0g/s 1003Mp/s 1003Mc/s 17067MC/s GPU:52°C util:96% fan:20% jaaasrjwr..jaaasrjwr ```
Author
Owner

@magnumripper commented on GitHub (Dec 3, 2015):

This is implemented. Not quite finished but we have other issues for it. A future issue will be "add GPU-side mask mode self-tests" btw.

<!-- gh-comment-id:161774466 --> @magnumripper commented on GitHub (Dec 3, 2015): This is implemented. Not quite finished but we have other issues for it. A future issue will be "add GPU-side mask mode self-tests" btw.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#711
No description provided.