[GH-ISSUE #1822] Create a mechanism to benchmark GPU mask mode. #1210

Closed
opened 2026-10-14 03:39:22 +07:00 by bsakaguchi · 22 comments
Owner

Originally created by @ghost on GitHub (Oct 13, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1822

Since it could be hard to implement a full/regular benchmark for GPU mask mode, I created a hack that might help:

  • It can be disabled if desired.
  • It does not impact a regular run.
  • Even when enabled, it does not interfere with a normal run.

Please, take a look and check if this is desirable, useful and mergeable. Patch,
ec2aa6ccd9ebfcf401bb7caa81a9bd9c8429e672

To use it (skip_self_test is mandatory)
_MASK_MODE_DSV0=1 ../run/john -test -form:raw-sha256-opencl -dev=0 --skip

Originally created by @ghost on GitHub (Oct 13, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1822 Since it could be hard to implement a full/regular benchmark for GPU mask mode, I created a hack that might help: - It can be disabled if desired. - It does not impact a regular run. - Even when enabled, it does not interfere with a normal run. Please, take a look and check if this is desirable, useful and mergeable. Patch, ec2aa6ccd9ebfcf401bb7caa81a9bd9c8429e672 To use it (skip_self_test is mandatory) `_MASK_MODE_DSV0=1 ../run/john -test -form:raw-sha256-opencl -dev=0 --skip`
bsakaguchi 2026-10-14 03:39:22 +07:00
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

Maybe instead of using that environment variable, we could let -test -mask=(...) imply this (and also imply -skip-self-test). I tried something similar a while ago but got stuck with options.c not allowing -test and -mask simultaneously and for some reason I couldn't get past that.

That would also mean we can choose any mask we want for benchmarking.

<!-- gh-comment-id:147569517 --> @magnumripper commented on GitHub (Oct 13, 2015): Maybe instead of using that environment variable, we could let `-test -mask=(...)` imply this (and also imply -skip-self-test). I tried something similar a while ago but got stuck with options.c not allowing -test and -mask simultaneously and for some reason I couldn't get past that. That would also mean we can choose any mask we want for benchmarking.
Author
Owner

@ghost commented on GitHub (Oct 13, 2015):

Since you got stuck in core code, I will wait to see if you get a way to solve it.

<!-- gh-comment-id:147571100 --> @ghost commented on GitHub (Oct 13, 2015): Since you got stuck in core code, I will wait to see if you get a way to solve it.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

Should there be any need for per-format code for this? My approach was to simply try to run a hybrid mask-mode code path (and ignore self-test).

<!-- gh-comment-id:147647596 --> @magnumripper commented on GitHub (Oct 13, 2015): Should there be any need for per-format code for this? My approach was to simply try to run a hybrid mask-mode code path (and ignore self-test).
Author
Owner

@ghost commented on GitHub (Oct 13, 2015):

Should there be any need for per-format code for this?

No. Your approach is much better.

<!-- gh-comment-id:147708810 --> @ghost commented on GitHub (Oct 13, 2015): > Should there be any need for per-format code for this? No. Your approach is much better.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

@claudioandre @Sayantan2048 I think I did it... some testing remains.

$ ../run/john -test -form:nt-opencl -dev=6 
Device 6: GeForce GTX TITAN X
Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE
Raw:    62128K c/s real, 62128K c/s virtual

$ ../run/john -test -form:nt-opencl -dev=6 -mask
Device 6: GeForce GTX TITAN X
Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE
Raw:    11193M c/s real, 11193M c/s virtual

You can also specify a mask (including hybrid ones) to see performance for eg. a very short mask.

$ ../run/john -test -form:nt-opencl -dev=6 -mask=?w?a?a?a
Device 6: GeForce GTX TITAN X
Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE
Raw:    11419M c/s real, 11533M c/s virtual

$ ../run/john -test -form:nt-opencl -dev=6 -mask=?a?a?a?w
Device 6: GeForce GTX TITAN X
Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE
Raw:    11311M c/s real, 11199M c/s virtual

$ ../run/john -test -form:nt-opencl -dev=6 -mask=?d      
Device 6: GeForce GTX TITAN X
Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE
Raw:    677421K c/s real, 677421K c/s virtual

We might have some tweaking to do. I'm not sure whether all formats actually auto-tune correctly for this feature. NT seems to do so but some salted ones might not. But this should be a good start!

<!-- gh-comment-id:147867469 --> @magnumripper commented on GitHub (Oct 13, 2015): @claudioandre @Sayantan2048 I think I did it... some testing remains. ``` $ ../run/john -test -form:nt-opencl -dev=6 Device 6: GeForce GTX TITAN X Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE Raw: 62128K c/s real, 62128K c/s virtual $ ../run/john -test -form:nt-opencl -dev=6 -mask Device 6: GeForce GTX TITAN X Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE Raw: 11193M c/s real, 11193M c/s virtual ``` You can also specify a mask (including hybrid ones) to see performance for eg. a very short mask. ``` $ ../run/john -test -form:nt-opencl -dev=6 -mask=?w?a?a?a Device 6: GeForce GTX TITAN X Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE Raw: 11419M c/s real, 11533M c/s virtual $ ../run/john -test -form:nt-opencl -dev=6 -mask=?a?a?a?w Device 6: GeForce GTX TITAN X Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE Raw: 11311M c/s real, 11199M c/s virtual $ ../run/john -test -form:nt-opencl -dev=6 -mask=?d Device 6: GeForce GTX TITAN X Benchmarking: nt-opencl, NT [MD4 OpenCL]... DONE Raw: 677421K c/s real, 677421K c/s virtual ``` We might have some tweaking to do. I'm not sure whether all formats actually auto-tune correctly for this feature. NT seems to do so but some salted ones might not. But this should be a good start!
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

DEScrypt does not work well with this

$ ../run/john -test -dev=6 -form:descrypt-opencl 
Device 6: GeForce GTX TITAN X
Benchmarking: descrypt-opencl, traditional crypt(3) [DES OpenCL]... Salt compiled from Source:910
Salt compiled from Binary:910
Salt compiled from Binary:2275
Salt compiled from Binary:990
Salt compiled from Binary:0
DONE
Warning: "Many salts" test limited: 2/256
Many salts: 134217K c/s real, 132888K c/s virtual
Only one salt:  61567K c/s real, 61008K c/s virtual

$ ../run/john -test -dev=6 -form:descrypt-opencl -mask 
Device 6: GeForce GTX TITAN X
Benchmarking: descrypt-opencl, traditional crypt(3) [DES OpenCL]... Salt compiled from Source:910
Salt compiled from Binary:910
Salt compiled from Binary:2275
Salt compiled from Binary:990
Salt compiled from Binary:0
DONE
Warning: "Many salts" test limited: 2/256
Many salts: 7489K c/s real, 7423K c/s virtual
Only one salt:  7049K c/s real, 7049K c/s virtual

LM does get faster, but not optimal speed. I guess both of them currently doesn't auto-tune for mask when this feature is used - some tweaks will be needed.

$ ../run/john -test -dev=6 -form:lm-opencl 
Device 6: GeForce GTX TITAN X
Benchmarking: LM-opencl [DES BS OpenCL]... DONE
Raw:    96559K c/s real, 95869K c/s virtual

$ ../run/john -test -dev=6 -form:lm-opencl -mask 
Device 6: GeForce GTX TITAN X
Benchmarking: LM-opencl [DES BS OpenCL]... DONE
Raw:    765671K c/s real, 765671K c/s virtual
<!-- gh-comment-id:147869272 --> @magnumripper commented on GitHub (Oct 13, 2015): DEScrypt does not work well with this ``` $ ../run/john -test -dev=6 -form:descrypt-opencl Device 6: GeForce GTX TITAN X Benchmarking: descrypt-opencl, traditional crypt(3) [DES OpenCL]... Salt compiled from Source:910 Salt compiled from Binary:910 Salt compiled from Binary:2275 Salt compiled from Binary:990 Salt compiled from Binary:0 DONE Warning: "Many salts" test limited: 2/256 Many salts: 134217K c/s real, 132888K c/s virtual Only one salt: 61567K c/s real, 61008K c/s virtual $ ../run/john -test -dev=6 -form:descrypt-opencl -mask Device 6: GeForce GTX TITAN X Benchmarking: descrypt-opencl, traditional crypt(3) [DES OpenCL]... Salt compiled from Source:910 Salt compiled from Binary:910 Salt compiled from Binary:2275 Salt compiled from Binary:990 Salt compiled from Binary:0 DONE Warning: "Many salts" test limited: 2/256 Many salts: 7489K c/s real, 7423K c/s virtual Only one salt: 7049K c/s real, 7049K c/s virtual ``` LM does get faster, but not optimal speed. I guess both of them currently doesn't auto-tune for mask when this feature is used - some tweaks will be needed. ``` $ ../run/john -test -dev=6 -form:lm-opencl Device 6: GeForce GTX TITAN X Benchmarking: LM-opencl [DES BS OpenCL]... DONE Raw: 96559K c/s real, 95869K c/s virtual $ ../run/john -test -dev=6 -form:lm-opencl -mask Device 6: GeForce GTX TITAN X Benchmarking: LM-opencl [DES BS OpenCL]... DONE Raw: 765671K c/s real, 765671K c/s virtual ```
Author
Owner

@ghost commented on GitHub (Oct 13, 2015):

Kudos.

Please, commit in a branch so we can test it.

<!-- gh-comment-id:147869628 --> @ghost commented on GitHub (Oct 13, 2015): Kudos. Please, commit in a branch so we can test it.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

It is committed, 4592cc6b

<!-- gh-comment-id:147870657 --> @magnumripper commented on GitHub (Oct 13, 2015): It is committed, 4592cc6b
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

Right now I'm actually never calling do_mask_crack(word) or anything like that from benchmark_format() - I just init mask mode. Maybe this is not quite sufficient. But we can't call crk_process_key() like we do in a real crack. We may need to write a benchmark version of do_mask_crack().

<!-- gh-comment-id:147872467 --> @magnumripper commented on GitHub (Oct 13, 2015): Right now I'm actually never calling `do_mask_crack(word)` or anything like that from benchmark_format() - I just init mask mode. Maybe this is not quite sufficient. But we can't call crk_process_key() like we do in a real crack. We may need to write a benchmark version of do_mask_crack().
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

I guess both of them currently doesn't auto-tune for mask when this feature is used

They do. It's probably the lack of do_mask_crack() or generate_keys() or whatever.

<!-- gh-comment-id:147873217 --> @magnumripper commented on GitHub (Oct 13, 2015): > I guess both of them currently doesn't auto-tune for mask when this feature is used They do. It's probably the lack of `do_mask_crack()` or `generate_keys()` or whatever.
Author
Owner

@ghost commented on GitHub (Oct 13, 2015):

Seems to be fine. I will change some details in format code and submit.

  • Is 500ms is not good enough? No.
  • Remove: self->params.max_keys_per_crypt /= 256;
  • Etc
        //Auto tune execution from shared/included code.
        autotune_run(self, 1, gws_limit, 500ULL);

        load_hash(NULL);

        if (options.flags & FLG_MASK_CHK) {
            fprintf(stdout,
                    "Using Mask Mode with internal candidate generation%s",
                    flag ? "" : "\n");

            if (flag) {
                self->params.max_keys_per_crypt /= 256;

                if (self->params.max_keys_per_crypt < 1)
                    self->params.max_keys_per_crypt = 1;
<!-- gh-comment-id:147874919 --> @ghost commented on GitHub (Oct 13, 2015): Seems to be fine. I will change some details in format code and submit. - Is 500ms is not good enough? No. - Remove: self->params.max_keys_per_crypt /= 256; - Etc ``` //Auto tune execution from shared/included code. autotune_run(self, 1, gws_limit, 500ULL); load_hash(NULL); if (options.flags & FLG_MASK_CHK) { fprintf(stdout, "Using Mask Mode with internal candidate generation%s", flag ? "" : "\n"); if (flag) { self->params.max_keys_per_crypt /= 256; if (self->params.max_keys_per_crypt < 1) self->params.max_keys_per_crypt = 1; ```
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

500ms is plenty. I think Sayantan aims for 300ms in some format I visited.

<!-- gh-comment-id:147875285 --> @magnumripper commented on GitHub (Oct 13, 2015): 500ms is plenty. I think Sayantan aims for 300ms in some format I visited.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2015):

Hold on, I will commit enhancements.

<!-- gh-comment-id:147887066 --> @magnumripper commented on GitHub (Oct 13, 2015): Hold on, I will commit enhancements.
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

c8d543c added more proper handling. We now do call do_mask_crack() although it's handled a bit different under --test.

DEScrypt and LM formats has a weird bug but it appears this is an old bug (using default mask):

$ ../run/john -dev=6 -test -form:lm-opencl -mask

Make process completed.
Device 6: GeForce GTX TITAN X
Benchmarking: LM-opencl [DES BS OpenCL]... Format internal ranges cannot be truncated!
Use a bigger key length or non-gpu format.

Opened a separate issue #1828 for this.

<!-- gh-comment-id:147892493 --> @magnumripper commented on GitHub (Oct 14, 2015): c8d543c added more proper handling. We now do call `do_mask_crack()` although it's handled a bit different under --test. DEScrypt and LM formats has a weird bug but it appears this is an old bug (using default mask): ``` $ ../run/john -dev=6 -test -form:lm-opencl -mask Make process completed. Device 6: GeForce GTX TITAN X Benchmarking: LM-opencl [DES BS OpenCL]... Format internal ranges cannot be truncated! Use a bigger key length or non-gpu format. ``` Opened a separate issue #1828 for this.
Author
Owner

@ghost commented on GitHub (Oct 14, 2015):

500ms is plenty.

I get your point, but remember, I'm always thinking about super --dev=0. Example:

  • raw-md5-opencl is using 300ms. You can see it picks GWS=1024 on -dev=0. If you use GWS=2048 the speed is 2x better.
<!-- gh-comment-id:147896224 --> @ghost commented on GitHub (Oct 14, 2015): > 500ms is plenty. I get your point, but remember, I'm always thinking about super --dev=0. Example: - raw-md5-opencl is using 300ms. You can see it picks GWS=1024 on -dev=0. If you use GWS=2048 the speed is 2x better.
Author
Owner

@ghost commented on GitHub (Oct 14, 2015):

Forget it. The solution is more brain and less bla bla bla.

<!-- gh-comment-id:147899128 --> @ghost commented on GitHub (Oct 14, 2015): Forget it. The solution is more brain and less bla bla bla.
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

I also see now 300ms is a bit on the low side for weak GPUs (like my laptop's GT650). But instead of increasing auto-tune time, it should be better to decrease mask_int_cand_target for weak devices.

Ideally we should have a simple and fast shared function you could call for a rough "performance class" figure for a device. But what should it return? Perhaps a duration, in ms, for a given speed-test kernel?

<!-- gh-comment-id:147900124 --> @magnumripper commented on GitHub (Oct 14, 2015): I also see now 300ms is a bit on the low side for weak GPUs (like my laptop's GT650). But instead of increasing auto-tune time, it should be better to decrease `mask_int_cand_target` for weak devices. Ideally we should have a simple and fast shared function you could call for a rough "performance class" figure for a device. But what should it return? Perhaps a duration, in ms, for a given speed-test kernel?
Author
Owner

@ghost commented on GitHub (Oct 14, 2015):

Indeed. I reduced mask_int_cand_target. Have to see if/how it will impact strong GPUs.

<!-- gh-comment-id:147900586 --> @ghost commented on GitHub (Oct 14, 2015): Indeed. I reduced `mask_int_cand_target`. Have to see if/how it will impact strong GPUs.
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

It's probably hard to find a good compromise. A Titan X can do over 15-20 Gp/s with NT. My laptop can do 0.3 Gp/s.

Also, the lower number for mask_int_cand_target, the less chance for mask mode to find a good multiple (eg. if 95x95 is too high, it has to decrease to just 95, which is too low for a good GPU).

<!-- gh-comment-id:147901093 --> @magnumripper commented on GitHub (Oct 14, 2015): It's probably hard to find a good compromise. A Titan X can do over 15-20 Gp/s with NT. My laptop can do 0.3 Gp/s. Also, the lower number for mask_int_cand_target, the less chance for mask mode to find a good multiple (eg. if 95x95 is too high, it has to decrease to just 95, which is too low for a good GPU).
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

That "first GWS check in half target time" that Solar added was one of the problems. Fixed in ce8c882.

<!-- gh-comment-id:147903613 --> @magnumripper commented on GitHub (Oct 14, 2015): That "first GWS check in half target time" that Solar added was one of the problems. Fixed in ce8c882.
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

I see you had it has 20000 though. You should definitely decrease it to 10000. No other format has over 10000, DEScrypt has just 1024.

<!-- gh-comment-id:147903861 --> @magnumripper commented on GitHub (Oct 14, 2015): I see you had it has 20000 though. You should definitely decrease it to 10000. No other format has over 10000, DEScrypt has just 1024.
Author
Owner

@magnumripper commented on GitHub (Oct 14, 2015):

That problem solved canonically in #1831 and some follow-ups 😎

<!-- gh-comment-id:148203251 --> @magnumripper commented on GitHub (Oct 14, 2015): That problem solved canonically in #1831 and some follow-ups :sunglasses:
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#1210
No description provided.