425 Commits
Author SHA1 Message Date
Brannon King daf37ac444 made solo LBRY mining run 2019-06-20 14:36:52 -06:00
clintar 68e2761d97 xmr: attempt fix for reorg (#45)
Fix for block reorg on alternate block being promoted to accepted block.
2019-04-03 15:13:10 +02:00
rebinsilva f07527339f readme: some cleanup (#72)
remove outdated sentences with typos
2019-04-03 15:07:47 +02:00
Tanguy Pruvot aa3db9e524 lyra2v3 changes cleanup 2019-02-02 14:16:16 +01:00
Tanguy Pruvot 6ff4e50987 v2.3.1 release 2019-01-30 16:08:42 +01:00
Tanguy Pruvot 9a1f20d455 Handle lyra2v3 algo, for VTC fork
mostly imported from opensourced vertcoin-miner with a few fixes
2019-01-30 15:27:43 +01:00
pyritepirate c59bc2438a sha256q (#70) 2019-01-27 08:24:53 +01:00
Tanguy Pruvot 01e632cf05 handle standard blake2b stratum algo
no weird protocol or reversed endian like sia...
2018-11-30 08:05:51 +01:00
opensourcerulez b36d174554 Add exosis algo (#69) 2018-10-22 21:11:33 +02:00
Tanguy Pruvot 1f5efa7d36 makefile: add new cuda arch and remove sm5.0 by default 2018-09-20 20:14:13 +02:00
Tanguy Pruvot 4a76ca5cb6 bench: handle cryptonight variants + V100 fix 2018-08-03 20:08:34 +02:00
Tanguy Pruvot 370684f743 cryptonight: some code finitions 2018-06-24 12:25:42 +02:00
Tanguy Pruvot 654e8a10ec fix g++ 7.3 warnings (ubuntu 18.04) 2018-06-24 12:12:55 +02:00
Tanguy Pruvot d9f242b8d1 add sonoa algo, heavy x17 hashes
seems to works, more or less correctly (a few validation errors)
2018-06-23 17:51:07 +02:00
Tanguy Pruvot 6dc1bbdd47 prepare the new release 2018-06-23 13:39:38 +02:00
Tanguy Pruvot 77c4b8724e handle new cryptonight variants, stellite, aeon
special thanks for klausT changes and ystarnaud who helped me to adapt my kernel variants...

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2018-06-23 13:30:23 +02:00
Tanguy Pruvot 968d2ba049 phi2: fix the double endian swap on roots 2018-06-21 10:12:18 +02:00
Tanguy Pruvot 9fd5b04af6 phi2: handle stratum sc hashes 2018-06-18 20:43:12 +02:00
Tanguy Pruvot 07859f93ce update windows version + 2.2.6 readme 2018-06-10 18:32:37 +02:00
Tanguy Pruvot 3d03a1b9fd phi2 algo 2018-05-28 15:21:54 +02:00
Tanguy Pruvot b8190e4aa7 allium: add missing device cpu flag for linux 2018-05-17 19:29:39 +02:00
Tanguy Pruvot a9357e1ec8 lyra2: remove unused nonce param 2018-05-10 06:35:28 +02:00
Tanguy Pruvot 57f8f776fb timetravel: cleanup, remove unused algos
+ cubehash 80 midstate
2018-05-09 16:18:23 +02:00
Tanguy Pruvot ffd6cf38bf update readme and win ver 2018-05-06 18:18:05 +02:00
Tanguy Pruvot b97567a451 allium algo 2018-05-06 18:09:41 +02:00
Tanguy Pruvot bfcf7a9e52 neoscrypt: add extra space for recent vstudio madness 2018-04-22 23:12:37 +02:00
Tanguy Pruvot 16ebe53b72 x12: apply echo512 optimised kernel on recent cards 2018-04-09 17:54:13 +02:00
Tanguy Pruvot 5d0c0a665d x17: apply echo512 improvement
add a tiny 1% on x17, better than nothing...
2018-04-07 12:31:18 +02:00
Tanguy Pruvot a81ab0f7a5 readme for 2.2.5 release 2018-04-02 08:24:59 +02:00
Tanguy Pruvot ff73bda584 scrypt stuff 2018-04-02 08:24:59 +02:00
Tanguy Pruvot 2fdc10a39c x16r/s: move to a common x16 folder 2018-04-02 08:24:54 +02:00
Tanguy Pruvot 13e333d3e2 x16: optimised echo512-64 kernel for maxwell+
which keep the SM 3.0 compat with x11 kernel
2018-04-02 08:15:33 +02:00
Tanguy Pruvot 27199e2a4d api: missing break on mcast argument 2018-03-31 19:34:22 +02:00
Tanguy Pruvot 96adaf986c x16s algo, compatible with SM3+ 2018-03-29 06:31:02 +02:00
Tanguy Pruvot 5b1b77ba95 api: fix possible issue on linux 2018-03-29 02:32:10 +02:00
Tanguy Pruvot 0961544c85 x12: reorder cpu code to notice its not x11 one 2018-03-26 06:52:50 +02:00
Tanguy Pruvot 51c02a7e9a x12: a bit more code cleanup 2018-03-26 06:10:49 +02:00
Tanguy Pruvot 84337459b8 x12 stuff + readme 2018-03-26 03:14:21 +02:00
Galaxy Cash Developers e21640545f x12 algorithm (#59) 2018-03-26 03:08:43 +02:00
Tanguy Pruvot fd406f02c2 equihash: error fix for the TITAN V 2018-03-15 22:03:35 +01:00
Tanguy Pruvot d8a64d4bd2 neoscrypt: improve perfs and fix the Titan default intensity 2018-03-15 21:08:44 +01:00
Tanguy Pruvot 78dad7dd65 x16r algo and new kernels
Was a very long work but finally working,
and unlike xevan these new kernels are reusable..

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2018-02-04 08:06:44 +01:00
Tanguy Pruvot b71f85ec31 stratum: show reason of auth failure 2018-01-16 10:35:37 +01:00
hakemimi 50781f00eb lyra2: Translate japanese comments into english (#40)
* Revert "lyra2: fix compilation on japanese windows (#38)"

This reverts commit 30db7d2433.

* Restore comments removed in #38, translate them into English

The original line says "allocate XXXX bytes to adjust for X Warp."
Remove the number from comment since they are trivial

* Translate Japanese comments
2018-01-10 12:24:50 +01:00
Guillaume George 30db7d2433 lyra2: fix compilation on japanese windows (#38)
Remove comment that prevent compilation on japanese windows (#38)
2018-01-09 18:32:12 +01:00
Tanguy Pruvot 3761774ccf cuda: get ride of cuda 9 mask warnings 2018-01-08 14:08:23 +01:00
Chris Spillane f1a7de4e9e Update README.txt (#37)
remove duplicate x17 line, add a few more coin examples.
2018-01-05 11:56:54 +01:00
Tanguy Pruvot b54be470e1 upgrade BIGNUM class for openssl 1.1 2018-01-04 18:14:57 +01:00
Tanguy Pruvot 69e12962fc update README for 2.2.4 2018-01-04 16:07:48 +01:00
Tanguy Pruvot 73dd6aac5c keccak: avoid to use twice cuda_default_throughput
and drop useless gpu hash alloc...
2018-01-04 15:58:01 +01:00
Tanguy Pruvot 11a512f2a7 change defaults to handle cuda 9+, disable heavy and SM 2.x
Heavy is the only algo using thrust which is generally broken on new cuda releases

mjollnir dropped too... never seen this coin anyway...
2018-01-04 15:37:01 +01:00
Tanguy Pruvot 91af8ab6e6 decred doesnt allow pow votes 2018-01-04 15:19:20 +01:00
Tanguy Pruvot 6165562839 equihash: fix for cuda 9.1 build 2018-01-04 14:59:31 +01:00
dementeb 72466ee476 api: update websocket sample (#31) 2018-01-04 14:58:36 +01:00
Tanguy Pruvot b70409ab5b lyra2RE: link the merged blake/keccak kernel into algos
old keccak256_gpu_hash_32 kernel commented to reduce binary size

compat. not yet tested on old cards
2017-12-14 18:21:40 +01:00
Myrinia 18d29914ec Improve Lyra2RE2 Performance
Improved Lyra2Re2 Performance by 1 %
2017-12-14 18:21:04 +01:00
Tanguy Pruvot 6c0e656030 keccak: fix issue with intensity 2017-12-09 16:54:48 +01:00
Tanguy Pruvot 015d129aa6 keccak second nonce, and higher intensity 2017-12-04 21:52:11 +01:00
Tanguy Pruvot cf886b5907 import and adapt alexis optimised keccak256 for SM 5+
and increase default intensity for these recent cards
2017-12-04 16:38:20 +01:00
Tanguy Pruvot d19e2a1e62 Add keccakc for creative coin
Same hash as keccak, just different pool settings (sha256d and diff factor 256)
2017-12-03 16:52:21 +01:00
Tanguy Pruvot df4fcbe3a4 jha: remove deprecated warning 2017-11-20 08:50:40 +01:00
Tanguy Pruvot bfa616a2a4 linux: common openssl lib function for 1.1+ 2017-11-20 07:58:55 +01:00
Tanguy Pruvot dfff3b3f98 windows: high precision timer before threads start 2017-11-20 07:30:14 +01:00
Tanguy Pruvot 2e0a977784 polytimos algo (6 chained algos with streebog) 2017-11-16 10:42:35 +01:00
Tanguy Pruvot e1575c5cb2 update README for v2.2.2 2017-10-09 20:11:22 +02:00
Tanguy Pruvot ed27598a7a import and clean hsr algo 2017-10-09 20:09:29 +02:00
Tanguy Pruvot cf18cb632c equihash: missing free on benchs 2017-10-09 15:54:54 +02:00
Tanguy Pruvot e505d1051d new --submit-stale parameter (#24) 2017-10-09 15:54:54 +02:00
Tanguy Pruvot 5a90db192a phi: maxwell opt (aes final + streebog)
+ fix the fugue leak..

Also update sib algo with this improvement
2017-10-09 15:54:48 +02:00
Tanguy Pruvot 3dbcc5dbbf Import phi algo (by anorganix)
only made a few changes to keep algos in the alpha order
2017-10-07 11:18:15 +02:00
Tanguy Pruvot 575aa1a0e4 ccminer: argument fix for 10th device selection 2017-10-05 13:18:24 +02:00
Tanguy Pruvot 4d09d856f6 readme: move ubuntu stuff in INSTALL file, no ads 2017-09-20 05:08:23 +02:00
cedric walter e3e848149c readme: add howto for ubuntu (#23)
tested on 17.10
2017-09-19 09:41:58 +02:00
Tanguy Pruvot ebf055d585 update c11 like tribus + 2.2.1 readme 2017-09-01 20:43:52 +02:00
Tanguy Pruvot d47dd9de39 tribus: optimised version for recent cards
main improvement is on echo, based on alexis sib kernel work

tested on SM 3.0 and more recent
2017-09-01 20:15:17 +02:00
Tanguy Pruvot 949061d223 xmr: disable huge pages if not defined #19 2017-08-27 19:17:57 +02:00
Tanguy Pruvot 1e71dc5782 streebog: apply skunk improvements to veltor 2017-08-16 13:43:10 +02:00
Tanguy Pruvot 6055af1fa9 skunk: proper indent and trim spaces 2017-08-14 04:06:03 +02:00
Tanguy Pruvot dfdf4b0691 now works with all CUDA versions 2017-08-13 21:04:56 +02:00
Tanguy Pruvot 5001a0cd1b update the README 2017-08-13 19:53:03 +02:00
Tanguy Pruvot 2e56177a2d small changes for the 2.2 release 2017-08-13 19:42:21 +02:00
Tanguy Pruvot 9a7d74eac4 skunk: merged kernel to use when possible
for now, only used for maxwell/pascal with cuda 7.5 or 8.0
2017-08-13 19:01:18 +02:00
Tanguy Pruvot 6e32ec2be0 wildkeccak: increase scratchpad buffer size + proxy 2017-08-07 12:31:08 +02:00
Tanguy Pruvot 9f113effd8 streebog: use TPB of 128 to reduce errors 2017-07-28 04:43:19 +02:00
Tanguy Pruvot 9c053042c9 cubehash: improve a bit and cleanup 2017-07-27 23:53:22 +02:00
Tanguy Pruvot 08a3f3402c readme: remove alexis addresses, on demand 2017-07-26 21:11:29 +02:00
Tanguy Pruvot 9c4b8caf1a nvapi: apply memory offsets like nvsettings 2017-07-24 14:16:14 +02:00
Tanguy Pruvot cbede12c47 Add skunk algo, initial version 2017-07-21 22:41:05 +02:00
Tanguy Pruvot 5aa50a4215 equihash: use client.show_message to get block height
current stratum is imcomplete and doesnt provide the coinbase data
2017-07-13 19:41:47 +02:00
Tanguy Pruvot 7ce3f2ccce tribus: handle jh80 midstate (+10%) 2017-07-07 18:15:08 +02:00
Tanguy Pruvot 807e141a4d equi: sm 2 test 2017-06-22 09:35:32 +02:00
Tanguy Pruvot 9dedec5ecd sysinfos: fix some file leaks 2017-06-22 07:38:40 +02:00
Tanguy Pruvot c120ecae1d handle the new tribus algo
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-06-15 07:32:04 +02:00
Tanguy Pruvot 1473a8fd6f nvs: fix fscanf return warning 2017-06-15 07:30:11 +02:00
Tanguy Pruvot 79f8f71fc3 fedora: note about the alternative method via rpms 2017-06-15 04:47:16 +02:00
Tanguy Pruvot 037bbe3ad3 sia: add missing cputest 2017-06-15 03:48:59 +02:00
Tanguy Pruvot 0f3fac9536 nvs: remove test with -n 2017-06-12 06:19:38 +00:00
Tanguy Pruvot bcadca2c45 linux: prepare nvidia-settings queries
Note: this method is slower than real apis and requires X opened
and configured correctly.

sample usage: -d 0,1 --mem-clock=+200,-200
2017-06-08 22:07:29 +02:00
Tanguy Pruvot 05abaf2b26 update readme and sample config 2017-05-24 00:11:27 +02:00
Tanguy Pruvot 21600491b8 update instructions for fedora 25
its a shame this distrib doesnt provide older gcc toolchains.. :/
2017-05-23 23:54:35 +02:00
Tanguy Pruvot 8cf21599d4 Interface nicehash djeZo equihash solver (squashed)
Todo:
    - send block height via stratum protocol (encoded in jobid?)
    - remove equi/blake2 cpu algorithm to use common one

the extranonce imcompatibility is related to the solver nonce data,
offsets may be reversed in nheqminer, to check...

The solver was adapted for SM 3.0+ support (no perf changes)

Note: The solver was not improved on purpose, to be able compare
the two miners performances (nheqminer 0.5c the last open sourced, and ccminer)

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>

stratum: code cleanup, move equi fns in equi folder
2017-05-23 23:54:35 +02:00
Tanguy Pruvot c44be3f81d api: various fixes
- prefer calloc to zero memory
- bind: keep the normal network read access with -b 0.0.0.0 like previous versions
- help: keep the write mode commands hidden in read-only mode
- close the socket on refused api calls to prevent client hangs
- small other changes
2017-05-23 23:53:58 +02:00
bitbandi 47472ed3f1 API restriction policy and multicast announces (#16)
same as sgminer, fixed to build (tpruvot), untested yet
2017-05-18 19:50:08 +02:00
Tanguy Pruvot b372729ce6 api: change api bind variable name 2017-05-16 12:09:32 +02:00
Tanguy Pruvot 857c1819c9 ccminer 2.0 final 2017-05-14 11:40:46 +02:00
Tanguy Pruvot e584f28441 fix quark and jackpot algos 2017-05-14 11:35:27 +02:00
Tanguy Pruvot 81d5f4e862 Improve project build compatibility (mac/vs2015)
This is incomplete, but is a first step...
2017-05-09 05:56:28 +02:00
Tanguy Pruvot 5dfeee45ec rewrite jha algo to be more compatible
old "german" implementation based on the quark method is kept
in the source tree, but is currently broken. to be continued.

This is a quick fix which should be compatible with all cards.
2017-05-08 08:03:55 +02:00
Tanguy Pruvot 762c7f8656 nvapi: fix plimit argument on x64
now use the same percents as the x86

nvml watts (like linux) could work but requires admin rights
2017-05-07 12:09:55 +02:00
Tanguy Pruvot e23b577e32 nvml: show product ids and pci bus in ccminer -D -n 2017-05-06 02:00:24 +02:00
Tanguy Pruvot 8e4d059a41 bitcore algo for linux users
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-05-03 11:12:50 +02:00
Tanguy Pruvot 063992b25b decred: handle new stake version field 2017-04-23 17:02:27 +02:00
Tanguy Pruvot d2f836119a vstudio: remove remains, move sha in tree
+ small code fixes
2017-04-23 17:02:27 +02:00
Tanguy Pruvot 6c9852c153 nvapi: fix weird code style 2017-04-21 13:20:31 +02:00
Tanguy Pruvot 80c755188d Add sha256d algo (bitcoin) btw...
even if it works on yiimp, the stratum diff is too high for gpus (for now)
2017-03-11 15:29:21 +01:00
Tanguy Pruvot 61231bc66c fix various memory leaks on algo switch 2017-03-11 11:19:20 +01:00
Tanguy Pruvot 0041bf47f1 wildkeccak: add credits and licence notice 2017-03-11 08:49:38 +01:00
Tanguy Pruvot 73f6720121 whirlpool: restore old source code for SM 3.0
SM 3.0 implementation need a manual define in whirlpool.cu...

alexis variant is 2x slower on SM3.0 (GT 740)
2017-03-08 15:59:51 +01:00
Tanguy Pruvot e388c11c02 blake2s fix and more missing cuda arch (for the benchmarks) 2017-03-08 13:13:52 +01:00
Tanguy Pruvot 2cdf2ddd43 Add missing real cuda arch checks 2017-03-08 09:19:10 +01:00
Tanguy Pruvot 18637503f2 whirlpool: upgrade with alexis variant (2x)
to check on older cards... maybe breaks some
2017-03-08 08:04:56 +01:00
Tanguy Pruvot de41bc9d21 update readme and use cuda 8 as default 2017-03-07 21:14:15 +01:00
Tanguy Pruvot 07ebcb544d timetravel algo
+ new kernels jh512-80 groestl-80 and cubehash-80

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-03-07 20:16:15 +01:00
Tanguy Pruvot 3ede61b0cc bastion algo
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-03-07 20:10:26 +01:00
Tanguy Pruvot 1b7c2fc296 lyra2z algo (temporary algo)
based on djm34 version, cleaned up and adapted to ccminer 2.0
2017-03-07 20:05:03 +01:00
Tanguy Pruvot ebef3c8656 sha256t algo (3x sha256, not sha256d)
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-03-07 19:32:59 +01:00
Tanguy Pruvot 3d70026ae6 hmq1725 algo
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-03-07 16:26:27 +01:00
Tanguy Pruvot 4d95ef4aec cuda: ensure the system can find the right lib
if you get this error on linux, its because libcudart.so.x.x was not found

ldconfig -p | grep libcudart.so.8.0
2017-02-17 19:00:51 +01:00
Tanguy Pruvot 1d5db48797 credits: show binary arch (32/64) in the header 2017-02-17 17:48:25 +01:00
Tanguy Pruvot b549bd54fe lyra2: clean the intelli-non-sense stuff 2017-02-08 12:21:36 +01:00
Tanguy Pruvot c66e8622b3 api: report per thread cpu hash checks (ACC/REJ)
+ update all algos for that...
2017-02-07 06:26:02 +01:00
Tanguy Pruvot 4da35e0bcf api: use MHz for all clocks and show plimit
plimit value is reported in mW like the power, or % on Windows x86 (via nvapi)

+ the monitor thread will no more report 0W if the device doesnt support it

also upgrade nvml and sample php api.

some more changes may come in this temporary API 1.9 (for the final 2.0)
2017-02-06 06:50:38 +01:00
Tanguy Pruvot 3fab2792fd lyra2: remove old debug traces 2017-02-06 04:38:43 +01:00
Tanguy Pruvot 916ec5047e logs: show solved count on solved shares 2017-02-05 14:06:51 +01:00
Tanguy Pruvot aaa24a6262 stats: submit real freqs and plimit to yiimp benchmarks 2017-02-05 13:20:38 +01:00
Tanguy Pruvot ef44e88ef9 ccminer: link --max-log-rate to the command line 2017-01-30 12:36:50 +00:00
Tanguy Pruvot b9da6c67f5 improve jh512 with vectors (nist5,quark,sib,x11+,zr5)
the main improvement is to reduce asm calls to read global mem

but, a few more regs are used (68 mini vs 64 on SM 5.2)
so reduce the forced launch bounds to allow 80 or 128 regs per thread

Note: cuda 6.5 seems not able to store with v4.u32... (7.5 is fine)
        st.global.v4.u32        [%rd2], {%r3783, %r3824, %r3823, %r3822};
        st.global.v2.u32        [%rd2+16], {%r3821, %r3820};
        st.global.u32   [%rd2+24], %r3819;
        st.global.u32   [%rd2+28], %r3818;
        st.global.u32   [%rd2+44], %r3814;
        st.global.u32   [%rd2+40], %r3815;
        ...

todo, check alexis variant.. but wanted to keep this code before in git...
2017-01-30 07:27:01 +01:00
Tanguy Pruvot 6440a9bf41 windows: some default intensity adjustments 2017-01-30 02:31:44 +01:00
Tanguy Pruvot 2152fd102d lbry cleanup, and proper error on cuda 6.5
both merged and unmerged implementations are broken with CUDA 6.5

No perf changes...
2017-01-30 02:31:28 +01:00
Tanguy Pruvot aaef92cab2 nvml: workaround for beta drivers 378.49 clocks
even nvidia-smi doesnt report the right pascal clocks
2017-01-29 22:23:05 +01:00
Tanguy Pruvot b47d9acaf5 readme + small warnings detected by vstudio 2017-01-29 22:23:05 +01:00
Tanguy Pruvot c8ff854456 sia was migrated too... 2017-01-29 06:10:08 +01:00
Tanguy Pruvot 0ff75791e5 migrate 2nd nonce storage of most algos
This allow to keep pdata[19] as cursor between scans, and later, to sort them..

remains... heavy, scrypt, sia...
2017-01-29 05:46:45 +01:00
Tanguy Pruvot 5a77d36635 groestl: explain code and improve perf on SM 2.x
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-01-29 00:51:42 +01:00
Tanguy Pruvot feb99d020f skein: merge the double implementations in one
based on alexis skein kernels, tested ok on SM 2.1 and 3.0

code is a bit hard to read but... well... users dont care :p
2017-01-29 00:01:06 +01:00
Tanguy Pruvot 16ac9b688f x13+: improve and clean a bit fugue512
reduce constant mem and load global data in bulk (vectors)
2017-01-29 00:00:43 +01:00
Tanguy Pruvot 013cda1cd2 ccminer: show first block diff even with -q 2017-01-29 00:00:28 +01:00
Tanguy Pruvot 496052e47d xmr: vstudio warning fix about mpcount linkage
and move ptr type cast defines to common cuda helper
2017-01-25 21:16:31 +00:00
Tanguy Pruvot dc816b4673 xmr: nicehash nonce prefix/hack support (v2) 2017-01-22 23:19:22 +01:00
Tanguy Pruvot def9888bd5 xmr: prefer 32bit uint4 and smaller offsets in core
also prefer ulong2 shared load to be closer to the ptx
2017-01-16 06:36:24 +01:00
Tanguy Pruvot 214f392778 xmr: default settings with card attributes 2017-01-15 01:42:25 +01:00
Tanguy Pruvot 94aa6b8e91 ccminer: allow 192 car. for the username 2017-01-14 18:55:36 +01:00
Tanguy Pruvot 588c7ba361 xmr: dont use shared mem hack, windows dont like 2017-01-14 15:13:31 +01:00
Tanguy Pruvot bd030db5d1 xmr: vectors rewrite, now the phase2 is using only 40 regs
no more constant memory used for aes.

tested only on linux cuda 8 for now... wip
2017-01-14 04:34:23 +01:00
Tanguy Pruvot 23be7f308d xmr: link the --bfactor setting (0-11) 2017-01-12 23:02:00 +01:00
Tanguy Pruvot e231343060 xmr: make it more smooth on windows with defaults
also improve a bit the 750 ti on linux...
2017-01-12 06:00:59 +01:00
Tanguy Pruvot 12ae185594 hwmonitor: efficiency unit and clean dead code 2017-01-10 14:20:33 +01:00
Tanguy Pruvot 0dd022779b power monitoring thread + some api changes
based on alexis monitoring thread idea, but which only use one thread

note: other api changes will come soon, related to that
2017-01-10 02:26:28 +00:00
Tanguy Pruvot 242aa4144b scanlog: remember sharediff for multiple nonces
rpc2: handle properly secondary nonce(s) + api ping time fix

be sure to fully recompile, structures are changed
2017-01-09 18:40:00 +01:00
Tanguy Pruvot 93adb56c8e handle cryptonight light variant
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2017-01-09 18:30:59 +01:00
Tanguy Pruvot 39aad5a003 xmr: allow to set intensity on command line 2017-01-08 22:36:03 +00:00
Tanguy Pruvot 804b5b5f53 xmr: be safe with diff divide 2017-01-08 21:28:54 +00:00
Tanguy Pruvot 2479ffaaa2 xmr: fix decimal diff + aes cleanup
change default launch config to -l 32x16 to handle the 750 Ti better
not definitive, doing tests..
2017-01-08 21:16:45 +00:00
Tanguy Pruvot c1f1ad9280 xmr: stabilize the final kernel 2017-01-08 14:39:13 +01:00
Tanguy Pruvot 066a569357 import xmr, to finish
todo: fix jh cuda and wrong decimal diff (0xffff problem ?)
2017-01-07 01:40:59 +01:00
Tanguy Pruvot 2bbccc5ff4 wildkeccak, basic stratum port of rpc 2.0
scratchpad delete fix and redownload, reduce rejects

(work in progress)
2017-01-06 08:55:15 +01:00
Tanguy Pruvot 099389f64f ccminer: be more quiet with -q, skip header noise 2016-12-30 15:18:35 +01:00
Tanguy Pruvot 50534789bc Release 1.8.4 2016-12-21 20:35:09 +01:00
Tanguy Pruvot c11901260a limit per gpu hashrate logs to 3 sec intervals
may be required for very fast algos, like blake2s
2016-12-21 20:16:47 +01:00
Tanguy Pruvot 44bd244fc4 blake2s improved
based on alexis work, with the new work->nonces
2016-12-21 19:44:20 +01:00
Tanguy Pruvot ce6a8da188 cuda: prevent ptxas crash with -n 2016-12-18 03:35:19 +01:00
Tanguy Pruvot 397472818d prepare 1.8.4 release 2016-11-03 18:55:42 +01:00
Tanguy Pruvot 36aedbb48e veltor update, 10x faster :p
From Alexis work, sib hash rate 200% also..
2016-11-03 18:54:29 +01:00
Tanguy Pruvot 3eba451d4c nvml: add Elsa vendor and workaround for Colorful pid
Colorful (and Inno3D) only set their vid, with an empty product id
2016-10-25 03:40:07 +02:00
Tanguy Pruvot c27f3139aa update startup credits 2016-10-06 13:08:41 +02:00
Tanguy Pruvot 056098dd86 update readme 2016-09-29 03:37:36 +02:00
Tanguy Pruvot 7b82915032 cuda 8 2016-09-29 00:40:06 +02:00
Tanguy Pruvot 225f25a6b9 uint2: remove the slower asm in operators funcs 2016-09-28 07:12:05 +02:00
Tanguy Pruvot 665de3a1f2 sia: use the new work share diff 2016-09-28 01:28:04 +02:00
Tanguy Pruvot 1a31d4d2d6 sia: move specific code in a new rpc unit
part 1: longpoll stuff (nanopool)
2016-09-28 01:27:57 +02:00
Tanguy Pruvot f84c83afe5 nvml: force 64bits types for mem sizes
size_t can be a bit... imprevisible on x86
2016-09-28 00:31:13 +02:00
Tanguy Pruvot 5a0b779434 api: use the new throughput2intensity func 2016-09-27 23:20:28 +02:00
Tanguy Pruvot a43205a84f decred: multiple nonces code cleanup
The double loop is not useful, and prefer the __thread attribute
to enhance the code readability (remove the 2D host arrays).

squashed: return to host 2D array to allow the free
2016-09-27 22:50:52 +02:00
Tanguy Pruvot 6f6cf966f8 lbry: new share diff and duplicate fix
when 2 nonces were found, the next scan was not at the right value

Doesn't really affect mining performance...
2016-09-27 22:50:51 +02:00
Tanguy Pruvot 9eead77027 diff: show by default, rework shares diff storage
This will allow later more gpu candidates.

Note: This is an unfinished work, we keep the previous behavior for now
To finish this, all algos solutions should be migrated and submitted nonces attributes stored.
Its required to handle the different share diff per nonce and fix the possible solved count error (if 1/2 nonces is solved).
2016-09-27 09:03:24 +02:00
Tanguy Pruvot 2f57ee9157 bench: skip the disabled whirlpoolx
+ veltor free
+ some missed/extra log things...
2016-09-27 01:41:49 +02:00
Tanguy Pruvot 009b013d25 nist5: rename and move source file
build tip: autoreconf && make -j
2016-09-27 00:57:31 +02:00
Tanguy Pruvot 0f8271f849 vstudio: return to CUDA 6.5 by default on x86
change was for the 1.8.2 tag (optimal for lbry)

and prepare next version...
2016-09-27 00:38:18 +02:00
Tanguy Pruvot c933ad901e sia: add missing algo in --help 2016-09-27 00:33:11 +02:00
Tanguy Pruvot 34e97bf3e6 Show intensity on init for all algos 2016-09-27 00:33:06 +02:00
Tanguy Pruvot 65cd430d76 cuda: throughput2intensity function to show default 2016-09-27 00:20:48 +02:00
Tanguy Pruvot 9f2ed5135b lbry maxwell and pascal update (up to 10% on pascal)
Based on alexis78 work and sponsored by LBRY.IO team (thanks)

Release 1.8.2, use cuda 8 for x86
2016-09-22 19:37:17 +02:00
Tanguy Pruvot f982fd70d5 lbry: small sha512 improvement 2016-09-04 18:11:42 +02:00
Tanguy Pruvot f8aa16f8d2 skein: cleanup, and precompute h8 2016-09-04 18:11:42 +02:00
Tanguy Pruvot 683dc0e149 VeltorCoin Streebog based algo (veltor)
also known as "Thor's Riddle"... yes sure ;)

Credits to ocminer who found and "implemented" it.

Note: tested "ok" on x64 and CUDA 6.5 x86, not on 7.5 and 8.0 x86

PS: Don't have the time for a more proper CUDA implementation of Streebog
2016-08-18 18:47:37 +02:00
Tanguy Pruvot 8f965c2cb2 windows: prevent system sleep while mining 2016-08-16 18:00:16 +02:00
Tanguy Pruvot 1a51a84a94 sia: small mutex fix on errors 2016-08-10 14:48:19 +02:00
Tanguy Pruvot 2520f9a388 lyra2: import latest nanashi code (v1) 2016-08-10 14:23:18 +02:00
Tanguy Pruvot 35bfe8d191 update version 2016-08-09 22:56:52 +02:00
Tanguy Pruvot d8e518ac3d sia: support for nanopool http protocol
-o http://xxxx:port -u <addr> -p <worker>

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-08-09 22:55:53 +02:00
Tanguy Pruvot b31fb5316b sia: cuda impl. and suprnova getwork over stratum
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-08-06 12:56:35 +02:00
Tanguy Pruvot 3d701944b2 lbry: exit on card failure, dont loop 2016-08-06 12:56:34 +02:00
Tanguy Pruvot 883fb19908 lbry: some changes from alexis, remove shared mem
105 LBC tipped ;)
2016-08-06 12:56:02 +02:00
Tanguy Pruvot de738ccc2b x11: secure groestl against possible cuda errors
big cleanup...
2016-08-06 12:56:02 +02:00
Tanguy Pruvot 0a0fd33cac attempt to reduce shared mem errors 2016-08-06 12:56:02 +02:00
Tanguy Pruvot 8985f7ee91 nvapi: asus rgb led
seems to be too slow to handle all wanted modes
2016-08-06 12:51:23 +02:00
Tanguy Pruvot 9123eff7dd Update Galax vendor id, used on 1070s 2016-07-25 16:37:00 +02:00
Tanguy Pruvot af1d5c9f3d nvapi: zotac rgb led support, to improve..
zotac cards doesnt allow a real RGB value, so i converted manually
the card seems to handle it, but seems to lock sometimes for some time...

colors can be tested with "ccminer -d 2 --led=0x1f1f00 -Dn"

but... unsure the card handle it fast enough to be fully usable
2016-07-22 01:20:30 +02:00
Tanguy Pruvot 78c3d25ccf release 1.8, as promised 2016-07-20 10:28:50 +02:00
Tanguy Pruvot be8be03eb8 neoscrypt: remove warnings and rename host funcs
also reduce the few errors on coins using shared mem
2016-07-20 10:26:42 +02:00
Tanguy Pruvot 6abee0659e update neoscrypt with Nanashi changes 2016-07-20 10:26:42 +02:00
Tanguy Pruvot bf17f34001 preview 3, with alexis78 touch 2016-07-20 10:26:13 +02:00
Tanguy Pruvot 223077d11a merged sha256d/ripemd
drop ripemd.cu and remove unused kernels
2016-07-16 22:29:12 +02:00
Tanguy Pruvot 940c1b3a2f lbry: small changes for second build
sha512/ripemd swab

this was preview 2
2016-07-16 22:28:48 +02:00
Tanguy Pruvot 5703a74e22 lbry algo (stratum only)
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-07-13 09:44:13 +02:00
Tanguy Pruvot dbb9507d2b api: change unit of device mem to MB
without that, no way to read sizes > 4GB on x86 binaries
2016-07-10 13:12:16 +02:00
Tanguy Pruvot 4ca7b5a404 neoscrypt: reduce spill load and increase pascal def intensity
1 MH/s reached on the 1070 ...
2016-07-09 23:39:15 +02:00
Tanguy Pruvot 26a862c7f6 neoscrypt: reduce a bit the cpu usage 2016-07-08 20:04:45 +02:00
Tanguy Pruvot a4196b341d neoscrypt: apply last VTC improvements
rewrote almost properly ;)
2016-07-08 16:30:26 +02:00
Tanguy Pruvot c0e9370ba2 quark: real hashrate was wrong, add a few kHs 2016-07-06 16:35:58 +02:00
Tanguy Pruvot 06e2485128 myr-gr: handle a second nonce & more cleanup 2016-07-05 13:06:51 +02:00
Tanguy Pruvot 374174c7c8 groestl: same, remove useless host alloc 2016-07-05 11:15:06 +02:00
Tanguy Pruvot 3fe4dda4c1 myr-gr: remove unused allocated memory + pascal tweak
+ cleanup...
2016-07-05 09:56:48 +02:00
Tanguy Pruvot 39d0e42b11 improve the --led values parsing
sample usage if GPU #0 is RVB and GPU #1 a generic led:

ccminer --led=0x00ff00,100,mining to put the led on while the gpus are scanning
2016-07-04 16:31:07 +02:00
Tanguy Pruvot fc1472b5f7 nvapi: allow different led modes (mining,shares) 2016-07-04 09:14:19 +02:00
Tanguy Pruvot 0e942bf60c nvapi: proper rgb color dimm function 2016-07-03 18:46:40 +02:00
Tanguy Pruvot d43084cec6 nvapi: improve rgb led stability + multi gpus 2016-07-03 18:25:38 +02:00
Tanguy Pruvot 8c4b25426f nvapi: device led flash on submit
disabled by default, require --led=100 on nvidia compatible devices

Gigabyte RGB led hack is not perfect for the moment, can fail and require a reboot.
2016-07-03 12:07:37 +02:00
Tanguy Pruvot 174e26164a nvapi: fix device mapping in -D -n
and rename RVB to RGB, french typo...
2016-07-02 20:21:33 +02:00
Tanguy Pruvot 036473347e nvapi: fan level, for future use... maybe 2016-07-01 20:13:47 +02:00
Tanguy Pruvot 24436febd6 led: proper log format 2016-07-01 20:13:17 +02:00
Tanguy Pruvot d3976cf38d nvapi: sample i2c rvb led color (gigabyte)
you can now use --led=0xFF00FF to change the color/level (windows only)

for non-rvb standard nvidia devices, you can use a level value (0 to 100)

ps: i really need to find how to turn them off on linux, not found yet...
2016-06-29 12:28:38 +02:00
Tanguy Pruvot 801db3d076 nvapi: be more secure with unsupported apis
also query the led level and fix OV delta output

note: the Gigabyte 1080 G1 seems not compatible with the current nvapi
2016-06-29 12:00:40 +02:00
Tanguy Pruvot eb84ef9c8a vendors: add Palit and the right PNY VIDs
seen on yiimp benchs, PNY duplicate could be for usb keys only
2016-06-28 01:39:53 +02:00
Tanguy Pruvot 095f25f9a8 nvapi: pascal core voltage boost + meminfo fix x86
cuda 6.5 one seems to crash on pascal or report invalid mem sizes
2016-06-26 22:30:54 +02:00
Tanguy Pruvot 0555201384 linux: return to default cuda, mistake in a nvapi commit 2016-06-26 20:31:31 +02:00
Tanguy Pruvot d19039fd7f nvapi: read pascal voltage + show meminfo in -Dn
also add perf stats api, unsure what it is exactly..
2016-06-26 08:28:44 +02:00
Tanguy Pruvot 7ff179abe9 nvapi: base memclock was wrong on maxwell 2016-06-25 16:18:39 +02:00
Tanguy Pruvot bc6ac3a3ab nvapi: link clocks and tlimit to command line
boost clocks and the thermal limit are shared with afterburner
beware with your settings, not as safe as application clocks!

Note: both nvapi and nvml are now used on windows x64
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-06-25 10:00:43 +02:00
Tanguy Pruvot 2ee8bc9791 nvapi: do not print that on normal -D 2016-06-24 10:14:58 +02:00
Tanguy Pruvot bdc441ebd0 nvapi: link some more apis, pascal boost table
these informations are shown with ccminer -D -n
2016-06-24 10:06:54 +02:00
Tanguy Pruvot eae4ede111 decred: return to previous implementation + second nonce
seems better on windows and a bit easier to read...
2016-06-23 03:54:33 +02:00
Tanguy Pruvot c643b3b900 decred: and even faster implementation by Alexis
optimized for the 9xx and more recent, same results on the 750 Ti
+ restore second nonce support not present in nicehash published version

Better on linux at least...
2016-06-23 00:36:28 +02:00
Tanguy Pruvot 7e490693e0 decred: nicehash/alexis improvement 2016-06-22 22:32:23 +02:00
Tanguy Pruvot 9296d5218e nvml: remove autoboost functions, unsupported
not for GTX pascal neither...
2016-06-21 05:16:21 +02:00
Tanguy Pruvot 0deb9a2aca win32: implement a nvapi.dll wrapper like nvml
Allow to get/set missing infos like the power limit on x86

squashed for a better min/max and device mapping

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-06-21 05:16:12 +02:00
Tanguy Pruvot 7a8ae1ab7a update static nvapi lib to R361 v2 (Jan 2016) 2016-06-21 03:00:44 +02:00
Tanguy Pruvot fd757f2180 nvml: add new getclock api (v8)
+ some new functions to test on pascal (if supported)
2016-06-20 07:32:26 +02:00
Tanguy Pruvot fe99de24a8 nvml: small changes to handle the 750ti app clocks
dynamically alloc the hardcoded gpu clocks list array size.

Unlike the 9xx, the 750ti api call requires to get them all (361.62)

Something was "fixed" recently for the 750 Ti in linux drivers...
2016-06-19 20:13:01 +02:00
Tanguy Pruvot 41a68f8f78 lyra2v2 fix define position 2016-06-11 13:37:51 +02:00
Tanguy Pruvot bbd3c6d5b9 lyra2v2: update credits, increase SM 5.0 default int to 19
+ small klausT cleanup..
2016-06-10 21:50:00 +02:00
Tanguy Pruvot 53275e3a00 Apply lyra2v2 boost published by NH
changes only tested/applied to SM 5+ with some cleanup
2016-06-09 21:12:09 +02:00
Tanguy Pruvot 8ecf0a9101 nist5: reported ccminer hashrate was wrong 2016-06-08 19:29:16 +02:00
Tanguy Pruvot 85c212eaad implement x11evo algo
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-05-31 20:05:15 +02:00
Tanguy Pruvot f85e3772f9 api: sample command line api call in perl
tx to lilyth for the idea (works on cpuminer, sgminer and cgminer too)
2016-05-31 19:20:58 +02:00
Tanguy Pruvot a7905e6802 some changes to prepare 1.8 and VS2015 support
also move vstudio specific cpuminer-config.h in compat/
2016-05-28 06:27:41 +02:00
Tanguy Pruvot 1b124720fe fix vote default value for suprnova 2016-05-20 22:27:48 +02:00
Tanguy Pruvot 282129f584 linux: add temporary cuda files to gitignore 2016-05-20 22:27:48 +02:00
Tanguy Pruvot 4a8e3d9aaa increase the max password len to 384
and handle the benchmark yiimp guest user for stats
2016-05-18 23:09:54 +02:00
Tanguy Pruvot 710d9292af fix duplicates on skein2 and blake2s (nonce endian) 2016-05-18 02:53:53 +02:00
Tanguy Pruvot 8658718791 linux: skein2.cu doesnt exist 2016-05-17 22:21:29 +02:00
Tanguy Pruvot 415b01f2c0 stats: submit also kernel cuda arch if different
depends on compile options...
2016-05-17 22:07:26 +02:00
Tanguy Pruvot 1c3a95213d nvml: do average on milliwatts reading
and ignore nvapi percents in pool stats

also allow decimals in intensity
2016-05-17 22:07:25 +02:00
Tanguy Pruvot b6a2c5c2ec handle option --shares-limit like sgminer --shares
--shares alone was confusing imo, but it also works on command line

Allowed in multi pool settings too...
2016-05-17 22:07:21 +02:00
Tanguy Pruvot b1db3a230b linux: allow to compile on ubuntu 16.04 2016-05-17 20:27:56 +02:00
Tanguy Pruvot e22aca94f1 stats: fix get_stats answer when not allowed
ccminer was answering both the error and the data

also remove the get_version stats hack...
2016-05-16 22:09:35 +02:00
Tanguy Pruvot ee042e5381 linux: missed to remove one PCI tag 2016-05-16 21:42:02 +02:00
Tanguy Pruvot a1d448d4e0 linux: disable pcidev stuff, no more required 2016-05-16 16:31:14 +02:00
Tanguy Pruvot 35b728907c nvapi: product id was wrong when subsystem id is set
also test its filled... (cf Inno3D), use generic nvidia ids else
2016-05-15 21:14:27 +02:00
Tanguy Pruvot dcbcf6ba7e stratum: improve and add new methods for pool benchmark/stats
will allow to submit some device benchmark data to compute algo
power usage and profitability.

Introduce two new methods mining.get_algo and mining_get_stats
These methods will be used with yiimp stratum with a special benchmark option
Note: only the first card is handled for the moment.

also add stratum mining.ping support (like cgminer 4.7.1+) and prevent disconnect
on unknown methods, reply it is unsupported.
2016-05-15 18:18:45 +02:00
Tanguy Pruvot 81051dd75f x17: restore nonceVector parameters
could be used by new algos
2016-05-10 13:44:01 +02:00
Tanguy Pruvot 8d67f0f774 project: CUDA 7.5 for x64 target, and 6.5 for x86 2016-05-09 17:10:34 +02:00
Tanguy Pruvot 929eb7ce3d we are in 2016... oops 2016-05-09 16:38:24 +02:00
Tanguy Pruvot dad0110557 x17 cleanup
haval256 is now 2x faster, but sha512 perf depends a lot on cuda version...
2016-05-09 16:34:18 +02:00
Tanguy Pruvot e7ed0dea5f api: small css fix 2016-05-08 18:14:22 +02:00
Tanguy Pruvot 838f108dd4 decred: last vote bit should not be changed 2016-04-16 02:44:50 +02:00
Tanguy Pruvot fbd30f784c decred: set maxregcount to reach linux speeds 2016-04-07 01:44:36 +02:00
Tanguy Pruvot 446e1abd66 decred: keep first protocol without the vote arg
argh... suprnova again...
2016-04-06 18:13:54 +02:00
Tanguy Pruvot c0fca5c932 decred: magic improvement in one line
+ ifdef the 4WAY commented code...
2016-04-04 17:49:54 +02:00
pallas1 ebf885d482 ~10% speedup 2016-04-02 22:21:31 +02:00
alexis78 be1f64446a vanilla: sync with MrM4D, remove SSE2 midstate computation
was not useful and hard to read...
2016-03-23 11:39:34 +01:00
Tanguy Pruvot 054af6526c decred: link the --vote parameter
without param or 0 = no vote, valid choices will start to 1..

stratum + getwork
2016-03-19 09:27:03 +01:00
Tanguy Pruvot 1d111c0ec1 prepare next version 2016-03-19 09:26:23 +01:00
Tanguy Pruvot 5a69056ee5 blake2s cleanup 2016-03-13 19:36:01 +01:00
Tanguy Pruvot 7ffe65c262 blake2s algo
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-03-13 16:50:32 +01:00
Tanguy Pruvot 24f452adf6 decred: missed --help 2016-03-02 00:11:26 +01:00
Tanguy Pruvot 6f4a1baa00 official release, 1.7.4
multiple 1.7.3 preview versions were compiled during the decred stratum
tests. Please use this newer version.
2016-02-28 18:36:16 +01:00
Tanguy Pruvot d58490911a decred: remove some useless double flip 2016-02-28 18:19:32 +01:00
Tanguy Pruvot 35738cec23 api: add stales and pools algo/name
+ remove hardcoded stales check on suprnova...
2016-02-27 17:48:42 +01:00
Tanguy Pruvot e1fd687b9b count pool stales + suprnova workaround
there was a weird job id problem not seen on yiimp stratum
2016-02-24 01:33:55 +01:00
Tanguy Pruvot 099195e39d decred: use given extradata... 2016-02-21 14:58:31 +01:00
Tanguy Pruvot f2f11b2331 getwork: fix reggression with normal work size 2016-02-20 19:41:26 +01:00
Tanguy Pruvot 7a62bf37fa decred: a bit more clean... 2016-02-19 18:06:24 +01:00
Tanguy Pruvot a823cca7f9 decred: allow custom extranonce sizes
the extranonce is already placed after header in job.coinbase
2016-02-19 15:52:17 +01:00
Tanguy Pruvot c3c977da04 fully remove whirlpoolx for builds 2016-02-19 15:52:17 +01:00
Tanguy Pruvot 096f136c36 enhance vanilla second nonce check 2016-02-19 11:31:00 +01:00
Tanguy Pruvot 4944e1a098 mrM4D vnl, with some changes 2016-02-19 11:31:00 +01:00
Tanguy Pruvot 08d58aebb1 release notes 2016-02-19 11:30:24 +01:00
Tanguy Pruvot 7c9ec8629f decred: handle a second nonce 2016-02-18 22:47:03 +01:00
Tanguy Pruvot 6cd53a2305 decred: quick fix for low net diff (testnet) 2016-02-18 12:36:56 +01:00
Tanguy Pruvot b0617ba0fc Revert "decred: prepare full stratum support"
This reverts commit 4e769915d8.

proper v1.7.3 for yiimp
2016-02-18 11:22:50 +01:00
Tanguy Pruvot 4e769915d8 decred: prepare full stratum support 2016-02-15 08:46:32 +01:00
Tanguy Pruvot 7d4c48d1d8 1.7.3 stratum test 2016-02-13 16:14:57 +01:00
Tanguy Pruvot 7fd2df5ba9 stratum: missing bloc height notif + range 2016-02-12 21:32:22 +01:00
Tanguy Pruvot 9bb9af49b2 decred: stratum tests with extranonce field
This implementation doesnt compute the merkle root, but allow
to mine on yiimp with the help of decred extradata fields.

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-02-12 14:45:54 +01:00
Tanguy Pruvot fc27c25436 windows builds cleanup 2016-02-11 07:57:44 +01:00
Tanguy Pruvot e18355ea9a release 1.7.2 2016-02-11 07:28:23 +01:00
Tanguy Pruvot 47530cf9ba ssl: allow certs from another machine 2016-02-11 07:10:54 +01:00
Tanguy Pruvot fcf6c1167b README 2016-02-11 07:10:54 +01:00
Tanguy Pruvot 6e95407dcf decred algo for longpoll/getwork
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-02-11 07:10:46 +01:00
djm34 6e9fe540b6 allow to compile with cuda 7.5 2016-02-04 19:20:54 +01:00
Tanguy Pruvot e584c86d88 cuda 7.5 test 2016-02-04 19:20:54 +01:00
Tanguy Pruvot da64c50059 blake: some more tuning and cleanup 2016-01-31 17:07:11 +01:00
Tanguy Pruvot 7c1137f335 blake: small change for the second nonce 2016-01-28 03:05:25 +01:00
Tanguy Pruvot 934f0e5054 blake: reduce intensity (and fix older devices) 2016-01-27 20:04:19 +01:00
Tanguy Pruvot 4a7e239d7c blake: merge sp improvements, start 1.7.2 dev..
to be tested on old arch too...
2016-01-27 18:30:06 +01:00
Tanguy Pruvot a237601747 1.7.1 release
set schedule flags to reduce linux cpu usage without MyStreamSynchronize()
2016-01-26 20:43:16 +01:00
xCoreDev 2e16d00f63 vanilla algo (Blake256 8 rounds - double sha256) 2016-01-26 19:01:42 +01:00
Tanguy Pruvot 76a22479b1 whirlpool midstate and debug/trace defines
+ new cuda_debug.cuh include to trace gpu data

Happy new year!

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2016-01-01 10:40:26 +01:00
Tanguy Pruvot 394d50987c x15/whirlpool: improve hash rate and reduce cpu usage
also do some define's clean up
2016-01-01 08:04:26 +01:00
Tanguy Pruvot 8ceb5cfd65 sib: add missing algo free entry + opt 64 2016-01-01 07:58:59 +01:00
Tanguy Pruvot d796a801c5 readme and vstudio project 2015-12-31 19:20:33 +01:00
Tanguy Pruvot e75b26feb4 sib coin algo (X11 + Streebog)
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-12-31 19:11:48 +01:00
Tanguy Pruvot 0cc87b68a9 bignum: some x64 warning fixes (vstudio) 2015-12-18 19:48:53 +01:00
Tanguy Pruvot a4404bc325 Add advanced resume options for conditional mining
only available for single pool, in multi, max-xxx rotates the pool
2015-12-18 19:48:52 +01:00
Tanguy Pruvot be73cd1ae0 improve the device mapping and a possible segfault
when using -n, work_restart array was not allocated
2015-12-03 15:03:19 +01:00
Tanguy Pruvot 5fb84189b2 nvml: fix possible mismatch of vendor names (x64)
seen on a weird motherboard with a PCI Express Switch (MSI XPower Z87)

On this motherboard, the first/top device pci id is the highest one...
2015-12-03 14:25:35 +01:00
Tanguy Pruvot 55932ee6f0 update windows version info 2015-11-08 15:17:42 +01:00
Tanguy Pruvot 94d86ca3b3 lyra2v2: fix tpb condition for SM 5.2 2015-11-06 20:59:42 +01:00
Tanguy Pruvot 41543b5c0b lyra2v2: add support for SM 2.1 devices
and improve a bit SM 3 perf
2015-11-06 19:40:23 +01:00
Tanguy Pruvot e4476a5eee reduce crashes on debug tests 2015-11-06 19:40:14 +01:00
Tanguy Pruvot d7c2168f2b quark: static shared memory allocation for SM3+
from KlausT committed on 4 Jan, add a few kH/s
2015-11-06 15:16:43 +01:00
Tanguy Pruvot 64e14b7d82 quark: final cleanup for the 1.7 2015-11-06 14:55:43 +01:00
Tanguy Pruvot 2247605d23 quark: add support for SM 2 devices
todo: use nonce vectors for the second branch

GPU #0: Gigabyte GTX 460, 261.26 kH/s
accepted: 2/2 (diff 0.046), 254.36 kH/s yay!!!

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-11-06 04:10:06 +01:00
Tanguy Pruvot 21115b7fc6 scrypt: link texture-cache parameter 2015-11-05 17:06:35 +01:00
Tanguy Pruvot e50556b637 various changes, cleanup for the release
small fixes to handle better the multi thread per gpu

explicitly report than quark is not compatible with SM 2.1 (compact shuffle)
2015-11-04 14:59:59 +01:00
Tanguy Pruvot 1e3db41a8d multialgo: clear hashrate stats on switch 2015-11-02 19:05:43 +01:00
Tanguy Pruvot e9b88b45e4 prepare the 1.7 release 2015-11-02 17:52:24 +01:00
Tanguy Pruvot d3e2088398 basic pool algo switch (without free barrier)
not really proper but should works for 2 "small" algos.

just put the "algo" param in each pools config
2015-11-02 17:52:24 +01:00
Tanguy Pruvot 113e22de2e blake: prevent empty scan ranges with multiple gpus
in some cases, an empty scan range was possible in benchmark..
2015-11-01 22:14:17 +01:00
Tanguy Pruvot 61ff92b5b4 never interrupt global benchmark with found nonces
fix some algo weird hashrates (like blake)
and reset device between algos, for better accuracy

but this reset doesnt seems enough to bench all algos correctly...

to test on linux, could be a driver issue...

heavy: fix first alloc and indent with tabs...
2015-11-01 21:12:50 +01:00
Tanguy Pruvot 2308f555c3 simd: cleanup and ignore linux host warning 2015-11-01 13:35:36 +01:00
Tanguy Pruvot 0d9d3520ac simd: add support for SM 2.1 devices
Add support for x11..x17, s3, fresh and qubit

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-11-01 12:37:52 +01:00
Tanguy Pruvot 03b2bddc16 lyra2v2: fix SM 3.5 support
May work also on SM 3.0 (to check)
2015-10-29 13:10:41 +00:00
Tanguy Pruvot 47f309ffb4 ifdef some unused kernels on SM5+
no need to build both (mine and sm variants)

and put global hashrate to 0 while waiting...
2015-10-28 07:25:52 +01:00
Tanguy Pruvot 2673b3aeff stratum: hide timeout warnings while waiting
this timeout is not important, we reconnect after
2015-10-26 09:17:00 +01:00
Tanguy Pruvot c4d6310143 heavy: fix define typo, else it works with cuda 7.5 2015-10-26 08:41:50 +01:00
Tanguy Pruvot 31bd1697b1 heavy: workaround to build on ubuntu 15.10
gcc 5.2.1 with cuda 6.5.19 give a weird C++ error
2015-10-25 11:13:52 +01:00
Tanguy Pruvot 8d4d4d65ce cuda: header for common kernel functions (quark/x11)
Was thinking about doing that since months ;) lets go
2015-10-25 06:54:17 +01:00
Tanguy Pruvot 26c7316a08 vstudio: clean and fix blake ifdef for x64
the allocated var was not used... sigh
2015-10-24 18:21:45 +02:00
Tanguy Pruvot 2d83f74a7e vstudio: special ifdef for the constant (bmw) 2015-10-24 15:13:35 +02:00
Tanguy Pruvot 098310abc6 pentablake: use common blake kernels (quark)
reduce the binary size and improve the speed...
2015-10-24 14:18:16 +02:00
Tanguy Pruvot d43dc9a021 use blake512 sp kernels on SM 5+ (80+64)
import and keep my code for older archs, like skein 64

reduce the gap between our versions...

+150kH x11   GTX 960 / +30kH  750Ti
+900kH quark GTX 960 / +230kH 750Ti
2015-10-24 13:43:22 +02:00
Tanguy Pruvot e12d666d36 pool switch: add thr_id param to handle a future barrier
Switching to a pool with a different algo will require a barrier
to free ressources, like what was made in the global benchmark.

add also the algo in pool structure...
2015-10-24 09:58:25 +02:00
Tanguy Pruvot 957d919a6a bmw512: save a few KBs, ifdef 80-bytes kernel
was only used by animecoin

Also ifdef SM 3.0 compat. code to be ignored on recent archs
2015-10-24 07:30:57 +02:00
Tanguy Pruvot 3b7ef923c7 lyra2(v1): use a common uint2x4 include
lyrav2 still need more definitions (uint16)
2015-10-23 15:25:24 +02:00
Tanguy Pruvot 82a7e62b30 skein: cleanup, strip uint2x4.h + update vstudio 2015-10-23 13:32:18 +02:00
Tanguy Pruvot ef817df79a import sp skein512 unrolled 64-bytes kernel (+0,6% x11)
Quark and S3 are now a bit faster (+1 %)
x11 get +0.6 % (+20kH/s on a 750ti, +30kH on a 960)

80 bytes implementation to do/test ... (skein/skein2)

but keep my previous version for older devices...
2015-10-23 09:43:20 +02:00
Tanguy Pruvot dec6dbed77 api: add best share diff and last share time
best share diff require --show-diff

shown in the "pool" command
2015-10-22 15:11:16 +02:00
Tanguy Pruvot e90ade048a ndevs: get vendor names on windows too
ccminer -n 2>NUL

GPU #0: SM 5.2 GeForce GTX 970
GPU #1: SM 5.0 Gigabyte GTX 750 Ti
GPU #2: SM 5.2 ASUS GTX 970

note: nvml destroy is made in proper_exit function
2015-10-22 13:36:46 +02:00
Tanguy Pruvot 59a6cd133b nvapi: x86 can also get sub vendor ids 2015-10-22 12:29:03 +02:00
Tanguy Pruvot 355b835ae0 benchmark: enhance the mem leak detection
reduce "false" warnings, and ignore unrelated/small ones <= 1 MB

On windows the gpu memory can be allocated by other processes

+ some cleanup in algos... (free/gpulog)
2015-10-16 22:04:30 +02:00
Tanguy Pruvot 4868c412b0 windows: add support for SM 2.1, drop SM 3.5 (x86)
Mostly to do compatibilty tests, SM 2.1 support is very limited

SM 3.0 code should run on SM 3.5 (only a few cards use this arch)

As i can't test SM 3.5, its best to let users do their own tests...
2015-10-15 23:02:35 +02:00
Tanguy Pruvot a7d54cd7ef blake: no need to fail on init, no big alloc 2015-10-15 20:10:58 +02:00
Tanguy Pruvot c3d10db873 algos: move cmdline algo/alias parser in a func 2015-10-15 08:49:40 +02:00
Tanguy Pruvot e5d1cf8416 lyra2v2: typo in type, its a struct of 4x uint2 :p 2015-10-15 06:48:42 +02:00
Tanguy Pruvot 6a9280a045 lyra2v2: set a better TPB for intensity 20 (sm52)
use sp forced unroll in skein and do some cleanup...
2015-10-15 02:01:34 +02:00
Tanguy Pruvot 5a08c21355 diff: store solved blocs count, update the api
Also show the real target diff on pools for the algos with a factor (lyra)

require the --show-diff parameter, may be used as default in the final 1.7
2015-10-14 20:21:14 +02:00
Tanguy Pruvot 32f212469b lyra2/v2: fixes for vstudio 2015-10-14 03:31:18 +02:00
Tanguy Pruvot 5bf1f98200 various fixes for SM 2.1 and the benchmark
X11+ algos and quark are not compatible for the moment

but these ones are :

Benchmark results for Gigabyte GTX 460 (SM 2.1 / 1 GB):

   blakecoin :     159090.5 kH/s,     1 MB,  1048576 thr.
       blake :      70208.9 kH/s,     1 MB,  1048576 thr.
         bmw :     122802.6 kH/s,    65 MB,  2097152 thr.
        deep :       3533.6 kH/s,    33 MB,   524288 thr.
    fugue256 :      43177.9 kH/s,    17 MB,   524288 thr.
       heavy :       4118.2 kH/s,   147 MB,   524032 thr.
      keccak :      18673.1 kH/s,   129 MB,  2097152 thr.
       luffa :      28816.0 kH/s,   257 MB,  4194304 thr.
       lyra2 :        213.7 kH/s,   570 MB,    65536 thr.
    mjollnir :       3895.6 kH/s,   147 MB,   524032 thr.
       nist5 :       1101.4 kH/s,    67 MB,  1048576 thr.
       penta :        501.6 kH/s,    21 MB,   327680 thr.
       skein :       5432.4 kH/s,    65 MB,  1048576 thr.
      skein2 :       6788.9 kH/s,    33 MB,   524288 thr.
   whirlpool :        688.5 kH/s,    33 MB,   524288 thr.
         zr5 :        122.5 kH/s,    86 MB,   262144 thr.
2015-10-14 02:59:54 +00:00
Tanguy Pruvot 8fd2739a65 lyra2: support for SM 2.1 cards (GTX 460)
also fix the build (scrypt) for this arch.

else, 318,26 kH/s on a GTX 460...
2015-10-14 01:12:41 +00:00
Tanguy Pruvot fc84c719e9 lyra2: improve cuda implementation (part 1, SM5+)
based on the new djm34 method, 2x faster than first version

cleaned and tuned for the GTX 750/960 (linux / cuda 6.5)
2015-10-13 00:57:29 +02:00
Tanguy Pruvot 9dfa757dc7 warn on cuda errors + various small changes
The full benchmark can now be launched with "ccminer --benchmark"

add a new helper function which log a warning with last cuda error
(not shown with the quiet option) : CUDA_LOG_ERROR();
it can be used where miner.h is included (.c/.cpp/.cu)

fix x14 (in ccminer.cpp), a break was missing in switch..case
2015-10-12 08:46:13 +02:00
Tanguy Pruvot 8fbfe2cfda add gpulog() function helper, simple and multi-threads
when using multiple cpu threads per gpu, use the T prefix, ex:

[2015-10-11 09:52:49] GPU #0: app clocks set to P0 (3600/1228)
 vs
[2015-10-11 09:52:51] GPU T0: MSI GTX 960, 5953.35 kH/s

Only thr_id is required, the function take care of the dev id
2015-10-11 10:46:05 +02:00
Tanguy Pruvot 58c0bb5c02 intensity: fix typo and drop old function 2015-10-11 08:39:07 +02:00
Tanguy Pruvot d195f2e8a2 intensity: do not reduce throughput before init
Else the memory allocated could be less than required later

btw, use the new "cuda" function to apply intensity/throughput
2015-10-11 05:01:41 +02:00
Tanguy Pruvot c6dcc5e5cf benchmark: show mem and default throughput in results
and prepare a new function to get the default intensity

also, take care of multiple threads per gpu...
2015-10-11 04:38:28 +02:00
Tanguy Pruvot 8db5a0bc9e blake: change dynamic round system
blakecoin was conflicting with lyra2, set the rounds more properly
2015-10-11 03:46:30 +02:00
Tanguy Pruvot c7cfe0e2ca Fix windows linkage, C/C++ mismatch 2015-10-11 00:55:22 +02:00
Tanguy Pruvot ab5cc7162e refactor: create bench.cpp and algos.h
Also enhance multi-thread benchmark synchro. with pthread barriers
2015-10-11 00:10:27 +02:00
Tanguy Pruvot c2214091ae benchmark: free last memory leaks on algo switch
remains my original lyra2 implementation to fix... (cuda_lyra2.cu)

I guess some kind of memory overflow force the driver to allocate
memory... but was unable to free it without device reset.
2015-10-10 02:15:32 +02:00
Tanguy Pruvot 4e1e03b891 benchmark: store all algos results + cuda fixes
Note: lyra2, lyra2v2 and script seems to have problems
to coexist with other algos... to run after some of them...

moved lyra2 first and skip scrypt/jane for the moment...

Only stored in memory for now.. to display a table after the bench

ccminer -a auto --benchmark

Results may be exported later to a json file...
2015-10-09 02:07:08 +02:00
Tanguy Pruvot 934555994d benchmark: allow -a auto to bench all algos at once 2015-10-08 21:41:20 +02:00
Tanguy Pruvot 922c2a5cd7 algos: free allocated mem for algo switch
All can be freed propertly now, except script (reset) and lyra2 (leak)
2015-10-08 21:35:30 +02:00
Tanguy Pruvot ee93927fac diff: use the new function in all algos 2015-10-07 20:10:15 +02:00
Tanguy Pruvot 42789f1a0d whirlpool: allow stratum compat with new coins
make a difference between whirlpool and whirlcoin algos (stratum)

Look like the old SHA merkleroot method doesnt work on recent coins

Doesn't affect solo mining, only pools using stratum+tcp:// protocol
2015-10-07 02:26:17 +00:00
Tanguy Pruvot 5f12943de5 whirlpool: add algo free function + vstudio 2015-10-06 23:53:03 +02:00
Tanguy Pruvot b641bfdf8b diff: rename functions like cpuminer-multi
more proper, intuitive...
2015-10-06 23:37:13 +02:00
Tanguy Pruvot 3f589cc4db restore the whirlpool algo 2015-10-06 23:37:07 +02:00
Tanguy Pruvot 87edf84bf3 lyra2v2: increase default intensity
to be able to say, like sp, that its faster :p
2015-10-04 21:54:51 +02:00
Tanguy Pruvot b3adebdf2a lyra2v2: improve speed on SM 5.2 (Cuda 6.5) with sp unrolls
Reduce a bit the 750Ti speed but improve a lot the 9xx speed.

Keep compat for SM 3/3.5 in a second file..

Note: With this code and Cuda 7.5, the speed won is the reverse...
      May be "reverted" soon
2015-10-04 20:22:45 +02:00
Tanguy Pruvot 2ebcd1fbd5 neoscrypt: handle both getwork data sizes FTC/ORB
only affect solo mining, this patch should handle more weird cases

also set getblocktemplate param type to an empty object (ORB)
2015-09-29 13:00:14 +02:00
Tanguy Pruvot 8fb92415fb stratum: prevent multiple bloc notifications on yaamp
yaamp always notify clean jobs,
was not correct for my "new bloc" detection system...
2015-09-26 10:15:52 +02:00
Tanguy Pruvot 2ee86e8f47 skein: fix share ratio / diff 2015-09-26 10:10:39 +02:00
Tanguy Pruvot e1c4b3042c algos: add functions to free allocated resources
Will be used later for algo switching

not really tested yet...
2015-09-25 07:51:57 +02:00
Tanguy Pruvot 8ec5dd7d8e Handle the getwork typo in neoscrypt wallets
allow solo mining neoscrypt coins... (FTC/UFO)
2015-09-24 20:53:17 +02:00
Tanguy Pruvot ec054db317 Show shares diff on longpoll pools too
and remove unused remains of old difficulty functions
2015-09-24 13:23:24 +02:00
Tanguy Pruvot 41707760f5 stratum: force exit on pool auth failure
the miner was stuck instead of exiting after the retries...
2015-09-24 11:31:20 +02:00
Tanguy Pruvot fade2b74b5 diff: cleanup after windows test 2015-09-24 03:57:12 +02:00
Tanguy Pruvot 5308898d1c start v1.7, apply new prototypes to all algos 2015-09-23 15:42:17 +02:00
Tanguy Pruvot 4babf37256 Add --show-diff parameter and fix pool net diff
which display submitted block and net difficulty and is able
to detect shares above net diff (solved blocs)

Note: only made on lyra2v2 and zr5 algos

TODO: compute the found diff on all algos...
require changes in all scan hash "kernel" function parameters

to be continued...
2015-09-23 14:44:59 +02:00
Tanguy Pruvot cd64f9b0e7 Add a new cuda-schedule parameter
0: cudaDeviceScheduleAuto
1: cudaDeviceScheduleSpin
2: cudaDeviceScheduleYield
4: cudaDeviceScheduleBlockingSync

Also set the best one (4) for luffa algo by default...
2015-09-17 23:45:03 +02:00
Tanguy Pruvot 8f98bde4fb lyra2v2: improve cubehash with uint2 2015-09-06 13:49:52 +02:00
Tanguy Pruvot 6e64383b32 klaus small fixes 2015-09-05 20:16:24 +02:00
Tanguy Pruvot ac1f6ad1bb try vstudio MinimalRebuild flag... 2015-09-04 21:14:58 +02:00
Tanguy Pruvot 4b40c16359 v1.6.6 release 2015-08-28 11:30:04 +02:00
Tanguy Pruvot bcbb959a34 applog: remove useless mutex 2015-08-24 13:41:12 +02:00
Tanguy Pruvot 9a13624c2e check abort_flag in threads loops
This flag was added recently (scrypt) from cudaminer code,
and i missed some...

and prevent multiple calls to proper_exit(), one is enough...
2015-08-24 13:33:03 +02:00
Tanguy Pruvot 629d987177 Allow to load remote config files with curl
different samples of use:

  ccminer -c http://127.0.0.1/ccminer.json

or dynamically from a web application :
  ccminer -c http://127.0.0.1/ccminer/config.php?h=linux

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-08-24 08:44:34 +02:00
Tanguy Pruvot 21f5435420 lyra2: improve skein256 component 2015-08-23 09:46:48 +02:00
Tanguy Pruvot 877f25aee5 lyra2v2: SM3.0 compat too
and strip most of the unused vectors defines...
2015-08-23 09:46:23 +02:00
Tanguy Pruvot 5be0a5c586 update autoconf scripts
made on ubuntu 14.04.2 with 'autoreconf -fvi'
2015-08-23 06:36:14 +02:00
Tanguy Pruvot 64e997e9d6 prepare release 1.6.6 2015-08-22 17:33:26 +02:00
Tanguy Pruvot 01f3183c31 bmw algo for MDT, with midstate
which could be extracted from json too

replace a satcoin by another one ;)

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-08-22 15:01:51 +02:00
Tanguy Pruvot e4414752c4 vstudio: lyra warning fixes + project dups 2015-08-22 14:57:15 +02:00
Tanguy Pruvot e3548f46f3 drop animecoin support
no more really minable... just minable in french
2015-08-22 12:35:22 +02:00
Tanguy Pruvot 736f916da3 Restore default timeout (300s) for normal use
Was only useful to reduce pool switching problems but
some pools require a longer value.
2015-08-22 12:30:30 +02:00
Tanguy Pruvot c9ef0b6b39 affinity: allow more than 8 cores values (and hexa) 2015-08-22 12:30:30 +02:00
Tanguy Pruvot b256ca47a0 bmw256: reduce target array size 2015-08-22 12:30:07 +02:00
Tanguy Pruvot 6500e7401a lyra2v2: properly exclude SM 3.0 devices 2015-08-18 13:43:21 +02:00
Tanguy Pruvot da8a31c4e5 vstudio: restore missing x15 whirlpool 2015-08-18 12:26:52 +02:00
Tanguy Pruvot 53cd591956 lyra2v2, bmw256 and cubehash256 cleanup + diff fix 2015-08-18 11:10:58 +02:00
Tanguy Pruvot 4b04ca8027 lyra2v2: aliases and readme 2015-08-18 09:27:30 +02:00
Tanguy Pruvot c9a66b696f return to original lyra2 code
until i find the problem...
2015-08-18 09:27:30 +02:00
Tanguy Pruvot d4e191610e Import and adapt lyra2v2
not tested on windows and with SM <= 5
2015-08-18 09:27:11 +02:00
286 changed files with 73013 additions and 13520 deletions

No files matched your search

+18 -2
View File
@@ -15,7 +15,7 @@ depcomp
missing
install-sh
stamp-h1
cpuminer-config.h*
ccminer-config.h*
compile
config.log
config.status
@@ -25,7 +25,7 @@ config.sub
mingw32-config.cache
*/.dirstamp
.dirstamp
.DS_Store
Desktop.ini
Thumbs.db
@@ -41,6 +41,8 @@ x64/Release/
*.opensdf
*.sdf
*.pdb
*.VC.opendb
*.VC.db
.settings/
.project
@@ -52,3 +54,17 @@ x64/Release/
compat/curl-for-windows/
*.ptx
*.i
*.ii
*.gpu
*.cubin
*.stub.c
*.module_id
*.hash
*.fatbin.c
*.fatbin
*.cudafe1.cpp
*.cudafe1.c
*.cudafe2.c
+402 -293
View File
@@ -1,24 +1,20 @@
/**
* Blake-256 Cuda Kernel (Tested on SM 5.0)
* Blake-256 Cuda Kernel (Tested on SM 5/5.2)
*
* Tanguy Pruvot - Nov. 2014
* Tanguy Pruvot / SP - Jan 2016
*/
#define PRECALC64 1
#include <stdint.h>
#include <memory.h>
#include "miner.h"
extern "C" {
#include "sph/sph_blake.h"
#include <stdint.h>
#include <memory.h>
}
/* threads per block and throughput (intensity) */
#define TPB 128
/* added in sph_blake.c */
extern "C" int blake256_rounds = 14;
/* threads per block */
#define TPB 512
/* hash by cpu with blake 256 */
extern "C" void blake256hash(void *output, const void *input, int8_t rounds = 14)
@@ -26,7 +22,7 @@ extern "C" void blake256hash(void *output, const void *input, int8_t rounds = 14
uchar hash[64];
sph_blake256_context ctx;
blake256_rounds = rounds;
sph_blake256_set_rounds(rounds);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, 80);
@@ -37,93 +33,33 @@ extern "C" void blake256hash(void *output, const void *input, int8_t rounds = 14
#include "cuda_helper.h"
#if PRECALC64
__constant__ uint32_t _ALIGN(32) d_data[12];
#else
__constant__ static uint32_t _ALIGN(32) c_data[20];
/* midstate hash cache, this algo is run on 2 parts */
__device__ static uint32_t cache[8];
__device__ static uint32_t prevsum = 0;
/* crc32.c */
extern "C" uint32_t crc32_u32t(const uint32_t *buf, size_t size);
#ifdef __INTELLISENSE__
#define __byte_perm(x, y, b) x
#endif
__constant__ uint32_t _ALIGN(32) d_data[12];
/* 8 adapters max */
static uint32_t *d_resNonce[MAX_GPUS];
static uint32_t *h_resNonce[MAX_GPUS];
/* max count of found nonces in one call */
#define NBN 2
static uint32_t extra_results[NBN] = { UINT32_MAX };
static __thread uint32_t extra_results[NBN] = { UINT32_MAX };
/* prefer uint32_t to prevent size conversions = speed +5/10 % */
__constant__
static uint32_t _ALIGN(32) c_sigma[16][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
};
#if !PRECALC64
__device__ __constant__
static const uint32_t __align__(32) c_IV256[8] = {
SPH_C32(0x6A09E667), SPH_C32(0xBB67AE85),
SPH_C32(0x3C6EF372), SPH_C32(0xA54FF53A),
SPH_C32(0x510E527F), SPH_C32(0x9B05688C),
SPH_C32(0x1F83D9AB), SPH_C32(0x5BE0CD19)
};
#endif
__device__ __constant__
static const uint32_t __align__(32) c_u256[16] = {
SPH_C32(0x243F6A88), SPH_C32(0x85A308D3),
SPH_C32(0x13198A2E), SPH_C32(0x03707344),
SPH_C32(0xA4093822), SPH_C32(0x299F31D0),
SPH_C32(0x082EFA98), SPH_C32(0xEC4E6C89),
SPH_C32(0x452821E6), SPH_C32(0x38D01377),
SPH_C32(0xBE5466CF), SPH_C32(0x34E90C6C),
SPH_C32(0xC0AC29B7), SPH_C32(0xC97C50DD),
SPH_C32(0x3F84D5B5), SPH_C32(0xB5470917)
};
#define GS(a,b,c,d,x) { \
const uint32_t idx1 = c_sigma[r][x]; \
const uint32_t idx2 = c_sigma[r][x+1]; \
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
v[d] = SPH_ROTL32(v[d] ^ v[a], 16); \
#define GSPREC(a,b,c,d,x,y) { \
v[a] += (m[x] ^ c_u256[y]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
v[c] += v[d]; \
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
\
v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
v[d] = SPH_ROTR32(v[d] ^ v[a], 8); \
v[a] += (m[y] ^ c_u256[x]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
v[c] += v[d]; \
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
}
}
/* Second part (64-80) msg never change, store it */
__device__ __constant__
static const uint32_t __align__(32) c_Padding[16] = {
0, 0, 0, 0,
0x80000000UL, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 640,
};
__device__ static
void blake256_compress(uint32_t *h, const uint32_t *block, const uint32_t T0, const int rounds)
__device__ __forceinline__
void blake256_compress_14(uint32_t *h, const uint32_t *block, const uint32_t T0)
{
uint32_t /*_ALIGN(8)*/ m[16];
uint32_t v[16];
@@ -133,12 +69,22 @@ void blake256_compress(uint32_t *h, const uint32_t *block, const uint32_t T0, co
m[2] = block[2];
m[3] = block[3];
for (uint32_t i = 4; i < 16; i++) {
#if PRECALC64
m[i] = c_Padding[i];
#else
m[i] = (T0 == 0x200) ? block[i] : c_Padding[i];
#endif
const uint32_t c_u256[16] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
};
const uint32_t c_Padding[12] = {
0x80000000UL, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 640,
};
#pragma unroll
for (uint32_t i = 0; i < 12; i++) {
m[i+4] = c_Padding[i];
}
//#pragma unroll 8
@@ -155,132 +101,143 @@ void blake256_compress(uint32_t *h, const uint32_t *block, const uint32_t T0, co
v[14] = c_u256[6];
v[15] = c_u256[7];
for (int r = 0; r < rounds; r++) {
/* column step */
GS(0, 4, 0x8, 0xC, 0x0);
GS(1, 5, 0x9, 0xD, 0x2);
GS(2, 6, 0xA, 0xE, 0x4);
GS(3, 7, 0xB, 0xF, 0x6);
/* diagonal step */
GS(0, 5, 0xA, 0xF, 0x8);
GS(1, 6, 0xB, 0xC, 0xA);
GS(2, 7, 0x8, 0xD, 0xC);
GS(3, 4, 0x9, 0xE, 0xE);
}
#if PRECALC64
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
GSPREC(0, 4, 0x8, 0xC,0,1);
GSPREC(1, 5, 0x9, 0xD,2,3);
GSPREC(2, 6, 0xA, 0xE, 4,5);
GSPREC(3, 7, 0xB, 0xF, 6,7);
GSPREC(0, 5, 0xA, 0xF, 8,9);
GSPREC(1, 6, 0xB, 0xC, 10,11);
GSPREC(2, 7, 0x8, 0xD, 12,13);
GSPREC(3, 4, 0x9, 0xE, 14,15);
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
GSPREC(0, 4, 0x8, 0xC, 14, 10);
GSPREC(1, 5, 0x9, 0xD, 4, 8);
GSPREC(2, 6, 0xA, 0xE, 9, 15);
GSPREC(3, 7, 0xB, 0xF, 13, 6);
GSPREC(0, 5, 0xA, 0xF, 1, 12);
GSPREC(1, 6, 0xB, 0xC, 0, 2);
GSPREC(2, 7, 0x8, 0xD, 11, 7);
GSPREC(3, 4, 0x9, 0xE, 5, 3);
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
GSPREC(0, 4, 0x8, 0xC, 11, 8);
GSPREC(1, 5, 0x9, 0xD, 12, 0);
GSPREC(2, 6, 0xA, 0xE, 5, 2);
GSPREC(3, 7, 0xB, 0xF, 15, 13);
GSPREC(0, 5, 0xA, 0xF, 10, 14);
GSPREC(1, 6, 0xB, 0xC, 3, 6);
GSPREC(2, 7, 0x8, 0xD, 7, 1);
GSPREC(3, 4, 0x9, 0xE, 9, 4);
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
GSPREC(0, 4, 0x8, 0xC, 7, 9);
GSPREC(1, 5, 0x9, 0xD, 3, 1);
GSPREC(2, 6, 0xA, 0xE, 13, 12);
GSPREC(3, 7, 0xB, 0xF, 11, 14);
GSPREC(0, 5, 0xA, 0xF, 2, 6);
GSPREC(1, 6, 0xB, 0xC, 5, 10);
GSPREC(2, 7, 0x8, 0xD, 4, 0);
GSPREC(3, 4, 0x9, 0xE, 15, 8);
// { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
GSPREC(0, 4, 0x8, 0xC, 9, 0);
GSPREC(1, 5, 0x9, 0xD, 5, 7);
GSPREC(2, 6, 0xA, 0xE, 2, 4);
GSPREC(3, 7, 0xB, 0xF, 10, 15);
GSPREC(0, 5, 0xA, 0xF, 14, 1);
GSPREC(1, 6, 0xB, 0xC, 11, 12);
GSPREC(2, 7, 0x8, 0xD, 6, 8);
GSPREC(3, 4, 0x9, 0xE, 3, 13);
// { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
GSPREC(0, 4, 0x8, 0xC, 2, 12);
GSPREC(1, 5, 0x9, 0xD, 6, 10);
GSPREC(2, 6, 0xA, 0xE, 0, 11);
GSPREC(3, 7, 0xB, 0xF, 8, 3);
GSPREC(0, 5, 0xA, 0xF, 4, 13);
GSPREC(1, 6, 0xB, 0xC, 7, 5);
GSPREC(2, 7, 0x8, 0xD, 15, 14);
GSPREC(3, 4, 0x9, 0xE, 1, 9);
// { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
GSPREC(0, 4, 0x8, 0xC, 12, 5);
GSPREC(1, 5, 0x9, 0xD, 1, 15);
GSPREC(2, 6, 0xA, 0xE, 14, 13);
GSPREC(3, 7, 0xB, 0xF, 4, 10);
GSPREC(0, 5, 0xA, 0xF, 0, 7);
GSPREC(1, 6, 0xB, 0xC, 6, 3);
GSPREC(2, 7, 0x8, 0xD, 9, 2);
GSPREC(3, 4, 0x9, 0xE, 8, 11);
// { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
GSPREC(0, 4, 0x8, 0xC, 13, 11);
GSPREC(1, 5, 0x9, 0xD, 7, 14);
GSPREC(2, 6, 0xA, 0xE, 12, 1);
GSPREC(3, 7, 0xB, 0xF, 3, 9);
GSPREC(0, 5, 0xA, 0xF, 5, 0);
GSPREC(1, 6, 0xB, 0xC, 15, 4);
GSPREC(2, 7, 0x8, 0xD, 8, 6);
GSPREC(3, 4, 0x9, 0xE, 2, 10);
// { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
GSPREC(0, 4, 0x8, 0xC, 6, 15);
GSPREC(1, 5, 0x9, 0xD, 14, 9);
GSPREC(2, 6, 0xA, 0xE, 11, 3);
GSPREC(3, 7, 0xB, 0xF, 0, 8);
GSPREC(0, 5, 0xA, 0xF, 12, 2);
GSPREC(1, 6, 0xB, 0xC, 13, 7);
GSPREC(2, 7, 0x8, 0xD, 1, 4);
GSPREC(3, 4, 0x9, 0xE, 10, 5);
// { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
GSPREC(0, 4, 0x8, 0xC, 10, 2);
GSPREC(1, 5, 0x9, 0xD, 8, 4);
GSPREC(2, 6, 0xA, 0xE, 7, 6);
GSPREC(3, 7, 0xB, 0xF, 1, 5);
GSPREC(0, 5, 0xA, 0xF, 15, 11);
GSPREC(1, 6, 0xB, 0xC, 9, 14);
GSPREC(2, 7, 0x8, 0xD, 3, 12);
GSPREC(3, 4, 0x9, 0xE, 13, 0);
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
GSPREC(0, 4, 0x8, 0xC, 0, 1);
GSPREC(1, 5, 0x9, 0xD, 2, 3);
GSPREC(2, 6, 0xA, 0xE, 4, 5);
GSPREC(3, 7, 0xB, 0xF, 6, 7);
GSPREC(0, 5, 0xA, 0xF, 8, 9);
GSPREC(1, 6, 0xB, 0xC, 10, 11);
GSPREC(2, 7, 0x8, 0xD, 12, 13);
GSPREC(3, 4, 0x9, 0xE, 14, 15);
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
GSPREC(0, 4, 0x8, 0xC, 14, 10);
GSPREC(1, 5, 0x9, 0xD, 4, 8);
GSPREC(2, 6, 0xA, 0xE, 9, 15);
GSPREC(3, 7, 0xB, 0xF, 13, 6);
GSPREC(0, 5, 0xA, 0xF, 1, 12);
GSPREC(1, 6, 0xB, 0xC, 0, 2);
GSPREC(2, 7, 0x8, 0xD, 11, 7);
GSPREC(3, 4, 0x9, 0xE, 5, 3);
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
GSPREC(0, 4, 0x8, 0xC, 11, 8);
GSPREC(1, 5, 0x9, 0xD, 12, 0);
GSPREC(2, 6, 0xA, 0xE, 5, 2);
GSPREC(3, 7, 0xB, 0xF, 15, 13);
GSPREC(0, 5, 0xA, 0xF, 10, 14);
GSPREC(1, 6, 0xB, 0xC, 3, 6);
GSPREC(2, 7, 0x8, 0xD, 7, 1);
GSPREC(3, 4, 0x9, 0xE, 9, 4);
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
GSPREC(0, 4, 0x8, 0xC, 7, 9);
GSPREC(1, 5, 0x9, 0xD, 3, 1);
GSPREC(2, 6, 0xA, 0xE, 13, 12);
GSPREC(3, 7, 0xB, 0xF, 11, 14);
GSPREC(0, 5, 0xA, 0xF, 2, 6);
GSPREC(1, 6, 0xB, 0xC, 5, 10);
GSPREC(2, 7, 0x8, 0xD, 4, 0);
GSPREC(3, 4, 0x9, 0xE, 15, 8);
// only compute h6 & 7
h[6U] ^= v[6U] ^ v[14U];
h[7U] ^= v[7U] ^ v[15U];
#else
//#pragma unroll 16
for (uint32_t i = 0; i < 16; i++) {
uint32_t j = i % 8U;
h[j] ^= v[i];
}
#endif
}
#if !PRECALC64 /* original method */
__global__
void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce,
const uint64_t highTarget, const int crcsum, const int rounds)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
const uint32_t nonce = startNonce + thread;
uint32_t h[8];
#pragma unroll
for(int i=0; i<8; i++) {
h[i] = c_IV256[i];
}
if (crcsum != prevsum) {
prevsum = crcsum;
blake256_compress(h, c_data, 512, rounds);
#pragma unroll
for(int i=0; i<8; i++) {
cache[i] = h[i];
}
} else {
#pragma unroll
for(int i=0; i<8; i++) {
h[i] = cache[i];
}
}
// ------ Close: Bytes 64 to 80 ------
uint32_t ending[4];
ending[0] = c_data[16];
ending[1] = c_data[17];
ending[2] = c_data[18];
ending[3] = nonce; /* our tested value */
blake256_compress(h, ending, 640, rounds);
// not sure why, h[7] is ok
h[6] = cuda_swab32(h[6]);
// compare count of leading zeros h[6] + h[7]
uint64_t high64 = ((uint64_t*)h)[3];
if (high64 <= highTarget)
#if NBN == 2
/* keep the smallest nonce, + extra one if found */
if (resNonce[0] > nonce) {
// printf("%llx %llx \n", high64, highTarget);
resNonce[1] = resNonce[0];
resNonce[0] = nonce;
}
else
resNonce[1] = nonce;
#else
resNonce[0] = nonce;
#endif
}
}
__host__
uint32_t blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint64_t highTarget,
const uint32_t crcsum, const int8_t rounds)
{
const uint32_t threadsperblock = TPB;
uint32_t result = UINT32_MAX;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
size_t shared_size = 0;
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
return result;
blake256_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNonce, d_resNonce[thr_id], highTarget, crcsum, (int) rounds);
MyStreamSynchronize(NULL, 0, thr_id);
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
result = h_resNonce[thr_id][0];
for (int n=0; n < (NBN-1); n++)
extra_results[n] = h_resNonce[thr_id][n+1];
}
return result;
}
__host__
void blake256_cpu_setBlock_80(uint32_t *pdata, const uint32_t *ptarget)
{
uint32_t data[20];
memcpy(data, pdata, 80);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, data, sizeof(data), 0, cudaMemcpyHostToDevice));
}
#else
/* ############################################################################################################################### */
/* Precalculated 1st 64-bytes block (midstate) method */
__global__
void blake256_gpu_hash_16(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce,
const uint64_t highTarget, const int rounds, const bool trace)
__global__ __launch_bounds__(1024,1)
void blake256_gpu_hash_16(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint64_t highTarget)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
@@ -301,28 +258,161 @@ void blake256_gpu_hash_16(const uint32_t threads, const uint32_t startNonce, uin
ending[2] = d_data[10];
ending[3] = nonce; /* our tested value */
blake256_compress(h, ending, 640, rounds);
blake256_compress_14(h, ending, 640);
if (h[7] == 0 && cuda_swab32(h[6]) <= highTarget) {
#if NBN == 2
/* keep the smallest nonce, + extra one if found */
if (resNonce[0] > nonce) {
resNonce[1] = resNonce[0];
resNonce[0] = nonce;
}
else
if (resNonce[0] != UINT32_MAX)
resNonce[1] = nonce;
else
resNonce[0] = nonce;
#else
resNonce[0] = nonce;
#endif
#ifdef _DEBUG
if (trace) {
uint64_t high64 = ((uint64_t*)h)[3];
printf("gpu: %16llx\n", high64);
printf("gpu: %08x.%08x\n", h[7], h[6]);
printf("tgt: %16llx\n", highTarget);
}
}
}
}
__global__
#if __CUDA_ARCH__ >= 500
__launch_bounds__(512, 3) /* 40 regs */
#endif
void blake256_gpu_hash_16_8(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint64_t highTarget)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t h[8];
const uint32_t nonce = startNonce + thread;
#pragma unroll
for (int i = 0; i < 8; i++) {
h[i] = d_data[i];
}
// ------ Close: Bytes 64 to 80 ------
uint32_t m[16] = {
d_data[8], d_data[9], d_data[10], nonce,
0x80000000UL, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 640,
};
const uint32_t c_u256[16] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
};
uint32_t v[16];
#pragma unroll
for (uint32_t i = 0; i < 8; i++)
v[i] = h[i];
v[8] = c_u256[0];
v[9] = c_u256[1];
v[10] = c_u256[2];
v[11] = c_u256[3];
v[12] = c_u256[4] ^ 640U;
v[13] = c_u256[5] ^ 640U;
v[14] = c_u256[6];
v[15] = c_u256[7];
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
GSPREC(0, 4, 0x8, 0xC, 0, 1);
GSPREC(1, 5, 0x9, 0xD, 2, 3);
GSPREC(2, 6, 0xA, 0xE, 4, 5);
GSPREC(3, 7, 0xB, 0xF, 6, 7);
GSPREC(0, 5, 0xA, 0xF, 8, 9);
GSPREC(1, 6, 0xB, 0xC, 10, 11);
GSPREC(2, 7, 0x8, 0xD, 12, 13);
GSPREC(3, 4, 0x9, 0xE, 14, 15);
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
GSPREC(0, 4, 0x8, 0xC, 14, 10);
GSPREC(1, 5, 0x9, 0xD, 4, 8);
GSPREC(2, 6, 0xA, 0xE, 9, 15);
GSPREC(3, 7, 0xB, 0xF, 13, 6);
GSPREC(0, 5, 0xA, 0xF, 1, 12);
GSPREC(1, 6, 0xB, 0xC, 0, 2);
GSPREC(2, 7, 0x8, 0xD, 11, 7);
GSPREC(3, 4, 0x9, 0xE, 5, 3);
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
GSPREC(0, 4, 0x8, 0xC, 11, 8);
GSPREC(1, 5, 0x9, 0xD, 12, 0);
GSPREC(2, 6, 0xA, 0xE, 5, 2);
GSPREC(3, 7, 0xB, 0xF, 15, 13);
GSPREC(0, 5, 0xA, 0xF, 10, 14);
GSPREC(1, 6, 0xB, 0xC, 3, 6);
GSPREC(2, 7, 0x8, 0xD, 7, 1);
GSPREC(3, 4, 0x9, 0xE, 9, 4);
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
GSPREC(0, 4, 0x8, 0xC, 7, 9);
GSPREC(1, 5, 0x9, 0xD, 3, 1);
GSPREC(2, 6, 0xA, 0xE, 13, 12);
GSPREC(3, 7, 0xB, 0xF, 11, 14);
GSPREC(0, 5, 0xA, 0xF, 2, 6);
GSPREC(1, 6, 0xB, 0xC, 5, 10);
GSPREC(2, 7, 0x8, 0xD, 4, 0);
GSPREC(3, 4, 0x9, 0xE, 15, 8);
// { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
GSPREC(0, 4, 0x8, 0xC, 9, 0);
GSPREC(1, 5, 0x9, 0xD, 5, 7);
GSPREC(2, 6, 0xA, 0xE, 2, 4);
GSPREC(3, 7, 0xB, 0xF, 10, 15);
GSPREC(0, 5, 0xA, 0xF, 14, 1);
GSPREC(1, 6, 0xB, 0xC, 11, 12);
GSPREC(2, 7, 0x8, 0xD, 6, 8);
GSPREC(3, 4, 0x9, 0xE, 3, 13);
// { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
GSPREC(0, 4, 0x8, 0xC, 2, 12);
GSPREC(1, 5, 0x9, 0xD, 6, 10);
GSPREC(2, 6, 0xA, 0xE, 0, 11);
GSPREC(3, 7, 0xB, 0xF, 8, 3);
GSPREC(0, 5, 0xA, 0xF, 4, 13);
GSPREC(1, 6, 0xB, 0xC, 7, 5);
GSPREC(2, 7, 0x8, 0xD, 15, 14);
GSPREC(3, 4, 0x9, 0xE, 1, 9);
// { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
GSPREC(0, 4, 0x8, 0xC, 12, 5);
GSPREC(1, 5, 0x9, 0xD, 1, 15);
GSPREC(2, 6, 0xA, 0xE, 14, 13);
GSPREC(3, 7, 0xB, 0xF, 4, 10);
GSPREC(0, 5, 0xA, 0xF, 0, 7);
GSPREC(1, 6, 0xB, 0xC, 6, 3);
GSPREC(2, 7, 0x8, 0xD, 9, 2);
GSPREC(3, 4, 0x9, 0xE, 8, 11);
// { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
GSPREC(0, 4, 0x8, 0xC, 13, 11);
GSPREC(1, 5, 0x9, 0xD, 7, 14);
GSPREC(2, 6, 0xA, 0xE, 12, 1);
GSPREC(3, 7, 0xB, 0xF, 3, 9);
GSPREC(0, 5, 0xA, 0xF, 5, 0);
GSPREC(1, 6, 0xB, 0xC, 15, 4);
GSPREC(2, 7, 0x8, 0xD, 8, 6);
//GSPREC(3, 4, 0x9, 0xE, 2, 10);
// { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
// only compute h6 & 7
//h[6] ^= v[6] ^ v[14];
//h[7] ^= v[7] ^ v[15];
if ((h[7]^v[7]^v[15]) == 0) // h7
{
GSPREC(3, 4, 0x9, 0xE, 2, 10);
if (cuda_swab32(h[6]^v[6]^v[14]) <= highTarget) {
#if NBN == 2
if (resNonce[0] != UINT32_MAX)
resNonce[1] = nonce;
else
resNonce[0] = nonce;
#else
resNonce[0] = nonce;
#endif
}
}
}
}
@@ -331,18 +421,20 @@ __host__
static uint32_t blake256_cpu_hash_16(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint64_t highTarget,
const int8_t rounds)
{
const uint32_t threadsperblock = TPB;
uint32_t result = UINT32_MAX;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
dim3 grid((threads + TPB-1)/TPB);
dim3 block(TPB);
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
return result;
blake256_gpu_hash_16 <<<grid, block>>> (threads, startNonce, d_resNonce[thr_id], highTarget, (int) rounds, opt_tracegpu);
MyStreamSynchronize(NULL, 0, thr_id);
if (rounds == 8)
blake256_gpu_hash_16_8 <<<grid, block>>> (threads, startNonce, d_resNonce[thr_id], highTarget);
else
blake256_gpu_hash_16 <<<grid, block>>> (threads, startNonce, d_resNonce[thr_id], highTarget);
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
result = h_resNonce[thr_id][0];
for (int n=0; n < (NBN-1); n++)
@@ -356,8 +448,7 @@ static void blake256mid(uint32_t *output, const uint32_t *input, int8_t rounds =
{
sph_blake256_context ctx;
/* in sph_blake.c */
blake256_rounds = rounds;
sph_blake256_set_rounds(rounds);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, 64);
@@ -375,116 +466,134 @@ void blake256_cpu_setBlock_16(uint32_t *penddata, const uint32_t *midstate, cons
data[10]= penddata[2];
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, data, 32 + 12, 0, cudaMemcpyHostToDevice));
}
#endif
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_blake256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds=14)
extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds=14)
{
uint32_t _ALIGN(64) endiandata[20];
uint32_t _ALIGN(64) midstate[8];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
uint64_t targetHigh = ((uint64_t*)ptarget)[3];
uint32_t _ALIGN(64) endiandata[20];
#if PRECALC64
uint32_t _ALIGN(64) midstate[8];
#else
uint32_t crcsum;
#endif
int intensity = (device_sm[device_map[thr_id]] > 500) ? 22 : 20;
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
throughput = min(throughput, max_nonce - first_nonce);
int dev_id = device_map[thr_id];
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 30 : 26;
if (device_sm[dev_id] < 350) intensity = 22;
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
int rc = 0;
if (opt_benchmark) {
targetHigh = 0x1ULL << 32;
((uint32_t*)ptarget)[6] = swab32(0xff);
ptarget[6] = swab32(0xff);
}
if (opt_tracegpu) {
/* test call from util.c */
throughput = 1;
for (int k = 0; k < 20; k++)
pdata[k] = swab32(pdata[k]);
}
if (!init[thr_id])
{
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
if (!init[thr_id]) {
if (active_gpus > 1)
cudaSetDevice(device_map[thr_id]);
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), 0);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), 0);
cuda_get_arch(thr_id);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
init[thr_id] = true;
}
#if PRECALC64
for (int k = 0; k < 16; k++)
be32enc(&endiandata[k], pdata[k]);
blake256mid(midstate, endiandata, blakerounds);
blake256_cpu_setBlock_16(&pdata[16], midstate, ptarget);
#else
blake256_cpu_setBlock_80(pdata, ptarget);
crcsum = crc32_u32t(pdata, 64);
#endif /* PRECALC64 */
do {
uint32_t foundNonce =
#if PRECALC64
// GPU HASH (second block only, first is midstate)
blake256_cpu_hash_16(thr_id, throughput, pdata[19], targetHigh, blakerounds);
#else
// GPU FULL HASH
blake256_cpu_hash_80(thr_id, throughput, pdata[19], targetHigh, crcsum, blakerounds);
#endif
if (foundNonce != UINT32_MAX)
{
uint32_t vhashcpu[8];
uint32_t Htarg = (uint32_t)targetHigh;
work->nonces[0] = blake256_cpu_hash_16(thr_id, throughput, pdata[19], targetHigh, blakerounds);
for (int k=0; k < 19; k++)
*hashes_done = pdata[19] - first_nonce + throughput;
if (work->nonces[0] != UINT32_MAX)
{
uint32_t _ALIGN(64) vhashcpu[8];
const uint32_t Htarg = ptarget[6];
for (int k=16; k < 19; k++)
be32enc(&endiandata[k], pdata[k]);
be32enc(&endiandata[19], foundNonce);
be32enc(&endiandata[19], work->nonces[0]);
blake256hash(vhashcpu, endiandata, blakerounds);
//applog(LOG_BLUE, "%08x %16llx", vhashcpu[6], targetHigh);
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget))
{
rc = 1;
pdata[19] = foundNonce;
*hashes_done = pdata[19] - first_nonce + 1;
work->valid_nonces = 1;
work_set_target_ratio(work, vhashcpu);
#if NBN > 1
if (extra_results[0] != UINT32_MAX) {
be32enc(&endiandata[19], extra_results[0]);
work->nonces[1] = extra_results[0];
be32enc(&endiandata[19], work->nonces[1]);
blake256hash(vhashcpu, endiandata, blakerounds);
if (vhashcpu[6] <= Htarg /* && fulltest(vhashcpu, ptarget) */) {
pdata[21] = extra_results[0];
applog(LOG_BLUE, "1:%x 2:%x", foundNonce, extra_results[0]);
*hashes_done = max(*hashes_done, extra_results[0] - first_nonce + 1);
rc = 2;
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) {
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
work_set_target_ratio(work, vhashcpu);
xchg(work->nonces[0], work->nonces[1]);
} else {
bn_set_target_ratio(work, vhashcpu, 1);
}
work->valid_nonces = 2;
}
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
extra_results[0] = UINT32_MAX;
} else {
pdata[19] = work->nonces[0] + 1; // cursor
}
#endif
//applog_hash((uint8_t*)ptarget);
//applog_compare_hash((uint8_t*)vhashcpu,(uint8_t*)ptarget);
return rc;
return work->valid_nonces;
}
else if (opt_debug) {
applog_hash((uchar*)ptarget);
applog_compare_hash((uchar*)vhashcpu, (uchar*)ptarget);
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
else if (vhashcpu[6] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
pdata[19] = work->nonces[0] + 1;
continue;
}
}
if ((uint64_t) pdata[19] + throughput > (uint64_t) max_nonce) {
break;
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart);
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + pdata[19]);
*hashes_done = pdata[19] - first_nonce;
MyStreamSynchronize(NULL, 0, device_map[thr_id]);
return rc;
}
// cleanup
extern "C" void free_blake256(int thr_id)
{
if (!init[thr_id])
return;
cudaDeviceSynchronize();
cudaFreeHost(h_resNonce[thr_id]);
cudaFree(d_resNonce[thr_id]);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+565
View File
@@ -0,0 +1,565 @@
/**
* Based on the SPH implementation of blake2s
* Provos Alexis - 2016
*/
#include "miner.h"
#include <string.h>
#include <stdint.h>
#include "sph/blake2s.h"
#include "sph/sph_types.h"
#ifdef __INTELLISENSE__
#define __byte_perm(x, y, b) x
#endif
#include "cuda_helper.h"
#ifdef __CUDA_ARCH__
__device__ __forceinline__
uint32_t ROR8(const uint32_t a) {
return __byte_perm(a, 0, 0x0321);
}
__device__ __forceinline__
uint32_t ROL16(const uint32_t a) {
return __byte_perm(a, 0, 0x1032);
}
#else
#define ROR8(u) (u >> 8)
#define ROL16(u) (u << 16)
#endif
__device__ __forceinline__
uint32_t xor3x(uint32_t a, uint32_t b, uint32_t c)
{
uint32_t result;
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result) : "r"(a), "r"(b),"r"(c)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
#else
result = a^b^c;
#endif
return result;
}
static const uint32_t blake2s_IV[8] = {
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
};
static const uint8_t blake2s_sigma[10][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
};
#define G(r,i,a,b,c,d) \
do { \
a = a + b + m[blake2s_sigma[r][2*i+0]]; \
d = SPH_ROTR32(d ^ a, 16); \
c = c + d; \
b = SPH_ROTR32(b ^ c, 12); \
a = a + b + m[blake2s_sigma[r][2*i+1]]; \
d = SPH_ROTR32(d ^ a, 8); \
c = c + d; \
b = SPH_ROTR32(b ^ c, 7); \
} while(0)
#define ROUND(r) \
do { \
G(r,0,v[0],v[4],v[ 8],v[12]); \
G(r,1,v[1],v[5],v[ 9],v[13]); \
G(r,2,v[2],v[6],v[10],v[14]); \
G(r,3,v[3],v[7],v[11],v[15]); \
G(r,4,v[0],v[5],v[10],v[15]); \
G(r,5,v[1],v[6],v[11],v[12]); \
G(r,6,v[2],v[7],v[ 8],v[13]); \
G(r,7,v[3],v[4],v[ 9],v[14]); \
} while(0)
extern "C" void blake2s_hash(void *output, const void *input)
{
uint32_t m[16];
uint32_t v[16];
uint32_t h[8];
uint32_t *in = (uint32_t*)input;
// COMPRESS
for(int i = 0; i < 16; ++i )
m[i] = in[i];
h[0] = 0x01010020 ^ blake2s_IV[0];
h[1] = blake2s_IV[1];
h[2] = blake2s_IV[2];
h[3] = blake2s_IV[3];
h[4] = blake2s_IV[4];
h[5] = blake2s_IV[5];
h[6] = blake2s_IV[6];
h[7] = blake2s_IV[7];
for(int i = 0; i < 8; ++i )
v[i] = h[i];
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
v[12] = 64 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
v[14] = blake2s_IV[6]; v[15] = blake2s_IV[7];
ROUND( 0 ); ROUND( 1 );
ROUND( 2 ); ROUND( 3 );
ROUND( 4 ); ROUND( 5 );
ROUND( 6 ); ROUND( 7 );
ROUND( 8 ); ROUND( 9 );
for(size_t i = 0; i < 8; ++i)
h[i] ^= v[i] ^ v[i + 8];
// COMPRESS
m[0] = in[16]; m[1] = in[17];
m[2] = in[18]; m[3] = in[19];
for(size_t i = 4; i < 16; ++i)
m[i] = 0;
for(size_t i = 0; i < 8; ++i)
v[i] = h[i];
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
v[12] = 0x50 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
v[14] = ~blake2s_IV[6]; v[15] = blake2s_IV[7];
ROUND( 0 ); ROUND( 1 );
ROUND( 2 ); ROUND( 3 );
ROUND( 4 ); ROUND( 5 );
ROUND( 6 ); ROUND( 7 );
ROUND( 8 ); ROUND( 9 );
for(size_t i = 0; i < 8; ++i)
h[i] ^= v[i] ^ v[i + 8];
memcpy(output, h, 32);
}
#define TPB 1024
#define NPT 256
#define maxResults 16
#define NBN 1
__constant__ uint32_t _ALIGN(32) midstate[20];
static uint32_t *d_resNonce[MAX_GPUS];
static uint32_t *h_resNonce[MAX_GPUS];
#define GS4(a,b,c,d,e,f,a1,b1,c1,d1,e1,f1,a2,b2,c2,d2,e2,f2,a3,b3,c3,d3,e3,f3){ \
a += b + e; a1+= b1 + e1; a2+= b2 + e2; a3+= b3 + e3; \
d = ROL16( d ^ a); d1 = ROL16(d1 ^ a1); d2 = ROL16(d2 ^ a2); d3 = ROL16(d3 ^ a3); \
c +=d; c1+=d1; c2+=d2; c3+=d3;\
b = ROTR32(b ^ c, 12); b1 = ROTR32(b1^c1, 12); b2 = ROTR32(b2^c2, 12); b3 = ROTR32(b3^c3, 12); \
a += b + f; a1+= b1 + f1; a2+= b2 + f2; a3+= b3 + f3; \
d = ROR8(d ^ a); d1 = ROR8(d1^a1); d2 = ROR8(d2^a2); d3 = ROR8(d3^a3); \
c += d; c1 += d1; c2 += d2; c3 += d3;\
b = ROTR32(b ^ c, 7); b1 = ROTR32(b1^c1, 7); b2 = ROTR32(b2^c2, 7); b3 = ROTR32(b3^c3, 7); \
}
__global__ __launch_bounds__(TPB,1)
void blake2s_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint32_t ptarget7)
{
const uint32_t step = gridDim.x * blockDim.x;
uint32_t m[ 3];
uint32_t v[16];
m[0] = midstate[16];
m[1] = midstate[17];
m[2] = midstate[18];
const uint32_t h7 = midstate[19];
for(uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x ; thread <threads; thread+=step){
#pragma unroll
for(int i=0;i<16;i++){
v[ i] = midstate[ i];
}
uint32_t nonce = cuda_swab32(startNonce + thread);
// Round( 0 );
v[ 1] += nonce;
v[13] = ROR8(v[13] ^ v[ 1]);
v[ 9] += v[13];
v[ 5] = ROTR32(v[ 5] ^ v[ 9], 7);
v[ 1]+= v[ 6];
v[ 0]+= v[ 5];
v[12] = ROL16(v[12] ^ v[ 1]);
v[13] = ROL16(v[13] ^ v[ 2]);
v[15] = ROL16(v[15] ^ v[ 0]);
v[11]+= v[12]; v[ 8]+= v[13]; v[ 9]+= v[14]; v[10]+= v[15];
v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 12); v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
v[ 1]+= v[ 6]; v[ 2]+= v[ 7]; v[ 3]+= v[ 4]; v[ 0]+= v[ 5];
v[12] = ROR8(v[12] ^ v[ 1]); v[13] = ROR8(v[13] ^ v[ 2]); v[14] = ROR8(v[14] ^ v[ 3]); v[15] = ROR8(v[15] ^ v[ 0]);
v[11]+= v[12]; v[ 8]+= v[13]; v[ 9]+= v[14]; v[10]+= v[15];
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 7] = ROTR32(v[ 7] ^ v[ 8], 7); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 1],0, v[ 1],v[ 6],v[11],v[12],m[ 0],m[ 2], v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],0,nonce);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,m[ 0], v[ 2],v[ 6],v[10],v[14],0,m[ 2], v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],nonce,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 1], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],nonce,m[ 1], v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 2],0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 0], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 0], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 2],0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 1], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],nonce,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],m[ 2],0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 0],0, v[ 3],v[ 7],v[11],v[15],0,nonce);
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 1],0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],m[ 1],0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 0],0, v[ 1],v[ 6],v[11],v[12],0,nonce, v[ 2],v[ 7],v[ 8],v[13],0,m[ 2], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,m[ 1], v[ 3],v[ 7],v[11],v[15],nonce,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 0], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 2],0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,nonce, v[ 3],v[ 7],v[11],v[15],m[ 0],0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 2], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],m[ 1],0, v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 2], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],m[ 1],0);
// GS(9,4,v[ 0],v[ 5],v[10],v[15]);
v[ 0] += v[ 5];
v[ 2] += v[ 7] + nonce;
v[15] = ROL16(v[15] ^ v[ 0]);
v[13] = ROL16(v[13] ^ v[ 2]);
v[10] += v[15];
v[ 8] += v[13];
v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12);
v[ 0] += v[ 5];
v[ 2] += v[ 7];
v[15] = ROR8(v[15] ^ v[ 0]);
v[13] = ROR8(v[13] ^ v[ 2]);
v[ 8] += v[13];
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 7);
if (xor3x(h7,v[7],v[15]) <= ptarget7){
uint32_t pos = atomicInc(&resNonce[0],0xffffffff)+1;
if(pos < maxResults)
resNonce[pos] = nonce;
return;
}
}
}
__global__ __launch_bounds__(TPB,1)
void blake2s_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce)
{
const uint32_t step = gridDim.x * blockDim.x;
uint32_t m[ 3];
uint32_t v[16];
m[0] = midstate[16];
m[1] = midstate[17];
m[2] = midstate[18];
const uint32_t h7 = midstate[19];
for(uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x ; thread <threads; thread+=step)
{
#pragma unroll
for(int i=0;i<16;i++){
v[ i] = midstate[ i];
}
uint32_t nonce = cuda_swab32(startNonce+thread);
// Round( 0 );
v[ 1] += nonce;
v[13] = ROR8(v[13] ^ v[ 1]);
v[ 9] += v[13];
v[ 5] = ROTR32(v[ 5] ^ v[ 9], 7);
v[ 1]+= v[ 6];
v[ 0]+= v[ 5];
v[13] = ROL16(v[13] ^ v[ 2]); v[12] = ROL16(v[12] ^ v[ 1]); v[15] = ROL16(v[15] ^ v[ 0]);
v[ 8]+= v[13]; v[11]+= v[12]; v[ 9]+= v[14]; v[10]+= v[15];
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12); v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 12); v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
v[ 2]+= v[ 7]; v[ 1]+= v[ 6]; v[ 3]+= v[ 4]; v[ 0]+= v[ 5];
v[13] = ROR8(v[13] ^ v[ 2]); v[12] = ROR8(v[12] ^ v[ 1]); v[14] = ROR8(v[14] ^ v[ 3]); v[15] = ROR8(v[15] ^ v[ 0]);
v[ 8]+= v[13]; v[11]+= v[12]; v[ 9]+= v[14]; v[10]+= v[15];
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 7] = ROTR32(v[ 7] ^ v[8], 7); v[ 4] = ROTR32(v[ 4] ^ v[ 9], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 1],0, v[ 1],v[ 6],v[11],v[12],m[ 0],m[ 2], v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],0,nonce);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,m[ 0], v[ 2],v[ 6],v[10],v[14],0,m[ 2], v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],nonce,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 1], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],nonce,m[ 1], v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 2],0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,m[ 0], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 0], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 2],0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 1], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],nonce,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],m[ 2],0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],m[ 0],0, v[ 3],v[ 7],v[11],v[15],0,nonce);
GS4(v[ 0],v[ 5],v[10],v[15],0,0, v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 1],0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],m[ 1],0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],0,0);
GS4(v[ 0],v[ 5],v[10],v[15],m[ 0],0, v[ 1],v[ 6],v[11],v[12],0,nonce, v[ 2],v[ 7],v[ 8],v[13],0,m[ 2], v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,m[ 1], v[ 3],v[ 7],v[11],v[15],nonce,0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 0], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],0,0, v[ 3],v[ 4],v[ 9],v[14],m[ 2],0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,0, v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,nonce, v[ 3],v[ 7],v[11],v[15],m[ 0],0);
GS4(v[ 0],v[ 5],v[10],v[15],0,m[ 2], v[ 1],v[ 6],v[11],v[12],0,0, v[ 2],v[ 7],v[ 8],v[13],m[ 1],0, v[ 3],v[ 4],v[ 9],v[14],0,0);
GS4(v[ 0],v[ 4],v[ 8],v[12],0,m[ 2], v[ 1],v[ 5],v[ 9],v[13],0,0, v[ 2],v[ 6],v[10],v[14],0,0, v[ 3],v[ 7],v[11],v[15],m[ 1],0);
v[ 0] += v[ 5];
v[ 2] += v[ 7] + nonce;
v[15] = ROL16(v[15] ^ v[ 0]);
v[13] = ROL16(v[13] ^ v[ 2]);
v[10] += v[15];
v[ 8] += v[13];
v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12);
v[ 0] += v[ 5];
v[ 2] += v[ 7];
v[15] = ROTR32(v[15] ^ v[ 0],1);
v[13] = ROR8(v[13] ^ v[ 2]);
v[ 8] += v[13];
if(xor3x(v[ 7],h7,v[ 8])==v[15]){
uint32_t pos = atomicInc(&resNonce[0],0xffffffff)+1;
if(pos < maxResults)
resNonce[pos]=nonce;
return;
}
}
}
static void blake2s_setBlock(const uint32_t* input,const uint32_t ptarget7)
{
uint32_t _ALIGN(64) m[16];
uint32_t _ALIGN(64) v[16];
uint32_t _ALIGN(64) h[21];
// COMPRESS
for(int i = 0; i < 16; ++i )
m[i] = input[i];
h[0] = 0x01010020 ^ blake2s_IV[0];
h[1] = blake2s_IV[1];
h[2] = blake2s_IV[2]; h[3] = blake2s_IV[3];
h[4] = blake2s_IV[4]; h[5] = blake2s_IV[5];
h[6] = blake2s_IV[6]; h[7] = blake2s_IV[7];
for(int i = 0; i < 8; ++i )
v[i] = h[i];
v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1];
v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3];
v[12] = 64 ^ blake2s_IV[4]; v[13] = blake2s_IV[5];
v[14] = blake2s_IV[6]; v[15] = blake2s_IV[7];
ROUND( 0 ); ROUND( 1 );
ROUND( 2 ); ROUND( 3 );
ROUND( 4 ); ROUND( 5 );
ROUND( 6 ); ROUND( 7 );
ROUND( 8 ); ROUND( 9 );
for(int i = 0; i < 8; ++i )
h[i] ^= v[i] ^ v[i + 8];
h[16] = input[16];
h[17] = input[17];
h[18] = input[18];
h[ 8] = 0x6A09E667; h[ 9] = 0xBB67AE85;
h[10] = 0x3C6EF372; h[11] = 0xA54FF53A;
h[12] = 0x510E522F; h[13] = 0x9B05688C;
h[14] =~0x1F83D9AB; h[15] = 0x5BE0CD19;
h[ 0]+= h[ 4] + h[16];
h[12] = SPH_ROTR32(h[12] ^ h[ 0],16);
h[ 8]+= h[12];
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8],12);
h[ 0]+= h[ 4] + h[17];
h[12] = SPH_ROTR32(h[12] ^ h[ 0],8);
h[ 8]+= h[12];
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8],7);
h[ 1]+= h[ 5] + h[18];
h[13] = SPH_ROTR32(h[13] ^ h[ 1], 16);
h[ 9]+= h[13];
h[ 5] = ROTR32(h[ 5] ^ h[ 9], 12);
h[ 2]+= h[ 6];
h[14] = SPH_ROTR32(h[14] ^ h[ 2],16);
h[10]+= h[14];
h[ 6] = SPH_ROTR32(h[ 6] ^ h[10], 12);
h[ 2]+= h[ 6];
h[14] = SPH_ROTR32(h[14] ^ h[ 2],8);
h[10]+= h[14];
h[ 6] = SPH_ROTR32(h[ 6] ^ h[10], 7);
h[19] = h[7]; //constant h[7] for nonce check
h[ 3]+= h[ 7];
h[15] = SPH_ROTR32(h[15] ^ h[ 3],16);
h[11]+= h[15];
h[ 7] = SPH_ROTR32(h[ 7] ^ h[11], 12);
h[ 3]+= h[ 7];
h[15] = SPH_ROTR32(h[15] ^ h[ 3],8);
h[11]+= h[15];
h[ 7] = SPH_ROTR32(h[ 7] ^ h[11], 7);
h[ 1]+= h[ 5];
h[ 3]+= h[ 4];
h[14] = SPH_ROTR32(h[14] ^ h[ 3],16);
h[ 2]+= h[ 7];
if(ptarget7==0){
h[19] = SPH_ROTL32(h[19],7); //align the rotation with v[7] v[15];
}
cudaMemcpyToSymbol(midstate, h, 20*sizeof(uint32_t), 0, cudaMemcpyHostToDevice);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
uint32_t *resNonces;
const uint32_t first_nonce = pdata[19];
const int dev_id = device_map[thr_id];
int rc = 0;
int intensity = is_windows() ? 25 : 28;
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
const dim3 grid((throughput + (NPT*TPB)-1)/(NPT*TPB));
const dim3 block(TPB);
if (!init[thr_id])
{
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
CUDA_LOG_ERROR();
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
cuda_get_arch(thr_id);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], maxResults * sizeof(uint32_t)), -1);
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], maxResults * sizeof(uint32_t)), -1);
init[thr_id] = true;
}
resNonces = h_resNonce[thr_id];
for (int i=0; i < 19; i++) {
be32enc(&endiandata[i], pdata[i]);
}
blake2s_setBlock(endiandata,ptarget[7]);
cudaMemset(d_resNonce[thr_id], 0x00, maxResults*sizeof(uint32_t));
do {
if(ptarget[7]) {
blake2s_gpu_hash_nonce<<<grid, block>>>(throughput,pdata[19],d_resNonce[thr_id],ptarget[7]);
} else {
blake2s_gpu_hash_nonce<<<grid, block>>>(throughput,pdata[19],d_resNonce[thr_id]);
}
cudaMemcpy(resNonces, d_resNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
if(resNonces[0])
{
cudaMemcpy(resNonces, d_resNonce[thr_id], maxResults*sizeof(uint32_t), cudaMemcpyDeviceToHost);
cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
if(resNonces[0] >= maxResults) {
gpulog(LOG_WARNING, thr_id, "candidates flood: %u", resNonces[0]);
resNonces[0] = maxResults-1;
}
uint32_t vhashcpu[8];
uint32_t nonce = sph_bswap32(resNonces[1]);
be32enc(&endiandata[19], nonce);
blake2s_hash(vhashcpu, endiandata);
*hashes_done = pdata[19] - first_nonce + throughput;
if(vhashcpu[6] <= ptarget[6] && fulltest(vhashcpu, ptarget))
{
work_set_target_ratio(work, vhashcpu);
work->nonces[0] = nonce;
rc = work->valid_nonces = 1;
// search for 2nd best nonce
for(uint32_t j=2; j <= resNonces[0]; j++)
{
nonce = sph_bswap32(resNonces[j]);
be32enc(&endiandata[19], nonce);
blake2s_hash(vhashcpu, endiandata);
if(vhashcpu[6] <= ptarget[6] && fulltest(vhashcpu, ptarget))
{
gpulog(LOG_DEBUG, thr_id, "Multiple nonces: 1/%08x - %u/%08x", work->nonces[0], j, nonce);
work->nonces[1] = nonce;
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
work->shareratio[1] = work->shareratio[0];
work->sharediff[1] = work->sharediff[0];
xchg(work->nonces[1], work->nonces[0]);
work_set_target_ratio(work, vhashcpu);
} else if (work->valid_nonces == 1) {
bn_set_target_ratio(work, vhashcpu, 1);
}
work->valid_nonces++;
rc = 2;
break;
}
}
pdata[19] = max(work->nonces[0], work->nonces[1]); // next scan start
return rc;
} else if (vhashcpu[7] > ptarget[7]) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", resNonces[0]);
}
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart && (uint64_t)max_nonce > (uint64_t)throughput + pdata[19]);
*hashes_done = pdata[19] - first_nonce;
return rc;
}
// cleanup
extern "C" void free_blake2s(int thr_id)
{
if (!init[thr_id])
return;
cudaDeviceSynchronize();
cudaFreeHost(h_resNonce[thr_id]);
cudaFree(d_resNonce[thr_id]);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+138
View File
@@ -0,0 +1,138 @@
/**
* bmw-256 MDT
* tpruvot - 2015
*/
extern "C" {
#include "sph/sph_bmw.h"
}
#include <miner.h>
#include <cuda_helper.h>
static uint32_t *d_hash[MAX_GPUS];
extern void bmw256_midstate_init(int thr_id, uint32_t threads);
extern void bmw256_midstate_free(int thr_id);
extern void bmw256_setBlock_80(int thr_id, void *pdata);
extern void bmw256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash, int swap);
extern uint32_t cuda_check_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash);
// CPU Hash
extern "C" void bmw_hash(void *state, const void *input)
{
uint32_t _ALIGN(64) hash[16];
sph_bmw256_context ctx;
sph_bmw256_init(&ctx);
sph_bmw256(&ctx, input, 80);
sph_bmw256_close(&ctx, (void*) hash);
memcpy(state, hash, 32);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 21);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (opt_benchmark)
ptarget[7] = 0x0005;
if (!init[thr_id]) {
cudaSetDevice(device_map[thr_id]);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
cuda_check_cpu_init(thr_id, throughput);
bmw256_midstate_init(thr_id, throughput);
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)32 * throughput));
init[thr_id] = true;
}
for (int k=0; k < 20; k++) {
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
}
cudaGetLastError();
bmw256_setBlock_80(thr_id, (void*)endiandata);
cuda_check_cpu_setTarget(ptarget);
do {
bmw256_cpu_hash_80(thr_id, (int) throughput, pdata[19], d_hash[thr_id], 1);
*hashes_done = pdata[19] - first_nonce + throughput;
work->nonces[0] = cuda_check_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id]);
if (work->nonces[0] != UINT32_MAX)
{
const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(64) vhash[8];
be32enc(&endiandata[19], work->nonces[0]);
bmw_hash(vhash, endiandata);
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
work->valid_nonces = 1;
work_set_target_ratio(work, vhash);
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
if (work->nonces[1] != 0) {
be32enc(&endiandata[19], work->nonces[1]);
bmw_hash(vhash, endiandata);
bn_set_target_ratio(work, vhash, 1);
work->valid_nonces++;
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
} else {
pdata[19] = work->nonces[0] + 1; // cursor
}
return work->valid_nonces;
}
else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
pdata[19] = work->nonces[0] + 1;
continue;
}
}
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
return 0;
}
// cleanup
extern "C" void free_bmw(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
cudaFree(d_hash[thr_id]);
bmw256_midstate_free(thr_id);
cuda_check_cpu_free(thr_id);
cudaDeviceSynchronize();
init[thr_id] = false;
}
+342 -9
View File
@@ -2,6 +2,8 @@
* Blake-256 Cuda Kernel (Tested on SM 5.0)
*
* Tanguy Pruvot - Nov. 2014
*
* + merged blake+keccak kernel for lyra2v2
*/
extern "C" {
#include "sph/sph_blake.h"
@@ -11,11 +13,25 @@ extern "C" {
#include <memory.h>
#ifdef __INTELLISENSE__
/* just for vstudio code colors */
__device__ uint32_t __byte_perm(uint32_t a, uint32_t b, uint32_t c);
#endif
#define UINT2(x,y) make_uint2(x,y)
__device__ __inline__ uint2 ROR8(const uint2 a) {
uint2 result;
result.x = __byte_perm(a.y, a.x, 0x0765);
result.y = __byte_perm(a.x, a.y, 0x0765);
return result;
}
static __device__ uint64_t cuda_swab32ll(uint64_t x) {
return MAKE_ULONGLONG(cuda_swab32(_LODWORD(x)), cuda_swab32(_HIDWORD(x)));
}
__constant__ static uint32_t c_data[3+1];
__constant__ static uint32_t c_data[3 + 1];
__constant__ static uint32_t sigma[16][16];
static uint32_t c_sigma[16][16] = {
@@ -58,9 +74,25 @@ static const uint32_t c_u256[16] = {
0x3F84D5B5, 0xB5470917
};
__constant__ uint2 keccak_round_constants35[24] = {
{ 0x00000001ul, 0x00000000 }, { 0x00008082ul, 0x00000000 },
{ 0x0000808aul, 0x80000000 }, { 0x80008000ul, 0x80000000 },
{ 0x0000808bul, 0x00000000 }, { 0x80000001ul, 0x00000000 },
{ 0x80008081ul, 0x80000000 }, { 0x00008009ul, 0x80000000 },
{ 0x0000008aul, 0x00000000 }, { 0x00000088ul, 0x00000000 },
{ 0x80008009ul, 0x00000000 }, { 0x8000000aul, 0x00000000 },
{ 0x8000808bul, 0x00000000 }, { 0x0000008bul, 0x80000000 },
{ 0x00008089ul, 0x80000000 }, { 0x00008003ul, 0x80000000 },
{ 0x00008002ul, 0x80000000 }, { 0x00000080ul, 0x80000000 },
{ 0x0000800aul, 0x00000000 }, { 0x8000000aul, 0x80000000 },
{ 0x80008081ul, 0x80000000 }, { 0x00008080ul, 0x80000000 },
{ 0x80000001ul, 0x00000000 }, { 0x80008008ul, 0x80000000 }
};
#define GS2(a,b,c,d,x) { \
const uint32_t idx1 = sigma[r][x]; \
const uint32_t idx2 = sigma[r][x+1]; \
const uint32_t idx2 = sigma[r][(x)+1]; \
v[a] += (m[idx1] ^ u256[idx2]) + v[b]; \
v[d] = SPH_ROTL32(v[d] ^ v[a], 16); \
v[c] += v[d]; \
@@ -76,7 +108,7 @@ static const uint32_t c_u256[16] = {
//#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#define hostGS(a,b,c,d,x) { \
const uint32_t idx1 = c_sigma[r][x]; \
const uint32_t idx2 = c_sigma[r][x+1]; \
const uint32_t idx2 = c_sigma[r][(x)+1]; \
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
v[d] = ROTR32(v[d] ^ v[a], 16); \
v[c] += v[d]; \
@@ -88,6 +120,17 @@ static const uint32_t c_u256[16] = {
v[b] = ROTR32(v[b] ^ v[c], 7); \
}
#define GSPREC(a,b,c,d,x,y) { \
v[a] += (m[x] ^ u256[y]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
v[c] += v[d]; \
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
v[a] += (m[y] ^ u256[x]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
v[c] += v[d]; \
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
}
/* Second part (64-80) msg never change, store it */
__device__ __constant__ static const uint32_t c_Padding[16] = {
0, 0, 0, 0,
@@ -158,8 +201,8 @@ static void blake256_compress2nd(uint32_t *h, const uint32_t *block, const uint3
for (int i = 0; i < 8; i++)
v[i] = h[i];
v[8] = u256[0];
v[9] = u256[1];
v[8] = u256[0];
v[9] = u256[1];
v[10] = u256[2];
v[11] = u256[3];
@@ -189,7 +232,273 @@ static void blake256_compress2nd(uint32_t *h, const uint32_t *block, const uint3
}
}
__global__ __launch_bounds__(256,3)
static void __forceinline__ __device__ keccak_block(uint2 *s)
{
uint2 bc[5], tmpxor[5], u, v;
// uint2 s[25];
#pragma unroll 1
for (int i = 0; i < 24; i++)
{
#pragma unroll
for (uint32_t x = 0; x < 5; x++)
tmpxor[x] = s[x] ^ s[x + 5] ^ s[x + 10] ^ s[x + 15] ^ s[x + 20];
bc[0] = tmpxor[0] ^ ROL2(tmpxor[2], 1);
bc[1] = tmpxor[1] ^ ROL2(tmpxor[3], 1);
bc[2] = tmpxor[2] ^ ROL2(tmpxor[4], 1);
bc[3] = tmpxor[3] ^ ROL2(tmpxor[0], 1);
bc[4] = tmpxor[4] ^ ROL2(tmpxor[1], 1);
u = s[1] ^ bc[0];
s[0] ^= bc[4];
s[1] = ROL2(s[6] ^ bc[0], 44);
s[6] = ROL2(s[9] ^ bc[3], 20);
s[9] = ROL2(s[22] ^ bc[1], 61);
s[22] = ROL2(s[14] ^ bc[3], 39);
s[14] = ROL2(s[20] ^ bc[4], 18);
s[20] = ROL2(s[2] ^ bc[1], 62);
s[2] = ROL2(s[12] ^ bc[1], 43);
s[12] = ROL2(s[13] ^ bc[2], 25);
s[13] = ROL8(s[19] ^ bc[3]);
s[19] = ROR8(s[23] ^ bc[2]);
s[23] = ROL2(s[15] ^ bc[4], 41);
s[15] = ROL2(s[4] ^ bc[3], 27);
s[4] = ROL2(s[24] ^ bc[3], 14);
s[24] = ROL2(s[21] ^ bc[0], 2);
s[21] = ROL2(s[8] ^ bc[2], 55);
s[8] = ROL2(s[16] ^ bc[0], 45);
s[16] = ROL2(s[5] ^ bc[4], 36);
s[5] = ROL2(s[3] ^ bc[2], 28);
s[3] = ROL2(s[18] ^ bc[2], 21);
s[18] = ROL2(s[17] ^ bc[1], 15);
s[17] = ROL2(s[11] ^ bc[0], 10);
s[11] = ROL2(s[7] ^ bc[1], 6);
s[7] = ROL2(s[10] ^ bc[4], 3);
s[10] = ROL2(u, 1);
u = s[0]; v = s[1]; s[0] ^= (~v) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & u; s[4] ^= (~u) & v;
u = s[5]; v = s[6]; s[5] ^= (~v) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & u; s[9] ^= (~u) & v;
u = s[10]; v = s[11]; s[10] ^= (~v) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & u; s[14] ^= (~u) & v;
u = s[15]; v = s[16]; s[15] ^= (~v) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & u; s[19] ^= (~u) & v;
u = s[20]; v = s[21]; s[20] ^= (~v) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & u; s[24] ^= (~u) & v;
s[0] ^= keccak_round_constants35[i];
}
}
//__launch_bounds__(256)
__global__
void blakeKeccak256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint32_t * Hash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
const uint32_t nonce = startNonce + thread;
const uint32_t T0 = 640;
uint32_t h[8];
#pragma unroll 8
for (int i = 0; i<8; i++) { h[i] = cpu_h[i]; }
uint32_t v[16];
const uint32_t c_Padding[12] = {
0x80000000, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 640
};
const uint32_t u256[16] = {
0x243F6A88, 0x85A308D3,
0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0,
0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377,
0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD,
0x3F84D5B5, 0xB5470917
};
uint32_t m[16] = {
c_data[0], c_data[1], c_data[2], nonce,
c_Padding[0], c_Padding[1], c_Padding[2], c_Padding[3],
c_Padding[4], c_Padding[5], c_Padding[6], c_Padding[7],
c_Padding[8], c_Padding[9], c_Padding[10], c_Padding[11]
};
#pragma unroll 8
for (int i = 0; i < 8; i++)
v[i] = h[i];
v[8] = u256[0];
v[9] = u256[1];
v[10] = u256[2];
v[11] = u256[3];
v[12] = u256[4] ^ T0;
v[13] = u256[5] ^ T0;
v[14] = u256[6];
v[15] = u256[7];
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
GSPREC(0, 4, 0x8, 0xC, 0, 1);
GSPREC(1, 5, 0x9, 0xD, 2, 3);
GSPREC(2, 6, 0xA, 0xE, 4, 5);
GSPREC(3, 7, 0xB, 0xF, 6, 7);
GSPREC(0, 5, 0xA, 0xF, 8, 9);
GSPREC(1, 6, 0xB, 0xC, 10, 11);
GSPREC(2, 7, 0x8, 0xD, 12, 13);
GSPREC(3, 4, 0x9, 0xE, 14, 15);
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
GSPREC(0, 4, 0x8, 0xC, 14, 10);
GSPREC(1, 5, 0x9, 0xD, 4, 8);
GSPREC(2, 6, 0xA, 0xE, 9, 15);
GSPREC(3, 7, 0xB, 0xF, 13, 6);
GSPREC(0, 5, 0xA, 0xF, 1, 12);
GSPREC(1, 6, 0xB, 0xC, 0, 2);
GSPREC(2, 7, 0x8, 0xD, 11, 7);
GSPREC(3, 4, 0x9, 0xE, 5, 3);
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
GSPREC(0, 4, 0x8, 0xC, 11, 8);
GSPREC(1, 5, 0x9, 0xD, 12, 0);
GSPREC(2, 6, 0xA, 0xE, 5, 2);
GSPREC(3, 7, 0xB, 0xF, 15, 13);
GSPREC(0, 5, 0xA, 0xF, 10, 14);
GSPREC(1, 6, 0xB, 0xC, 3, 6);
GSPREC(2, 7, 0x8, 0xD, 7, 1);
GSPREC(3, 4, 0x9, 0xE, 9, 4);
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
GSPREC(0, 4, 0x8, 0xC, 7, 9);
GSPREC(1, 5, 0x9, 0xD, 3, 1);
GSPREC(2, 6, 0xA, 0xE, 13, 12);
GSPREC(3, 7, 0xB, 0xF, 11, 14);
GSPREC(0, 5, 0xA, 0xF, 2, 6);
GSPREC(1, 6, 0xB, 0xC, 5, 10);
GSPREC(2, 7, 0x8, 0xD, 4, 0);
GSPREC(3, 4, 0x9, 0xE, 15, 8);
// { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
GSPREC(0, 4, 0x8, 0xC, 9, 0);
GSPREC(1, 5, 0x9, 0xD, 5, 7);
GSPREC(2, 6, 0xA, 0xE, 2, 4);
GSPREC(3, 7, 0xB, 0xF, 10, 15);
GSPREC(0, 5, 0xA, 0xF, 14, 1);
GSPREC(1, 6, 0xB, 0xC, 11, 12);
GSPREC(2, 7, 0x8, 0xD, 6, 8);
GSPREC(3, 4, 0x9, 0xE, 3, 13);
// { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
GSPREC(0, 4, 0x8, 0xC, 2, 12);
GSPREC(1, 5, 0x9, 0xD, 6, 10);
GSPREC(2, 6, 0xA, 0xE, 0, 11);
GSPREC(3, 7, 0xB, 0xF, 8, 3);
GSPREC(0, 5, 0xA, 0xF, 4, 13);
GSPREC(1, 6, 0xB, 0xC, 7, 5);
GSPREC(2, 7, 0x8, 0xD, 15, 14);
GSPREC(3, 4, 0x9, 0xE, 1, 9);
// { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
GSPREC(0, 4, 0x8, 0xC, 12, 5);
GSPREC(1, 5, 0x9, 0xD, 1, 15);
GSPREC(2, 6, 0xA, 0xE, 14, 13);
GSPREC(3, 7, 0xB, 0xF, 4, 10);
GSPREC(0, 5, 0xA, 0xF, 0, 7);
GSPREC(1, 6, 0xB, 0xC, 6, 3);
GSPREC(2, 7, 0x8, 0xD, 9, 2);
GSPREC(3, 4, 0x9, 0xE, 8, 11);
// { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
GSPREC(0, 4, 0x8, 0xC, 13, 11);
GSPREC(1, 5, 0x9, 0xD, 7, 14);
GSPREC(2, 6, 0xA, 0xE, 12, 1);
GSPREC(3, 7, 0xB, 0xF, 3, 9);
GSPREC(0, 5, 0xA, 0xF, 5, 0);
GSPREC(1, 6, 0xB, 0xC, 15, 4);
GSPREC(2, 7, 0x8, 0xD, 8, 6);
GSPREC(3, 4, 0x9, 0xE, 2, 10);
// { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
GSPREC(0, 4, 0x8, 0xC, 6, 15);
GSPREC(1, 5, 0x9, 0xD, 14, 9);
GSPREC(2, 6, 0xA, 0xE, 11, 3);
GSPREC(3, 7, 0xB, 0xF, 0, 8);
GSPREC(0, 5, 0xA, 0xF, 12, 2);
GSPREC(1, 6, 0xB, 0xC, 13, 7);
GSPREC(2, 7, 0x8, 0xD, 1, 4);
GSPREC(3, 4, 0x9, 0xE, 10, 5);
// { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
GSPREC(0, 4, 0x8, 0xC, 10, 2);
GSPREC(1, 5, 0x9, 0xD, 8, 4);
GSPREC(2, 6, 0xA, 0xE, 7, 6);
GSPREC(3, 7, 0xB, 0xF, 1, 5);
GSPREC(0, 5, 0xA, 0xF, 15, 11);
GSPREC(1, 6, 0xB, 0xC, 9, 14);
GSPREC(2, 7, 0x8, 0xD, 3, 12);
GSPREC(3, 4, 0x9, 0xE, 13, 0);
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
GSPREC(0, 4, 0x8, 0xC, 0, 1);
GSPREC(1, 5, 0x9, 0xD, 2, 3);
GSPREC(2, 6, 0xA, 0xE, 4, 5);
GSPREC(3, 7, 0xB, 0xF, 6, 7);
GSPREC(0, 5, 0xA, 0xF, 8, 9);
GSPREC(1, 6, 0xB, 0xC, 10, 11);
GSPREC(2, 7, 0x8, 0xD, 12, 13);
GSPREC(3, 4, 0x9, 0xE, 14, 15);
// { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
GSPREC(0, 4, 0x8, 0xC, 14, 10);
GSPREC(1, 5, 0x9, 0xD, 4, 8);
GSPREC(2, 6, 0xA, 0xE, 9, 15);
GSPREC(3, 7, 0xB, 0xF, 13, 6);
GSPREC(0, 5, 0xA, 0xF, 1, 12);
GSPREC(1, 6, 0xB, 0xC, 0, 2);
GSPREC(2, 7, 0x8, 0xD, 11, 7);
GSPREC(3, 4, 0x9, 0xE, 5, 3);
// { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
GSPREC(0, 4, 0x8, 0xC, 11, 8);
GSPREC(1, 5, 0x9, 0xD, 12, 0);
GSPREC(2, 6, 0xA, 0xE, 5, 2);
GSPREC(3, 7, 0xB, 0xF, 15, 13);
GSPREC(0, 5, 0xA, 0xF, 10, 14);
GSPREC(1, 6, 0xB, 0xC, 3, 6);
GSPREC(2, 7, 0x8, 0xD, 7, 1);
GSPREC(3, 4, 0x9, 0xE, 9, 4);
// { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
GSPREC(0, 4, 0x8, 0xC, 7, 9);
GSPREC(1, 5, 0x9, 0xD, 3, 1);
GSPREC(2, 6, 0xA, 0xE, 13, 12);
GSPREC(3, 7, 0xB, 0xF, 11, 14);
GSPREC(0, 5, 0xA, 0xF, 2, 6);
GSPREC(1, 6, 0xB, 0xC, 5, 10);
GSPREC(2, 7, 0x8, 0xD, 4, 0);
GSPREC(3, 4, 0x9, 0xE, 15, 8);
h[0] = cuda_swab32(h[0] ^ v[0] ^ v[8]);
h[1] = cuda_swab32(h[1] ^ v[1] ^ v[9]);
h[2] = cuda_swab32(h[2] ^ v[2] ^ v[10]);
h[3] = cuda_swab32(h[3] ^ v[3] ^ v[11]);
h[4] = cuda_swab32(h[4] ^ v[4] ^ v[12]);
h[5] = cuda_swab32(h[5] ^ v[5] ^ v[13]);
h[6] = cuda_swab32(h[6] ^ v[6] ^ v[14]);
h[7] = cuda_swab32(h[7] ^ v[7] ^ v[15]);
uint2 keccak_gpu_state[25] = { 0 };
keccak_gpu_state[0].x = h[0];
keccak_gpu_state[0].y = h[1];
keccak_gpu_state[1].x = h[2];
keccak_gpu_state[1].y = h[3];
keccak_gpu_state[2].x = h[4];
keccak_gpu_state[2].y = h[5];
keccak_gpu_state[3].x = h[6];
keccak_gpu_state[3].y = h[7];
keccak_gpu_state[4] = UINT2(1, 0);
keccak_gpu_state[16] = UINT2(0, 0x80000000);
keccak_block(keccak_gpu_state);
uint64_t *outputHash = (uint64_t *)Hash;
#pragma unroll 4
for (int i = 0; i<4; i++)
outputHash[i*threads + thread] = devectorize(keccak_gpu_state[i]);
}
}
__global__ __launch_bounds__(256, 3)
void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint64_t * Hash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
@@ -207,9 +516,9 @@ void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uin
input[3] = startNonce + thread;
blake256_compress2nd(h, input, 640);
#pragma unroll
#pragma unroll
for (int i = 0; i<4; i++) {
Hash[i*threads + thread] = cuda_swab32ll(MAKE_ULONGLONG(h[2 * i], h[2*i+1]));
Hash[i*threads + thread] = cuda_swab32ll(MAKE_ULONGLONG(h[2 * i], h[2 * i + 1]));
}
}
}
@@ -222,7 +531,7 @@ void blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
blake256_gpu_hash_80 <<<grid, block>>> (threads, startNonce, Hash);
blake256_gpu_hash_80 << <grid, block >> > (threads, startNonce, Hash);
MyStreamSynchronize(NULL, order, thr_id);
}
@@ -245,3 +554,27 @@ void blake256_cpu_init(int thr_id, uint32_t threads)
cudaMemcpyToSymbol(u256, c_u256, sizeof(c_u256), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(sigma, c_sigma, sizeof(c_sigma), 0, cudaMemcpyHostToDevice);
}
/** for lyra2v2 **/
__host__
void blakeKeccak256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
blakeKeccak256_gpu_hash_80 <<<grid, block>>> (threads, startNonce, (uint32_t *)Hash);
}
__host__
void blakeKeccak256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order, cudaStream_t stream)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
blakeKeccak256_gpu_hash_80 <<<grid, block, 0, stream>>> (threads, startNonce, (uint32_t *)Hash);
}
+380
View File
@@ -0,0 +1,380 @@
/**
* BMW-256 CUDA Implementation - tpruvot 2015
*
* Not optimal but close to the sph version and easier to adapt.
*/
#include <stdio.h>
#include <memory.h>
#define SPH_64 1
#define USE_MIDSTATE
extern "C" {
#include "sph/sph_bmw.h"
}
#include "cuda_helper.h"
__constant__ uint64_t c_PaddedMessage80[16]; // padded message (80 bytes + padding)
#ifndef USE_MIDSTATE
__constant__ static sph_u32 IV256[16] = {
0x40414243, 0x44454647, 0x48494A4B, 0x4C4D4E4F,
0x50515253, 0x54555657, 0x58595A5B, 0x5C5D5E5F,
0x60616263, 0x64656667, 0x68696A6B, 0x6C6D6E6F,
0x70717273, 0x74757677, 0x78797A7B, 0x7C7D7E7F
};
#endif
__constant__ static sph_u32 final_s[16] = {
0xaaaaaaa0, 0xaaaaaaa1, 0xaaaaaaa2, 0xaaaaaaa3,
0xaaaaaaa4, 0xaaaaaaa5, 0xaaaaaaa6, 0xaaaaaaa7,
0xaaaaaaa8, 0xaaaaaaa9, 0xaaaaaaaa, 0xaaaaaaab,
0xaaaaaaac, 0xaaaaaaad, 0xaaaaaaae, 0xaaaaaaaf
};
static sph_bmw_small_context* d_midstate[MAX_GPUS];
#define I16_16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
#define I16_17 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
#define I16_18 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
#define I16_19 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
#define I16_20 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
#define I16_21 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
#define I16_22 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
#define I16_23 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
#define I16_24 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
#define I16_25 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
#define I16_26 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
#define I16_27 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
#define I16_28 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
#define I16_29 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
#define I16_30 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
#define I16_31 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
//#define M16_16 0, 1, 3, 4, 7, 10, 11
//#define M16_17 1, 2, 4, 5, 8, 11, 12
#define M16_18 2, 3, 5, 6, 9, 12, 13
#define M16_19 3, 4, 6, 7, 10, 13, 14
#define M16_20 4, 5, 7, 8, 11, 14, 15
#define M16_21 5, 6, 8, 9, 12, 15, 16
#define M16_22 6, 7, 9, 10, 13, 0, 1
#define M16_23 7, 8, 10, 11, 14, 1, 2
#define M16_24 8, 9, 11, 12, 15, 2, 3
#define M16_25 9, 10, 12, 13, 0, 3, 4
#define M16_26 10, 11, 13, 14, 1, 4, 5
#define M16_27 11, 12, 14, 15, 2, 5, 6
#define M16_28 12, 13, 15, 16, 3, 6, 7
#define M16_29 13, 14, 0, 1, 4, 7, 8
#define M16_30 14, 15, 1, 2, 5, 8, 9
#define M16_31 15, 16, 2, 3, 6, 9, 10
#define ss0(x) (((x) >> 1) ^ ((x) << 3) ^ ROTL32(x, 4) ^ ROTL32(x, 19))
#define ss1(x) (((x) >> 1) ^ ((x) << 2) ^ ROTL32(x, 8) ^ ROTL32(x, 23))
#define ss2(x) (((x) >> 2) ^ ((x) << 1) ^ ROTL32(x, 12) ^ ROTL32(x, 25))
#define ss3(x) (((x) >> 2) ^ ((x) << 2) ^ ROTL32(x, 15) ^ ROTL32(x, 29))
#define ss4(x) (((x) >> 1) ^ (x))
#define ss5(x) (((x) >> 2) ^ (x))
#define rs1(x) ROTL32(x, 3)
#define rs2(x) ROTL32(x, 7)
#define rs3(x) ROTL32(x, 13)
#define rs4(x) ROTL32(x, 16)
#define rs5(x) ROTL32(x, 19)
#define rs6(x) ROTL32(x, 23)
#define rs7(x) ROTL32(x, 27)
#define MAKE_W(tt, i0, op01, i1, op12, i2, op23, i3, op34, i4) \
tt((data[i0] ^ h[i0]) op01 (data[i1] ^ h[i1]) op12 (data[i2] ^ h[i2]) op23 (data[i3] ^ h[i3]) op34 (data[i4] ^ h[i4]))
//#define Ws0 MAKE_W(SPH_T32, 5, -, 7, +, 10, +, 13, +, 14)
//#define Ws1 MAKE_W(SPH_T32, 6, -, 8, +, 11, +, 14, -, 15)
//#define Ws2 MAKE_W(SPH_T32, 0, +, 7, +, 9, -, 12, +, 15)
//#define Ws3 MAKE_W(SPH_T32, 0, -, 1, +, 8, -, 10, +, 13)
//#define Ws4 MAKE_W(SPH_T32, 1, +, 2, +, 9, -, 11, -, 14)
//#define Ws5 MAKE_W(SPH_T32, 3, -, 2, +, 10, -, 12, +, 15)
//#define Ws6 MAKE_W(SPH_T32, 4, -, 0, -, 3, -, 11, +, 13)
//#define Ws7 MAKE_W(SPH_T32, 1, -, 4, -, 5, -, 12, -, 14)
//#define Ws8 MAKE_W(SPH_T32, 2, -, 5, -, 6, +, 13, -, 15)
//#define Ws9 MAKE_W(SPH_T32, 0, -, 3, +, 6, -, 7, +, 14)
//#define Ws10 MAKE_W(SPH_T32, 8, -, 1, -, 4, -, 7, +, 15)
//#define Ws11 MAKE_W(SPH_T32, 8, -, 0, -, 2, -, 5, +, 9)
//#define Ws12 MAKE_W(SPH_T32, 1, +, 3, -, 6, -, 9, +, 10)
//#define Ws13 MAKE_W(SPH_T32, 2, +, 4, +, 7, +, 10, +, 11)
//#define Ws14 MAKE_W(SPH_T32, 3, -, 5, +, 8, -, 11, -, 12)
//#define Ws15 MAKE_W(SPH_T32, 12, -, 4, -, 6, -, 9, +, 13)
__device__
static void gpu_compress_small(const sph_u32 *data, const sph_u32 h[16], sph_u32 dh[16])
{
// FOLD MAKE_Qas;
sph_u32 dx[16];
for (int i=0; i<16; i++)
dx[i] = data[i] ^ h[i];
sph_u32 qt[32];
qt[ 0] = dx[ 5] - dx[7] + dx[10] + dx[13] + dx[14]; // Ws0
qt[ 1] = dx[ 6] - dx[8] + dx[11] + dx[14] - dx[15]; // Ws1
qt[ 2] = dx[ 0] + dx[7] + dx[ 9] - dx[12] + dx[15]; // Ws2
qt[ 3] = dx[ 0] - dx[1] + dx[ 8] - dx[10] + dx[13]; // Ws3
qt[ 4] = dx[ 1] + dx[2] + dx[ 9] - dx[11] - dx[14]; // Ws4;
qt[ 5] = dx[ 3] - dx[2] + dx[10] - dx[12] + dx[15]; // Ws5;
qt[ 6] = dx[ 4] - dx[0] - dx[ 3] - dx[11] + dx[13]; // Ws6;
qt[ 7] = dx[ 1] - dx[4] - dx[ 5] - dx[12] - dx[14]; // Ws7;
qt[ 8] = dx[ 2] - dx[5] - dx[ 6] + dx[13] - dx[15]; // Ws8;
qt[ 9] = dx[ 0] - dx[3] + dx[ 6] - dx[ 7] + dx[14]; // Ws9;
qt[10] = dx[ 8] - dx[1] - dx[ 4] - dx[ 7] + dx[15]; // Ws10;
qt[11] = dx[ 8] - dx[0] - dx[ 2] - dx[ 5] + dx[ 9]; // Ws11;
qt[12] = dx[ 1] + dx[3] - dx[ 6] - dx[ 9] + dx[10]; // Ws12;
qt[13] = dx[ 2] + dx[4] + dx[ 7] + dx[10] + dx[11]; // Ws13;
qt[14] = dx[ 3] - dx[5] + dx[ 8] - dx[11] - dx[12]; // Ws14;
qt[15] = dx[12] - dx[4] - dx[ 6] - dx[ 9] + dx[13]; // Ws15;
qt[ 0] = ss0(qt[ 0]) + h[ 1];
qt[ 1] = ss1(qt[ 1]) + h[ 2];
qt[ 2] = ss2(qt[ 2]) + h[ 3];
qt[ 3] = ss3(qt[ 3]) + h[ 4];
qt[ 4] = ss4(qt[ 4]) + h[ 5];
qt[ 5] = ss0(qt[ 5]) + h[ 6];
qt[ 6] = ss1(qt[ 6]) + h[ 7];
qt[ 7] = ss2(qt[ 7]) + h[ 8];
qt[ 8] = ss3(qt[ 8]) + h[ 9];
qt[ 9] = ss4(qt[ 9]) + h[10];
qt[10] = ss0(qt[10]) + h[11];
qt[11] = ss1(qt[11]) + h[12];
qt[12] = ss2(qt[12]) + h[13];
qt[13] = ss3(qt[13]) + h[14];
qt[14] = ss4(qt[14]) + h[15];
qt[15] = ss0(qt[15]) + h[ 0];
//MAKE_Qbs;
#define Ks(j) ((sph_u32)(0x05555555UL * j))
#define Qs(j) (qt[j])
#define expand1s_in(i16, \
i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, \
i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
(ss1(qt[i0]) + ss2(qt[i1]) + ss3(qt[i2]) + ss0(qt[i3]) + ss1(qt[i4]) + ss2(qt[i5]) + ss3(qt[i6]) + ss0(qt[i7]) \
+ ss1(qt[i8]) + ss2(qt[i9]) + ss3(qt[i10]) + ss0(qt[i11]) + ss1(qt[i12]) + ss2(qt[i13]) + ss3(qt[i14]) + ss0(qt[i15]) \
+ ((ROTL32(data[i0m], i1m) + ROTL32(data[i3m], i4m) - ROTL32(data[i10m], i11m) + Ks(i16)) ^ h[i7m]))
qt[16] = expand1s_in(16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 3, 4, 7, 10, 11);
qt[17] = expand1s_in(17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 4, 5, 8, 11, 12);
#define expand2s_inner(qf, i16, \
i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, \
i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
(qf(i0) + rs1(qf(i1)) + qf(i2) + rs2(qf(i3)) \
+ qf(i4) + rs3(qf(i5)) + qf(i6) + rs4(qf(i7)) + qf(i8) + rs5(qf(i9)) + qf(i10) + rs6(qf(i11)) \
+ qf(i12) + rs7(qf(i13)) + ss4(qf(i14)) + ss5(qf(i15)) \
+ ((ROTL32(data[i0m], i1m) + ROTL32(data[i3m], i4m) - ROTL32(data[i10m], i11m) + Ks(i16)) ^ h[i7m]))
#ifdef _MSC_VER
#define LPAR (
#define expand2s(i16) \
expand2s_(Qs, i16, I16_ ## i16, M16_ ## i16)
#define expand2s_(qf, i16, ix, iy) \
expand2s_inner LPAR qf, i16, ix, iy)
#else
#define expand2s_(i16, ix, iy) \
expand2s_inner(Qs, i16, ix, iy)
#define expand2s(i16) \
expand2s_(i16, I16_ ## i16, M16_ ## i16)
#endif
qt[18] = expand2s(18);
qt[19] = expand2s(19);
qt[20] = expand2s(20);
qt[21] = expand2s(21);
qt[22] = expand2s(22);
qt[23] = expand2s(23);
qt[24] = expand2s(24);
qt[25] = expand2s(25);
qt[26] = expand2s(26);
qt[27] = expand2s(27);
qt[28] = expand2s(28);
qt[29] = expand2s(29);
qt[30] = expand2s(30);
qt[31] = expand2s(31);
sph_u32 xl, xh;
xl = Qs(16) ^ Qs(17) ^ Qs(18) ^ Qs(19) ^ Qs(20) ^ Qs(21) ^ Qs(22) ^ Qs(23);
xh = xl ^ Qs(24) ^ Qs(25) ^ Qs(26) ^ Qs(27) ^ Qs(28) ^ Qs(29) ^ Qs(30) ^ Qs(31);
dh[ 0] = ((xh << 5) ^ (Qs(16) >> 5) ^ data[ 0]) + (xl ^ Qs(24) ^ Qs(0));
dh[ 1] = ((xh >> 7) ^ (Qs(17) << 8) ^ data[ 1]) + (xl ^ Qs(25) ^ Qs(1));
dh[ 2] = ((xh >> 5) ^ (Qs(18) << 5) ^ data[ 2]) + (xl ^ Qs(26) ^ Qs(2));
dh[ 3] = ((xh >> 1) ^ (Qs(19) << 5) ^ data[ 3]) + (xl ^ Qs(27) ^ Qs(3));
dh[ 4] = ((xh >> 3) ^ (Qs(20) << 0) ^ data[ 4]) + (xl ^ Qs(28) ^ Qs(4));
dh[ 5] = ((xh << 6) ^ (Qs(21) >> 6) ^ data[ 5]) + (xl ^ Qs(29) ^ Qs(5));
dh[ 6] = ((xh >> 4) ^ (Qs(22) << 6) ^ data[ 6]) + (xl ^ Qs(30) ^ Qs(6));
dh[ 7] = ((xh >> 11) ^ (Qs(23) << 2) ^ data[ 7]) + (xl ^ Qs(31) ^ Qs(7));
dh[ 8] = ROTL32(dh[4], 9) + (xh ^ Qs(24) ^ data[ 8]) + ((xl << 8) ^ Qs(23) ^ Qs( 8));
dh[ 9] = ROTL32(dh[5], 10) + (xh ^ Qs(25) ^ data[ 9]) + ((xl >> 6) ^ Qs(16) ^ Qs( 9));
dh[10] = ROTL32(dh[6], 11) + (xh ^ Qs(26) ^ data[10]) + ((xl << 6) ^ Qs(17) ^ Qs(10));
dh[11] = ROTL32(dh[7], 12) + (xh ^ Qs(27) ^ data[11]) + ((xl << 4) ^ Qs(18) ^ Qs(11));
dh[12] = ROTL32(dh[0], 13) + (xh ^ Qs(28) ^ data[12]) + ((xl >> 3) ^ Qs(19) ^ Qs(12));
dh[13] = ROTL32(dh[1], 14) + (xh ^ Qs(29) ^ data[13]) + ((xl >> 4) ^ Qs(20) ^ Qs(13));
dh[14] = ROTL32(dh[2], 15) + (xh ^ Qs(30) ^ data[14]) + ((xl >> 7) ^ Qs(21) ^ Qs(14));
dh[15] = ROTL32(dh[3], 16) + (xh ^ Qs(31) ^ data[15]) + ((xl >> 2) ^ Qs(22) ^ Qs(15));
}
#ifndef USE_MIDSTATE
__device__
static void gpu_bmw256_init(sph_bmw_small_context *sc)
{
memcpy(sc->H, IV256, sizeof sc->H);
sc->ptr = 0;
sc->bit_count = 0;
}
__device__
static void gpu_bmw256(sph_bmw_small_context *sc, const void *data, size_t len)
{
sph_u32 htmp[16];
sph_u32 *h1, *h2;
unsigned char *buf = sc->buf;
size_t ptr = sc->ptr;
sc->bit_count += (sph_u64)len << 3;
h1 = sc->H;
h2 = htmp;
while (len > 0) {
size_t clen;
clen = (sizeof sc->buf) - ptr;
if (clen > len)
clen = len;
memcpy(buf + ptr, data, clen);
data = (const unsigned char *)data + clen;
len -= clen;
ptr += clen;
if (ptr == sizeof sc->buf) {
sph_u32 *ht;
gpu_compress_small((sph_u32 *) buf, h1, h2);
ht = h1;
h1 = h2;
h2 = ht;
ptr = 0;
}
}
sc->ptr = ptr;
if (h1 != sc->H)
memcpy(sc->H, h1, sizeof sc->H);
}
#endif
#define sph_enc64le(ptr, x) \
*((uint64_t*)(ptr)) = x
#define sph_enc64le_aligned sph_enc64le
__device__
static void gpu_bmw256_close(sph_bmw_small_context *sc, uint2 *out)
{
unsigned char *buf = sc->buf;
size_t ptr = sc->ptr;
buf[ptr ++] = 0x80;
sph_u32 *h = sc->H;
sph_u32 h1[16];
if (ptr > (sizeof sc->buf) - 8) {
memset(buf + ptr, 0, (sizeof sc->buf) - ptr);
gpu_compress_small((sph_u32 *) buf, h, h1);
ptr = 0;
h = h1;
}
memset(buf + ptr, 0, sizeof(sc->buf) - 8 - ptr);
sph_enc64le_aligned(buf + sizeof(sc->buf) - 8, SPH_T64(sc->bit_count));
sph_u32 h2[16];
gpu_compress_small((sph_u32 *) buf, h, h2);
gpu_compress_small(h2, final_s, h1);
uint64_t* h64 = (uint64_t*) (&h1[8]);
#pragma unroll
for (int i = 0; i < 4; i++) {
out[i] = vectorize(h64[i]);
}
}
__global__ /* __launch_bounds__(256, 3) */
void bmw256_gpu_hash_80(uint32_t threads, uint32_t startNonce, uint64_t *g_hash, sph_bmw256_context *d_midstate, int swap)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t nonce = startNonce + thread;
nonce = swap ? cuda_swab32(nonce): nonce;
#ifndef USE_MIDSTATE
uint2 hash[10];
#pragma unroll
for(int i=0;i<9;i++)
hash[i] = vectorize(c_PaddedMessage80[i]);
hash[9] = make_uint2(c_PaddedMessage80[9], nonce);
sph_bmw256_context ctx;
gpu_bmw256_init(&ctx);
gpu_bmw256(&ctx, (void*) hash, 80);
#else
sph_bmw256_context ctx;
ctx.ptr = 16; ctx.bit_count = 640;
uint2 *buf = (uint2 *) ctx.buf;
buf[0] = vectorize(c_PaddedMessage80[8]);
buf[1] = make_uint2(c_PaddedMessage80[9], nonce);
#pragma unroll
for(int i=0;i<16;i++)
ctx.H[i] = d_midstate->H[i];
#endif
gpu_bmw256_close(&ctx, (uint2*) &g_hash[thread << 2]);
}
}
__host__
void bmw256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_outputHash, int swap)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
bmw256_gpu_hash_80<<<grid, block>>>(threads, startNonce, (uint64_t*)d_outputHash, d_midstate[thr_id], swap);
}
__host__
void bmw256_setBlock_80(int thr_id, void *pdata)
{
uint64_t PaddedMessage[16];
memcpy(PaddedMessage, pdata, 80);
memset(&PaddedMessage[10], 0, 48);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, sizeof(PaddedMessage), 0, cudaMemcpyHostToDevice));
sph_bmw256_context ctx;
sph_bmw256_init(&ctx);
sph_bmw256(&ctx, (void*) PaddedMessage, 80);
CUDA_SAFE_CALL(cudaMemcpy(d_midstate[thr_id], &ctx, sizeof(sph_bmw256_context), cudaMemcpyHostToDevice));
}
__host__
void bmw256_midstate_init(int thr_id, uint32_t threads)
{
cudaMalloc(&d_midstate[thr_id], sizeof(sph_bmw256_context));
}
__host__
void bmw256_midstate_free(int thr_id)
{
cudaFree(d_midstate[thr_id]);
}
+283
View File
@@ -0,0 +1,283 @@
#include <stdio.h>
#include <memory.h>
#include "cuda_helper.h"
#undef SPH_ROTL32
#define SPH_ROTL32 ROTL32
static uint32_t *d_gnounce[MAX_GPUS];
static uint32_t *d_GNonce[MAX_GPUS];
__constant__ uint64_t pTarget[4];
#define shl(x, n) ((x) << (n))
#define shr(x, n) ((x) >> (n))
#define ss0(x) (shr((x), 1) ^ shl((x), 3) ^ SPH_ROTL32((x), 4) ^ SPH_ROTL32((x), 19))
#define ss1(x) (shr((x), 1) ^ shl((x), 2) ^ SPH_ROTL32((x), 8) ^ SPH_ROTL32((x), 23))
#define ss2(x) (shr((x), 2) ^ shl((x), 1) ^ SPH_ROTL32((x), 12) ^ SPH_ROTL32((x), 25))
#define ss3(x) (shr((x), 2) ^ shl((x), 2) ^ SPH_ROTL32((x), 15) ^ SPH_ROTL32((x), 29))
#define ss4(x) (shr((x), 1) ^ (x))
#define ss5(x) (shr((x), 2) ^ (x))
#define rs1(x) SPH_ROTL32((x), 3)
#define rs2(x) SPH_ROTL32((x), 7)
#define rs3(x) SPH_ROTL32((x), 13)
#define rs4(x) SPH_ROTL32((x), 16)
#define rs5(x) SPH_ROTL32((x), 19)
#define rs6(x) SPH_ROTL32((x), 23)
#define rs7(x) SPH_ROTL32((x), 27)
/* Message expansion function 1 */
__forceinline__ __device__
uint32_t expand32_1(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
{
return (ss1(Q[i - 16]) + ss2(Q[i - 15]) + ss3(Q[i - 14]) + ss0(Q[i - 13])
+ ss1(Q[i - 12]) + ss2(Q[i - 11]) + ss3(Q[i - 10]) + ss0(Q[i - 9])
+ ss1(Q[i - 8]) + ss2(Q[i - 7]) + ss3(Q[i - 6]) + ss0(Q[i - 5])
+ ss1(Q[i - 4]) + ss2(Q[i - 3]) + ss3(Q[i - 2]) + ss0(Q[i - 1])
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
}
/* Message expansion function 2 */
__forceinline__ __device__
uint32_t expand32_2(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
{
return (Q[i - 16] + rs1(Q[i - 15]) + Q[i - 14] + rs2(Q[i - 13])
+ Q[i - 12] + rs3(Q[i - 11]) + Q[i - 10] + rs4(Q[i - 9])
+ Q[i - 8] + rs5(Q[i - 7]) + Q[i - 6] + rs6(Q[i - 5])
+ Q[i - 4] + rs7(Q[i - 3]) + ss4(Q[i - 2]) + ss5(Q[i - 1])
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
}
__forceinline__ __device__
void Compression256(uint32_t * M32)
{
uint32_t Q[32], XL32, XH32;
const uint32_t H[16] = {
0x40414243, 0x44454647, 0x48494A4B, 0x4C4D4E4F,
0x50515253, 0x54555657, 0x58595A5B, 0x5C5D5E5F,
0x60616263, 0x64656667, 0x68696A6B, 0x6C6D6E6F,
0x70717273, 0x74757677, 0x78797A7B, 0x7C7D7E7F
};
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe. */
Q[0] = ss0(Q[0]) + H[1];
Q[1] = ss1(Q[1]) + H[2];
Q[2] = ss2(Q[2]) + H[3];
Q[3] = ss3(Q[3]) + H[4];
Q[4] = ss4(Q[4]) + H[5];
Q[5] = ss0(Q[5]) + H[6];
Q[6] = ss1(Q[6]) + H[7];
Q[7] = ss2(Q[7]) + H[8];
Q[8] = ss3(Q[8]) + H[9];
Q[9] = ss4(Q[9]) + H[10];
Q[10] = ss0(Q[10]) + H[11];
Q[11] = ss1(Q[11]) + H[12];
Q[12] = ss2(Q[12]) + H[13];
Q[13] = ss3(Q[13]) + H[14];
Q[14] = ss4(Q[14]) + H[15];
Q[15] = ss0(Q[15]) + H[0];
/* This is the Message expansion or f_1 in the documentation. */
/* It has 16 rounds. */
/* Blue Midnight Wish has two tunable security parameters. */
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
/* The following relation for these parameters should is satisfied: */
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
#pragma unroll
for (int i=16; i<18; i++)
Q[i] = expand32_1(i, M32, H, Q);
#pragma nounroll
for (int i=18; i<32; i++)
Q[i] = expand32_2(i, M32, H, Q);
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
/* 16 new variables that are prooduced in the Message Expansion part. */
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
XH32 = XL32^Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
/* This part is the function f_2 - in the documentation */
/* Compute the double chaining pipe for the next message block. */
M32[0] = (shl(XH32, 5) ^ shr(Q[16], 5) ^ M32[0]) + (XL32 ^ Q[24] ^ Q[0]);
M32[1] = (shr(XH32, 7) ^ shl(Q[17], 8) ^ M32[1]) + (XL32 ^ Q[25] ^ Q[1]);
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
M32[4] = (shr(XH32, 3) ^ Q[20] ^ M32[4]) + (XL32 ^ Q[28] ^ Q[4]);
M32[5] = (shl(XH32, 6) ^ shr(Q[21], 6) ^ M32[5]) + (XL32 ^ Q[29] ^ Q[5]);
M32[6] = (shr(XH32, 4) ^ shl(Q[22], 6) ^ M32[6]) + (XL32 ^ Q[30] ^ Q[6]);
M32[7] = (shr(XH32, 11) ^ shl(Q[23], 2) ^ M32[7]) + (XL32 ^ Q[31] ^ Q[7]);
M32[8] = SPH_ROTL32(M32[4], 9) + (XH32 ^ Q[24] ^ M32[8]) + (shl(XL32, 8) ^ Q[23] ^ Q[8]);
M32[9] = SPH_ROTL32(M32[5], 10) + (XH32 ^ Q[25] ^ M32[9]) + (shr(XL32, 6) ^ Q[16] ^ Q[9]);
M32[10] = SPH_ROTL32(M32[6], 11) + (XH32 ^ Q[26] ^ M32[10]) + (shl(XL32, 6) ^ Q[17] ^ Q[10]);
M32[11] = SPH_ROTL32(M32[7], 12) + (XH32 ^ Q[27] ^ M32[11]) + (shl(XL32, 4) ^ Q[18] ^ Q[11]);
M32[12] = SPH_ROTL32(M32[0], 13) + (XH32 ^ Q[28] ^ M32[12]) + (shr(XL32, 3) ^ Q[19] ^ Q[12]);
M32[13] = SPH_ROTL32(M32[1], 14) + (XH32 ^ Q[29] ^ M32[13]) + (shr(XL32, 4) ^ Q[20] ^ Q[13]);
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
}
__forceinline__ __device__
void Compression256_2(uint32_t * M32)
{
uint32_t XL32, XH32, Q[32];
const uint32_t H[16] = {
0xaaaaaaa0, 0xaaaaaaa1, 0xaaaaaaa2, 0xaaaaaaa3,
0xaaaaaaa4, 0xaaaaaaa5, 0xaaaaaaa6, 0xaaaaaaa7,
0xaaaaaaa8, 0xaaaaaaa9, 0xaaaaaaaa, 0xaaaaaaab,
0xaaaaaaac, 0xaaaaaaad, 0xaaaaaaae, 0xaaaaaaaf
};
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe.*/
Q[0] = ss0(Q[0]) + H[1];
Q[1] = ss1(Q[1]) + H[2];
Q[2] = ss2(Q[2]) + H[3];
Q[3] = ss3(Q[3]) + H[4];
Q[4] = ss4(Q[4]) + H[5];
Q[5] = ss0(Q[5]) + H[6];
Q[6] = ss1(Q[6]) + H[7];
Q[7] = ss2(Q[7]) + H[8];
Q[8] = ss3(Q[8]) + H[9];
Q[9] = ss4(Q[9]) + H[10];
Q[10] = ss0(Q[10]) + H[11];
Q[11] = ss1(Q[11]) + H[12];
Q[12] = ss2(Q[12]) + H[13];
Q[13] = ss3(Q[13]) + H[14];
Q[14] = ss4(Q[14]) + H[15];
Q[15] = ss0(Q[15]) + H[0];
/* This is the Message expansion or f_1 in the documentation. */
/* It has 16 rounds. */
/* Blue Midnight Wish has two tunable security parameters. */
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
/* The following relation for these parameters should is satisfied: */
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
#pragma unroll
for (int i = 16; i<18; i++)
Q[i] = expand32_1(i, M32, H, Q);
#pragma nounroll
for (int i = 18; i<32; i++)
Q[i] = expand32_2(i, M32, H, Q);
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
/* 16 new variables that are prooduced in the Message Expansion part. */
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
XH32 = XL32 ^ Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
}
#define TPB 512
__global__ __launch_bounds__(TPB, 2)
void bmw256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *const __restrict__ nonceVector)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t message[16] = { 0 };
LOHI(message[0], message[1], __ldg(&g_hash[thread]));
LOHI(message[2], message[3], __ldg(&g_hash[thread + 1 * threads]));
LOHI(message[4], message[5], __ldg(&g_hash[thread + 2 * threads]));
LOHI(message[6], message[7], __ldg(&g_hash[thread + 3 * threads]));
message[8]=0x80;
message[14]=0x100;
Compression256(message);
Compression256_2(message);
if (((uint64_t*)message)[7] <= pTarget[3])
{
uint32_t tmp = atomicExch(&nonceVector[0], startNounce + thread);
if (tmp != 0)
nonceVector[1] = tmp;
}
}
}
__host__
void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *resultnonces)
{
const uint32_t threadsperblock = TPB;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
cudaMemset(d_GNonce[thr_id], 0, 2 * sizeof(uint32_t));
bmw256_gpu_hash_32 << <grid, block >> >(threads, startNounce, g_hash, d_GNonce[thr_id]);
cudaMemcpy(d_gnounce[thr_id], d_GNonce[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
resultnonces[0] = *(d_gnounce[thr_id]);
resultnonces[1] = *(d_gnounce[thr_id] + 1);
}
__host__
void bmw256_cpu_init(int thr_id, uint32_t threads)
{
cudaMalloc(&d_GNonce[thr_id], 2 * sizeof(uint32_t));
cudaMallocHost(&d_gnounce[thr_id], 2 * sizeof(uint32_t));
}
__host__
void bmw256_cpu_free(int thr_id)
{
cudaFree(d_GNonce[thr_id]);
cudaFreeHost(d_gnounce[thr_id]);
}
__host__
void bmw256_setTarget(const void *pTargetIn)
{
cudaMemcpyToSymbol(pTarget, pTargetIn, 32, 0, cudaMemcpyHostToDevice);
}
+370
View File
@@ -0,0 +1,370 @@
#include "cuda_helper.h"
#define CUBEHASH_ROUNDS 16 /* this is r for CubeHashr/b */
#define CUBEHASH_BLOCKBYTES 32 /* this is b for CubeHashr/b */
#ifdef __INTELLISENSE__
/* just for vstudio code colors */
#define __CUDA_ARCH__ 520
#endif
#if __CUDA_ARCH__ < 350
#define LROT(x,bits) ((x << bits) | (x >> (32 - bits)))
#else
#define LROT(x, bits) __funnelshift_l(x, x, bits)
#endif
#define TPB35 576
#define TPB50 1024
#define ROTATEUPWARDS7(a) LROT(a,7)
#define ROTATEUPWARDS11(a) LROT(a,11)
__device__ __forceinline__ void rrounds(uint32_t x[2][2][2][2][2])
{
int r;
uint32_t x0[2][2][2][2];
uint32_t x1[2][2][2][2];
for (r = 0; r < CUBEHASH_ROUNDS; r += 2) {
/* "rotate x_0jklm upwards by 7 bits" */
x0[0][0][0][0] = ROTATEUPWARDS7(x[0][0][0][0][0]);
x0[0][0][0][1] = ROTATEUPWARDS7(x[0][0][0][0][1]);
x0[0][0][1][0] = ROTATEUPWARDS7(x[0][0][0][1][0]);
x0[0][0][1][1] = ROTATEUPWARDS7(x[0][0][0][1][1]);
x0[0][1][0][0] = ROTATEUPWARDS7(x[0][0][1][0][0]);
x0[0][1][0][1] = ROTATEUPWARDS7(x[0][0][1][0][1]);
x0[0][1][1][0] = ROTATEUPWARDS7(x[0][0][1][1][0]);
x0[0][1][1][1] = ROTATEUPWARDS7(x[0][0][1][1][1]);
x0[1][0][0][0] = ROTATEUPWARDS7(x[0][1][0][0][0]);
x0[1][0][0][1] = ROTATEUPWARDS7(x[0][1][0][0][1]);
x0[1][0][1][0] = ROTATEUPWARDS7(x[0][1][0][1][0]);
x0[1][0][1][1] = ROTATEUPWARDS7(x[0][1][0][1][1]);
x0[1][1][0][0] = ROTATEUPWARDS7(x[0][1][1][0][0]);
x0[1][1][0][1] = ROTATEUPWARDS7(x[0][1][1][0][1]);
x0[1][1][1][0] = ROTATEUPWARDS7(x[0][1][1][1][0]);
x0[1][1][1][1] = ROTATEUPWARDS7(x[0][1][1][1][1]);
/* "add x_0jklm into x_1jklm modulo 2^32" */
x1[0][0][0][0] = x[1][0][0][0][0] + x[0][0][0][0][0];
x1[0][0][0][1] = x[1][0][0][0][1] + x[0][0][0][0][1];
x1[0][0][1][0] = x[1][0][0][1][0] + x[0][0][0][1][0];
x1[0][0][1][1] = x[1][0][0][1][1] + x[0][0][0][1][1];
x1[0][1][0][0] = x[1][0][1][0][0] + x[0][0][1][0][0];
x1[0][1][0][1] = x[1][0][1][0][1] + x[0][0][1][0][1];
x1[0][1][1][0] = x[1][0][1][1][0] + x[0][0][1][1][0];
x1[0][1][1][1] = x[1][0][1][1][1] + x[0][0][1][1][1];
x1[1][0][0][0] = x[1][1][0][0][0] + x[0][1][0][0][0];
x1[1][0][0][1] = x[1][1][0][0][1] + x[0][1][0][0][1];
x1[1][0][1][0] = x[1][1][0][1][0] + x[0][1][0][1][0];
x1[1][0][1][1] = x[1][1][0][1][1] + x[0][1][0][1][1];
x1[1][1][0][0] = x[1][1][1][0][0] + x[0][1][1][0][0];
x1[1][1][0][1] = x[1][1][1][0][1] + x[0][1][1][0][1];
x1[1][1][1][0] = x[1][1][1][1][0] + x[0][1][1][1][0];
x1[1][1][1][1] = x[1][1][1][1][1] + x[0][1][1][1][1];
/* "xor x_1~jklm into x_0jklm" */
x[0][0][0][0][0] = x0[0][0][0][0] ^ x1[1][0][0][0];
x[0][0][0][0][1] = x0[0][0][0][1] ^ x1[1][0][0][1];
x[0][0][0][1][0] = x0[0][0][1][0] ^ x1[1][0][1][0];
x[0][0][0][1][1] = x0[0][0][1][1] ^ x1[1][0][1][1];
x[0][0][1][0][0] = x0[0][1][0][0] ^ x1[1][1][0][0];
x[0][0][1][0][1] = x0[0][1][0][1] ^ x1[1][1][0][1];
x[0][0][1][1][0] = x0[0][1][1][0] ^ x1[1][1][1][0];
x[0][0][1][1][1] = x0[0][1][1][1] ^ x1[1][1][1][1];
x[0][1][0][0][0] = x0[1][0][0][0] ^ x1[0][0][0][0];
x[0][1][0][0][1] = x0[1][0][0][1] ^ x1[0][0][0][1];
x[0][1][0][1][0] = x0[1][0][1][0] ^ x1[0][0][1][0];
x[0][1][0][1][1] = x0[1][0][1][1] ^ x1[0][0][1][1];
x[0][1][1][0][0] = x0[1][1][0][0] ^ x1[0][1][0][0];
x[0][1][1][0][1] = x0[1][1][0][1] ^ x1[0][1][0][1];
x[0][1][1][1][0] = x0[1][1][1][0] ^ x1[0][1][1][0];
x[0][1][1][1][1] = x0[1][1][1][1] ^ x1[0][1][1][1];
/* "rotate x_0jklm upwards by 11 bits" */
x0[0][0][0][0] = ROTATEUPWARDS11(x[0][0][0][0][0]);
x0[0][0][0][1] = ROTATEUPWARDS11(x[0][0][0][0][1]);
x0[0][0][1][0] = ROTATEUPWARDS11(x[0][0][0][1][0]);
x0[0][0][1][1] = ROTATEUPWARDS11(x[0][0][0][1][1]);
x0[0][1][0][0] = ROTATEUPWARDS11(x[0][0][1][0][0]);
x0[0][1][0][1] = ROTATEUPWARDS11(x[0][0][1][0][1]);
x0[0][1][1][0] = ROTATEUPWARDS11(x[0][0][1][1][0]);
x0[0][1][1][1] = ROTATEUPWARDS11(x[0][0][1][1][1]);
x0[1][0][0][0] = ROTATEUPWARDS11(x[0][1][0][0][0]);
x0[1][0][0][1] = ROTATEUPWARDS11(x[0][1][0][0][1]);
x0[1][0][1][0] = ROTATEUPWARDS11(x[0][1][0][1][0]);
x0[1][0][1][1] = ROTATEUPWARDS11(x[0][1][0][1][1]);
x0[1][1][0][0] = ROTATEUPWARDS11(x[0][1][1][0][0]);
x0[1][1][0][1] = ROTATEUPWARDS11(x[0][1][1][0][1]);
x0[1][1][1][0] = ROTATEUPWARDS11(x[0][1][1][1][0]);
x0[1][1][1][1] = ROTATEUPWARDS11(x[0][1][1][1][1]);
/* "add x_0jklm into x_1~jk~lm modulo 2^32" */
x[1][1][0][1][0] = x1[1][0][1][0] + x[0][0][0][0][0];
x[1][1][0][1][1] = x1[1][0][1][1] + x[0][0][0][0][1];
x[1][1][0][0][0] = x1[1][0][0][0] + x[0][0][0][1][0];
x[1][1][0][0][1] = x1[1][0][0][1] + x[0][0][0][1][1];
x[1][1][1][1][0] = x1[1][1][1][0] + x[0][0][1][0][0];
x[1][1][1][1][1] = x1[1][1][1][1] + x[0][0][1][0][1];
x[1][1][1][0][0] = x1[1][1][0][0] + x[0][0][1][1][0];
x[1][1][1][0][1] = x1[1][1][0][1] + x[0][0][1][1][1];
x[1][0][0][1][0] = x1[0][0][1][0] + x[0][1][0][0][0];
x[1][0][0][1][1] = x1[0][0][1][1] + x[0][1][0][0][1];
x[1][0][0][0][0] = x1[0][0][0][0] + x[0][1][0][1][0];
x[1][0][0][0][1] = x1[0][0][0][1] + x[0][1][0][1][1];
x[1][0][1][1][0] = x1[0][1][1][0] + x[0][1][1][0][0];
x[1][0][1][1][1] = x1[0][1][1][1] + x[0][1][1][0][1];
x[1][0][1][0][0] = x1[0][1][0][0] + x[0][1][1][1][0];
x[1][0][1][0][1] = x1[0][1][0][1] + x[0][1][1][1][1];
/* "xor x_1~j~k~lm into x_0jklm" */
x[0][0][0][0][0] = x0[0][0][0][0] ^ x[1][1][1][1][0];
x[0][0][0][0][1] = x0[0][0][0][1] ^ x[1][1][1][1][1];
x[0][0][0][1][0] = x0[0][0][1][0] ^ x[1][1][1][0][0];
x[0][0][0][1][1] = x0[0][0][1][1] ^ x[1][1][1][0][1];
x[0][0][1][0][0] = x0[0][1][0][0] ^ x[1][1][0][1][0];
x[0][0][1][0][1] = x0[0][1][0][1] ^ x[1][1][0][1][1];
x[0][0][1][1][0] = x0[0][1][1][0] ^ x[1][1][0][0][0];
x[0][0][1][1][1] = x0[0][1][1][1] ^ x[1][1][0][0][1];
x[0][1][0][0][0] = x0[1][0][0][0] ^ x[1][0][1][1][0];
x[0][1][0][0][1] = x0[1][0][0][1] ^ x[1][0][1][1][1];
x[0][1][0][1][0] = x0[1][0][1][0] ^ x[1][0][1][0][0];
x[0][1][0][1][1] = x0[1][0][1][1] ^ x[1][0][1][0][1];
x[0][1][1][0][0] = x0[1][1][0][0] ^ x[1][0][0][1][0];
x[0][1][1][0][1] = x0[1][1][0][1] ^ x[1][0][0][1][1];
x[0][1][1][1][0] = x0[1][1][1][0] ^ x[1][0][0][0][0];
x[0][1][1][1][1] = x0[1][1][1][1] ^ x[1][0][0][0][1];
/* "rotate x_0jklm upwards by 7 bits" */
x0[0][0][0][0] = ROTATEUPWARDS7(x[0][0][0][0][0]);
x0[0][0][0][1] = ROTATEUPWARDS7(x[0][0][0][0][1]);
x0[0][0][1][0] = ROTATEUPWARDS7(x[0][0][0][1][0]);
x0[0][0][1][1] = ROTATEUPWARDS7(x[0][0][0][1][1]);
x0[0][1][0][0] = ROTATEUPWARDS7(x[0][0][1][0][0]);
x0[0][1][0][1] = ROTATEUPWARDS7(x[0][0][1][0][1]);
x0[0][1][1][0] = ROTATEUPWARDS7(x[0][0][1][1][0]);
x0[0][1][1][1] = ROTATEUPWARDS7(x[0][0][1][1][1]);
x0[1][0][0][0] = ROTATEUPWARDS7(x[0][1][0][0][0]);
x0[1][0][0][1] = ROTATEUPWARDS7(x[0][1][0][0][1]);
x0[1][0][1][0] = ROTATEUPWARDS7(x[0][1][0][1][0]);
x0[1][0][1][1] = ROTATEUPWARDS7(x[0][1][0][1][1]);
x0[1][1][0][0] = ROTATEUPWARDS7(x[0][1][1][0][0]);
x0[1][1][0][1] = ROTATEUPWARDS7(x[0][1][1][0][1]);
x0[1][1][1][0] = ROTATEUPWARDS7(x[0][1][1][1][0]);
x0[1][1][1][1] = ROTATEUPWARDS7(x[0][1][1][1][1]);
/* "add x_0jklm into x_1~j~k~l~m modulo 2^32" */
x1[1][1][1][1] = x[1][1][1][1][1] + x[0][0][0][0][0];
x1[1][1][1][0] = x[1][1][1][1][0] + x[0][0][0][0][1];
x1[1][1][0][1] = x[1][1][1][0][1] + x[0][0][0][1][0];
x1[1][1][0][0] = x[1][1][1][0][0] + x[0][0][0][1][1];
x1[1][0][1][1] = x[1][1][0][1][1] + x[0][0][1][0][0];
x1[1][0][1][0] = x[1][1][0][1][0] + x[0][0][1][0][1];
x1[1][0][0][1] = x[1][1][0][0][1] + x[0][0][1][1][0];
x1[1][0][0][0] = x[1][1][0][0][0] + x[0][0][1][1][1];
x1[0][1][1][1] = x[1][0][1][1][1] + x[0][1][0][0][0];
x1[0][1][1][0] = x[1][0][1][1][0] + x[0][1][0][0][1];
x1[0][1][0][1] = x[1][0][1][0][1] + x[0][1][0][1][0];
x1[0][1][0][0] = x[1][0][1][0][0] + x[0][1][0][1][1];
x1[0][0][1][1] = x[1][0][0][1][1] + x[0][1][1][0][0];
x1[0][0][1][0] = x[1][0][0][1][0] + x[0][1][1][0][1];
x1[0][0][0][1] = x[1][0][0][0][1] + x[0][1][1][1][0];
x1[0][0][0][0] = x[1][0][0][0][0] + x[0][1][1][1][1];
/* "xor x_1j~k~l~m into x_0jklm" */
x[0][0][0][0][0] = x0[0][0][0][0] ^ x1[0][1][1][1];
x[0][0][0][0][1] = x0[0][0][0][1] ^ x1[0][1][1][0];
x[0][0][0][1][0] = x0[0][0][1][0] ^ x1[0][1][0][1];
x[0][0][0][1][1] = x0[0][0][1][1] ^ x1[0][1][0][0];
x[0][0][1][0][0] = x0[0][1][0][0] ^ x1[0][0][1][1];
x[0][0][1][0][1] = x0[0][1][0][1] ^ x1[0][0][1][0];
x[0][0][1][1][0] = x0[0][1][1][0] ^ x1[0][0][0][1];
x[0][0][1][1][1] = x0[0][1][1][1] ^ x1[0][0][0][0];
x[0][1][0][0][0] = x0[1][0][0][0] ^ x1[1][1][1][1];
x[0][1][0][0][1] = x0[1][0][0][1] ^ x1[1][1][1][0];
x[0][1][0][1][0] = x0[1][0][1][0] ^ x1[1][1][0][1];
x[0][1][0][1][1] = x0[1][0][1][1] ^ x1[1][1][0][0];
x[0][1][1][0][0] = x0[1][1][0][0] ^ x1[1][0][1][1];
x[0][1][1][0][1] = x0[1][1][0][1] ^ x1[1][0][1][0];
x[0][1][1][1][0] = x0[1][1][1][0] ^ x1[1][0][0][1];
x[0][1][1][1][1] = x0[1][1][1][1] ^ x1[1][0][0][0];
/* "rotate x_0jklm upwards by 11 bits" */
x0[0][0][0][0] = ROTATEUPWARDS11(x[0][0][0][0][0]);
x0[0][0][0][1] = ROTATEUPWARDS11(x[0][0][0][0][1]);
x0[0][0][1][0] = ROTATEUPWARDS11(x[0][0][0][1][0]);
x0[0][0][1][1] = ROTATEUPWARDS11(x[0][0][0][1][1]);
x0[0][1][0][0] = ROTATEUPWARDS11(x[0][0][1][0][0]);
x0[0][1][0][1] = ROTATEUPWARDS11(x[0][0][1][0][1]);
x0[0][1][1][0] = ROTATEUPWARDS11(x[0][0][1][1][0]);
x0[0][1][1][1] = ROTATEUPWARDS11(x[0][0][1][1][1]);
x0[1][0][0][0] = ROTATEUPWARDS11(x[0][1][0][0][0]);
x0[1][0][0][1] = ROTATEUPWARDS11(x[0][1][0][0][1]);
x0[1][0][1][0] = ROTATEUPWARDS11(x[0][1][0][1][0]);
x0[1][0][1][1] = ROTATEUPWARDS11(x[0][1][0][1][1]);
x0[1][1][0][0] = ROTATEUPWARDS11(x[0][1][1][0][0]);
x0[1][1][0][1] = ROTATEUPWARDS11(x[0][1][1][0][1]);
x0[1][1][1][0] = ROTATEUPWARDS11(x[0][1][1][1][0]);
x0[1][1][1][1] = ROTATEUPWARDS11(x[0][1][1][1][1]);
/* "add x_0jklm into x_1j~kl~m modulo 2^32" */
x[1][0][1][0][1] = x1[0][1][0][1] + x[0][0][0][0][0];
x[1][0][1][0][0] = x1[0][1][0][0] + x[0][0][0][0][1];
x[1][0][1][1][1] = x1[0][1][1][1] + x[0][0][0][1][0];
x[1][0][1][1][0] = x1[0][1][1][0] + x[0][0][0][1][1];
x[1][0][0][0][1] = x1[0][0][0][1] + x[0][0][1][0][0];
x[1][0][0][0][0] = x1[0][0][0][0] + x[0][0][1][0][1];
x[1][0][0][1][1] = x1[0][0][1][1] + x[0][0][1][1][0];
x[1][0][0][1][0] = x1[0][0][1][0] + x[0][0][1][1][1];
x[1][1][1][0][1] = x1[1][1][0][1] + x[0][1][0][0][0];
x[1][1][1][0][0] = x1[1][1][0][0] + x[0][1][0][0][1];
x[1][1][1][1][1] = x1[1][1][1][1] + x[0][1][0][1][0];
x[1][1][1][1][0] = x1[1][1][1][0] + x[0][1][0][1][1];
x[1][1][0][0][1] = x1[1][0][0][1] + x[0][1][1][0][0];
x[1][1][0][0][0] = x1[1][0][0][0] + x[0][1][1][0][1];
x[1][1][0][1][1] = x1[1][0][1][1] + x[0][1][1][1][0];
x[1][1][0][1][0] = x1[1][0][1][0] + x[0][1][1][1][1];
/* "xor x_1jkl~m into x_0jklm" */
x[0][0][0][0][0] = x0[0][0][0][0] ^ x[1][0][0][0][1];
x[0][0][0][0][1] = x0[0][0][0][1] ^ x[1][0][0][0][0];
x[0][0][0][1][0] = x0[0][0][1][0] ^ x[1][0][0][1][1];
x[0][0][0][1][1] = x0[0][0][1][1] ^ x[1][0][0][1][0];
x[0][0][1][0][0] = x0[0][1][0][0] ^ x[1][0][1][0][1];
x[0][0][1][0][1] = x0[0][1][0][1] ^ x[1][0][1][0][0];
x[0][0][1][1][0] = x0[0][1][1][0] ^ x[1][0][1][1][1];
x[0][0][1][1][1] = x0[0][1][1][1] ^ x[1][0][1][1][0];
x[0][1][0][0][0] = x0[1][0][0][0] ^ x[1][1][0][0][1];
x[0][1][0][0][1] = x0[1][0][0][1] ^ x[1][1][0][0][0];
x[0][1][0][1][0] = x0[1][0][1][0] ^ x[1][1][0][1][1];
x[0][1][0][1][1] = x0[1][0][1][1] ^ x[1][1][0][1][0];
x[0][1][1][0][0] = x0[1][1][0][0] ^ x[1][1][1][0][1];
x[0][1][1][0][1] = x0[1][1][0][1] ^ x[1][1][1][0][0];
x[0][1][1][1][0] = x0[1][1][1][0] ^ x[1][1][1][1][1];
x[0][1][1][1][1] = x0[1][1][1][1] ^ x[1][1][1][1][0];
}
}
__device__ __forceinline__
void Final(uint32_t x[2][2][2][2][2], uint32_t *hashval)
{
/* "the integer 1 is xored into the last state word x_11111" */
x[1][1][1][1][1] ^= 1U;
/* "the state is then transformed invertibly through 10r identical rounds" */
for (int i = 0; i < 10; ++i) rrounds(x);
/* "output the first h/8 bytes of the state" */
hashval[0] = x[0][0][0][0][0];
hashval[1] = x[0][0][0][0][1];
hashval[2] = x[0][0][0][1][0];
hashval[3] = x[0][0][0][1][1];
hashval[4] = x[0][0][1][0][0];
hashval[5] = x[0][0][1][0][1];
hashval[6] = x[0][0][1][1][0];
hashval[7] = x[0][0][1][1][1];
}
#if __CUDA_ARCH__ >= 500
__global__ __launch_bounds__(TPB50, 1)
#else
__global__ __launch_bounds__(TPB35, 1)
#endif
void cubehash256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *g_hash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
#if __CUDA_ARCH__ >= 500
uint2 Hash[4];
Hash[0] = __ldg(&g_hash[thread]);
Hash[1] = __ldg(&g_hash[thread + 1 * threads]);
Hash[2] = __ldg(&g_hash[thread + 2 * threads]);
Hash[3] = __ldg(&g_hash[thread + 3 * threads]);
#else
uint32_t Hash[8];
LOHI(Hash[0], Hash[1], __ldg(&((uint64_t*)g_hash)[thread]));
LOHI(Hash[2], Hash[3], __ldg(&((uint64_t*)g_hash)[thread + 1 * threads]));
LOHI(Hash[4], Hash[5], __ldg(&((uint64_t*)g_hash)[thread + 2 * threads]));
LOHI(Hash[6], Hash[7], __ldg(&((uint64_t*)g_hash)[thread + 3 * threads]));
#endif
uint32_t x[2][2][2][2][2] =
{
0xEA2BD4B4, 0xCCD6F29F, 0x63117E71, 0x35481EAE,
0x22512D5B, 0xE5D94E63, 0x7E624131, 0xF4CC12BE,
0xC2D0B696, 0x42AF2070, 0xD0720C35, 0x3361DA8C,
0x28CCECA4, 0x8EF8AD83, 0x4680AC00, 0x40E5FBAB,
0xD89041C3, 0x6107FBD5, 0x6C859D41, 0xF0B26679,
0x09392549, 0x5FA25603, 0x65C892FD, 0x93CB6285,
0x2AF2B5AE, 0x9E4B4E60, 0x774ABFDD, 0x85254725,
0x15815AEB, 0x4AB6AAD6, 0x9CDAF8AF, 0xD6032C0A
};
#if __CUDA_ARCH__ >= 500
x[0][0][0][0][0] ^= Hash[0].x;
x[0][0][0][0][1] ^= Hash[0].y;
x[0][0][0][1][0] ^= Hash[1].x;
x[0][0][0][1][1] ^= Hash[1].y;
x[0][0][1][0][0] ^= Hash[2].x;
x[0][0][1][0][1] ^= Hash[2].y;
x[0][0][1][1][0] ^= Hash[3].x;
x[0][0][1][1][1] ^= Hash[3].y;
#else
x[0][0][0][0][0] ^= Hash[0];
x[0][0][0][0][1] ^= Hash[1];
x[0][0][0][1][0] ^= Hash[2];
x[0][0][0][1][1] ^= Hash[3];
x[0][0][1][0][0] ^= Hash[4];
x[0][0][1][0][1] ^= Hash[5];
x[0][0][1][1][0] ^= Hash[6];
x[0][0][1][1][1] ^= Hash[7];
#endif
rrounds(x);
x[0][0][0][0][0] ^= 0x80U;
rrounds(x);
#if __CUDA_ARCH__ >= 500
Final(x, (uint32_t*)Hash);
g_hash[thread] = Hash[0];
g_hash[1 * threads + thread] = Hash[1];
g_hash[2 * threads + thread] = Hash[2];
g_hash[3 * threads + thread] = Hash[3];
#else
Final(x, Hash);
((uint64_t*)g_hash)[thread] = ((uint64_t*)Hash)[0];
((uint64_t*)g_hash)[1 * threads + thread] = ((uint64_t*)Hash)[1];
((uint64_t*)g_hash)[2 * threads + thread] = ((uint64_t*)Hash)[2];
((uint64_t*)g_hash)[3 * threads + thread] = ((uint64_t*)Hash)[3];
#endif
}
}
__host__
void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_hash, int order)
{
uint32_t tpb = TPB35;
if (cuda_arch[thr_id] >= 500) tpb = TPB50;
dim3 grid((threads + tpb - 1) / tpb);
dim3 block(tpb);
cubehash256_gpu_hash_32 <<<grid, block >>> (threads, startNounce, (uint2*)d_hash);
}
__host__
void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_hash, int order, cudaStream_t stream)
{
uint32_t tpb = TPB35;
if (cuda_arch[thr_id] >= 500) tpb = TPB50;
dim3 grid((threads + tpb - 1) / tpb);
dim3 block(tpb);
cubehash256_gpu_hash_32 <<<grid, block, 0, stream >>> (threads, startNounce, (uint2*)d_hash);
}
+29 -19
View File
@@ -10,14 +10,15 @@
uint32_t *d_fugue256_hashoutput[MAX_GPUS];
static uint32_t *d_resultNonce[MAX_GPUS];
static unsigned int* d_textures[MAX_GPUS][8];
__constant__ uint32_t GPUstate[30]; // Single GPU
__constant__ uint32_t pTarget[8]; // Single GPU
texture<unsigned int, 1, cudaReadModeElementType> mixTab0Tex;
texture<unsigned int, 1, cudaReadModeElementType> mixTab1Tex;
texture<unsigned int, 1, cudaReadModeElementType> mixTab2Tex;
texture<unsigned int, 1, cudaReadModeElementType> mixTab3Tex;
static texture<unsigned int, 1, cudaReadModeElementType> mixTab0Tex;
static texture<unsigned int, 1, cudaReadModeElementType> mixTab1Tex;
static texture<unsigned int, 1, cudaReadModeElementType> mixTab2Tex;
static texture<unsigned int, 1, cudaReadModeElementType> mixTab3Tex;
#if USE_SHARED
#define mixtab0(x) (*((uint32_t*)mixtabs + ( (x))))
@@ -707,48 +708,57 @@ fugue256_gpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outp
}
}
#define texDef(texname, texmem, texsource, texsize) \
#define texDef(id, texname, texmem, texsource, texsize) { \
unsigned int *texmem; \
cudaMalloc(&texmem, texsize); \
d_textures[thr_id][id] = texmem; \
cudaMemcpy(texmem, texsource, texsize, cudaMemcpyHostToDevice); \
texname.normalized = 0; \
texname.filterMode = cudaFilterModePoint; \
texname.addressMode[0] = cudaAddressModeClamp; \
{ cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned int>(); \
cudaBindTexture(NULL, &texname, texmem, &channelDesc, texsize ); }
cudaBindTexture(NULL, &texname, texmem, &channelDesc, texsize ); \
} \
}
__host__
void fugue256_cpu_init(int thr_id, uint32_t threads)
{
// Kopiere die Hash-Tabellen in den GPU-Speicher
texDef(mixTab0Tex, mixTab0m, mixtab0_cpu, sizeof(uint32_t)*256);
texDef(mixTab1Tex, mixTab1m, mixtab1_cpu, sizeof(uint32_t)*256);
texDef(mixTab2Tex, mixTab2m, mixtab2_cpu, sizeof(uint32_t)*256);
texDef(mixTab3Tex, mixTab3m, mixtab3_cpu, sizeof(uint32_t)*256);
// Link the hash tables in the GPU
texDef(0, mixTab0Tex, mixTab0m, mixtab0_cpu, sizeof(uint32_t)*256);
texDef(1, mixTab1Tex, mixTab1m, mixtab1_cpu, sizeof(uint32_t)*256);
texDef(2, mixTab2Tex, mixTab2m, mixtab2_cpu, sizeof(uint32_t)*256);
texDef(3, mixTab3Tex, mixTab3m, mixtab3_cpu, sizeof(uint32_t)*256);
// Speicher für alle Ergebnisse belegen
cudaMalloc(&d_fugue256_hashoutput[thr_id], 8 * sizeof(uint32_t) * threads);
CUDA_SAFE_CALL(cudaMalloc(&d_fugue256_hashoutput[thr_id], (size_t) 32 * threads));
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
}
__host__
void fugue256_cpu_free(int thr_id)
{
cudaFree(d_fugue256_hashoutput[thr_id]);
cudaFree(d_resultNonce[thr_id]);
for (int i=0; i<4; i++)
cudaFree(d_textures[thr_id][i]);
}
__host__
void fugue256_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
{
// CPU-Vorbereitungen treffen
sph_fugue256_context ctx_fugue_const;
sph_fugue256_init(&ctx_fugue_const);
sph_fugue256 (&ctx_fugue_const, data, 80); // State speichern
sph_fugue256 (&ctx_fugue_const, data, 80);
cudaMemcpyToSymbol(GPUstate, ctx_fugue_const.S, sizeof(uint32_t) * 30);
cudaMemcpyToSymbol(pTarget, pTargetIn, sizeof(uint32_t) * 8);
cudaMemcpyToSymbol(pTarget, pTargetIn, 32);
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
}
__host__
void fugue256_cpu_hash(int thr_id, uint32_t threads, int startNounce, void *outputHashes, uint32_t *nounce)
void fugue256_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce)
{
#if USE_SHARED
const uint32_t threadsperblock = 256; // Alignment mit mixtab Grösse. NICHT ÄNDERN
+34 -21
View File
@@ -7,6 +7,7 @@
static uint32_t *h_GNonces[MAX_GPUS];
static uint32_t *d_GNonces[MAX_GPUS];
static unsigned int* d_textures[MAX_GPUS][8];
__constant__ uint32_t pTarget[8];
@@ -66,14 +67,14 @@ __constant__ uint32_t pTarget[8];
#define T3dn(x) tex1Dfetch(t3dn2, x)
#endif
texture<unsigned int, 1, cudaReadModeElementType> t0up2;
texture<unsigned int, 1, cudaReadModeElementType> t0dn2;
texture<unsigned int, 1, cudaReadModeElementType> t1up2;
texture<unsigned int, 1, cudaReadModeElementType> t1dn2;
texture<unsigned int, 1, cudaReadModeElementType> t2up2;
texture<unsigned int, 1, cudaReadModeElementType> t2dn2;
texture<unsigned int, 1, cudaReadModeElementType> t3up2;
texture<unsigned int, 1, cudaReadModeElementType> t3dn2;
static texture<unsigned int, 1, cudaReadModeElementType> t0up2;
static texture<unsigned int, 1, cudaReadModeElementType> t0dn2;
static texture<unsigned int, 1, cudaReadModeElementType> t1up2;
static texture<unsigned int, 1, cudaReadModeElementType> t1dn2;
static texture<unsigned int, 1, cudaReadModeElementType> t2up2;
static texture<unsigned int, 1, cudaReadModeElementType> t2dn2;
static texture<unsigned int, 1, cudaReadModeElementType> t3up2;
static texture<unsigned int, 1, cudaReadModeElementType> t3dn2;
#define RSTT(d0, d1, a, b0, b1, b2, b3, b4, b5, b6, b7) do { \
t[d0] = T0up(B32_0(a[b0])) \
@@ -175,7 +176,7 @@ void groestl256_perm_Q(uint32_t thread, uint32_t *a, char *mixtabs)
}
__global__ __launch_bounds__(256,1)
void groestl256_gpu_hash32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash, uint32_t *resNonces)
void groestl256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash, uint32_t *resNonces)
{
#if USE_SHARED
extern __shared__ char mixtabs[];
@@ -249,34 +250,46 @@ void groestl256_gpu_hash32(uint32_t threads, uint32_t startNounce, uint64_t *out
}
}
#define texDef(texname, texmem, texsource, texsize) \
#define texDef(id, texname, texmem, texsource, texsize) { \
unsigned int *texmem; \
cudaMalloc(&texmem, texsize); \
d_textures[thr_id][id] = texmem; \
cudaMemcpy(texmem, texsource, texsize, cudaMemcpyHostToDevice); \
texname.normalized = 0; \
texname.filterMode = cudaFilterModePoint; \
texname.addressMode[0] = cudaAddressModeClamp; \
{ cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned int>(); \
cudaBindTexture(NULL, &texname, texmem, &channelDesc, texsize ); } \
cudaBindTexture(NULL, &texname, texmem, &channelDesc, texsize ); \
} \
}
__host__
void groestl256_cpu_init(int thr_id, uint32_t threads)
{
// Texturen mit obigem Makro initialisieren
texDef(t0up2, d_T0up, T0up_cpu, sizeof(uint32_t) * 256);
texDef(t0dn2, d_T0dn, T0dn_cpu, sizeof(uint32_t) * 256);
texDef(t1up2, d_T1up, T1up_cpu, sizeof(uint32_t) * 256);
texDef(t1dn2, d_T1dn, T1dn_cpu, sizeof(uint32_t) * 256);
texDef(t2up2, d_T2up, T2up_cpu, sizeof(uint32_t) * 256);
texDef(t2dn2, d_T2dn, T2dn_cpu, sizeof(uint32_t) * 256);
texDef(t3up2, d_T3up, T3up_cpu, sizeof(uint32_t) * 256);
texDef(t3dn2, d_T3dn, T3dn_cpu, sizeof(uint32_t) * 256);
texDef(0, t0up2, d_T0up, T0up_cpu, sizeof(uint32_t) * 256);
texDef(1, t0dn2, d_T0dn, T0dn_cpu, sizeof(uint32_t) * 256);
texDef(2, t1up2, d_T1up, T1up_cpu, sizeof(uint32_t) * 256);
texDef(3, t1dn2, d_T1dn, T1dn_cpu, sizeof(uint32_t) * 256);
texDef(4, t2up2, d_T2up, T2up_cpu, sizeof(uint32_t) * 256);
texDef(5, t2dn2, d_T2dn, T2dn_cpu, sizeof(uint32_t) * 256);
texDef(6, t3up2, d_T3up, T3up_cpu, sizeof(uint32_t) * 256);
texDef(7, t3dn2, d_T3dn, T3dn_cpu, sizeof(uint32_t) * 256);
cudaMalloc(&d_GNonces[thr_id], 2*sizeof(uint32_t));
cudaMallocHost(&h_GNonces[thr_id], 2*sizeof(uint32_t));
}
__host__
void groestl256_cpu_free(int thr_id)
{
for (int i=0; i<8; i++)
cudaFree(d_textures[thr_id][i]);
cudaFree(d_GNonces[thr_id]);
cudaFreeHost(h_GNonces[thr_id]);
}
__host__
uint32_t groestl256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
{
@@ -293,7 +306,7 @@ uint32_t groestl256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNoun
#else
size_t shared_size = 0;
#endif
groestl256_gpu_hash32<<<grid, block, shared_size>>>(threads, startNounce, d_outputHash, d_GNonces[thr_id]);
groestl256_gpu_hash_32<<<grid, block, shared_size>>>(threads, startNounce, d_outputHash, d_GNonces[thr_id]);
MyStreamSynchronize(NULL, order, thr_id);
+350 -269
View File
@@ -1,302 +1,383 @@
#include "miner.h"
/**
* KECCAK-256 CUDA optimised implementation, based on ccminer-alexis code
*/
#include <miner.h>
extern "C" {
#include <stdint.h>
#include <memory.h>
}
#include "cuda_helper.h"
#include <cuda_helper.h>
#include <cuda_vectors.h>
static const uint64_t host_keccak_round_constants[24] = {
0x0000000000000001ull, 0x0000000000008082ull,
0x800000000000808aull, 0x8000000080008000ull,
0x000000000000808bull, 0x0000000080000001ull,
0x8000000080008081ull, 0x8000000000008009ull,
0x000000000000008aull, 0x0000000000000088ull,
0x0000000080008009ull, 0x000000008000000aull,
0x000000008000808bull, 0x800000000000008bull,
0x8000000000008089ull, 0x8000000000008003ull,
0x8000000000008002ull, 0x8000000000000080ull,
0x000000000000800aull, 0x800000008000000aull,
0x8000000080008081ull, 0x8000000000008080ull,
0x0000000080000001ull, 0x8000000080008008ull
#define TPB52 1024
#define TPB50 384
#define NPT 2
#define NBN 2
static uint32_t *d_nonces[MAX_GPUS];
static uint32_t *h_nonces[MAX_GPUS];
__constant__ uint2 c_message48[6];
__constant__ uint2 c_mid[17];
__constant__ uint2 keccak_round_constants[24] = {
{ 0x00000001, 0x00000000 }, { 0x00008082, 0x00000000 }, { 0x0000808a, 0x80000000 }, { 0x80008000, 0x80000000 },
{ 0x0000808b, 0x00000000 }, { 0x80000001, 0x00000000 }, { 0x80008081, 0x80000000 }, { 0x00008009, 0x80000000 },
{ 0x0000008a, 0x00000000 }, { 0x00000088, 0x00000000 }, { 0x80008009, 0x00000000 }, { 0x8000000a, 0x00000000 },
{ 0x8000808b, 0x00000000 }, { 0x0000008b, 0x80000000 }, { 0x00008089, 0x80000000 }, { 0x00008003, 0x80000000 },
{ 0x00008002, 0x80000000 }, { 0x00000080, 0x80000000 }, { 0x0000800a, 0x00000000 }, { 0x8000000a, 0x80000000 },
{ 0x80008081, 0x80000000 }, { 0x00008080, 0x80000000 }, { 0x80000001, 0x00000000 }, { 0x80008008, 0x80000000 }
};
uint32_t *d_nounce[MAX_GPUS];
uint32_t *d_KNonce[MAX_GPUS];
__constant__ uint32_t pTarget[8];
__constant__ uint64_t keccak_round_constants[24];
__constant__ uint64_t c_PaddedMessage80[10]; // padded message (80 bytes + padding?)
#if __CUDA_ARCH__ >= 350
__device__ __forceinline__
static void keccak_blockv35(uint2 *s, const uint64_t *keccak_round_constants)
{
size_t i;
uint2 t[5], u[5], v, w;
#pragma unroll
for (i = 0; i < 24; i++) {
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
u[0] = t[4] ^ ROL2(t[1], 1);
u[1] = t[0] ^ ROL2(t[2], 1);
u[2] = t[1] ^ ROL2(t[3], 1);
u[3] = t[2] ^ ROL2(t[4], 1);
u[4] = t[3] ^ ROL2(t[0], 1);
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
/* rho pi: b[..] = rotl(a[..], ..) */
v = s[1];
s[1] = ROL2(s[6], 44);
s[6] = ROL2(s[9], 20);
s[9] = ROL2(s[22], 61);
s[22] = ROL2(s[14], 39);
s[14] = ROL2(s[20], 18);
s[20] = ROL2(s[2], 62);
s[2] = ROL2(s[12], 43);
s[12] = ROL2(s[13], 25);
s[13] = ROL2(s[19], 8);
s[19] = ROL2(s[23], 56);
s[23] = ROL2(s[15], 41);
s[15] = ROL2(s[4], 27);
s[4] = ROL2(s[24], 14);
s[24] = ROL2(s[21], 2);
s[21] = ROL2(s[8], 55);
s[8] = ROL2(s[16], 45);
s[16] = ROL2(s[5], 36);
s[5] = ROL2(s[3], 28);
s[3] = ROL2(s[18], 21);
s[18] = ROL2(s[17], 15);
s[17] = ROL2(s[11], 10);
s[11] = ROL2(s[7], 6);
s[7] = ROL2(s[10], 3);
s[10] = ROL2(v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
v = s[0]; w = s[1]; s[0] ^= (~w) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & v; s[4] ^= (~v) & w;
v = s[5]; w = s[6]; s[5] ^= (~w) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & v; s[9] ^= (~v) & w;
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
/* iota: a[0,0] ^= round constant */
s[0] ^= vectorize(keccak_round_constants[i]);
}
}
uint2 xor3x(const uint2 a,const uint2 b,const uint2 c) {
uint2 result;
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result.x) : "r"(a.x), "r"(b.x),"r"(c.x)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
asm ("lop3.b32 %0, %1, %2, %3, 0x96;" : "=r"(result.y) : "r"(a.y), "r"(b.y),"r"(c.y)); //0x96 = 0xF0 ^ 0xCC ^ 0xAA
#else
__device__ __forceinline__
static void keccak_blockv30(uint64_t *s, const uint64_t *keccak_round_constants)
{
size_t i;
uint64_t t[5], u[5], v, w;
/* absorb input */
for (i = 0; i < 24; i++) {
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
u[0] = t[4] ^ ROTL64(t[1], 1);
u[1] = t[0] ^ ROTL64(t[2], 1);
u[2] = t[1] ^ ROTL64(t[3], 1);
u[3] = t[2] ^ ROTL64(t[4], 1);
u[4] = t[3] ^ ROTL64(t[0], 1);
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
/* rho pi: b[..] = rotl(a[..], ..) */
v = s[ 1];
s[ 1] = ROTL64(s[ 6], 44);
s[ 6] = ROTL64(s[ 9], 20);
s[ 9] = ROTL64(s[22], 61);
s[22] = ROTL64(s[14], 39);
s[14] = ROTL64(s[20], 18);
s[20] = ROTL64(s[ 2], 62);
s[ 2] = ROTL64(s[12], 43);
s[12] = ROTL64(s[13], 25);
s[13] = ROTL64(s[19], 8);
s[19] = ROTL64(s[23], 56);
s[23] = ROTL64(s[15], 41);
s[15] = ROTL64(s[ 4], 27);
s[ 4] = ROTL64(s[24], 14);
s[24] = ROTL64(s[21], 2);
s[21] = ROTL64(s[ 8], 55);
s[ 8] = ROTL64(s[16], 45);
s[16] = ROTL64(s[ 5], 36);
s[ 5] = ROTL64(s[ 3], 28);
s[ 3] = ROTL64(s[18], 21);
s[18] = ROTL64(s[17], 15);
s[17] = ROTL64(s[11], 10);
s[11] = ROTL64(s[ 7], 6);
s[ 7] = ROTL64(s[10], 3);
s[10] = ROTL64( v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w;
v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w;
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
/* iota: a[0,0] ^= round constant */
s[0] ^= keccak_round_constants[i];
}
}
result = a^b^c;
#endif
__global__ __launch_bounds__(128,5)
void keccak256_gpu_hash_80(uint32_t threads, uint32_t startNounce, void *outputHash, uint32_t *resNounce)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t nounce = startNounce + thread;
#if __CUDA_ARCH__ >= 350
uint2 keccak_gpu_state[25];
#pragma unroll 25
for (int i=0; i<25; i++) {
if (i<9) keccak_gpu_state[i] = vectorize(c_PaddedMessage80[i]);
else keccak_gpu_state[i] = make_uint2(0, 0);
}
keccak_gpu_state[9]= vectorize(c_PaddedMessage80[9]);
keccak_gpu_state[9].y = cuda_swab32(nounce);
keccak_gpu_state[10] = make_uint2(1, 0);
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
keccak_blockv35(keccak_gpu_state,keccak_round_constants);
if (devectorize(keccak_gpu_state[3]) <= ((uint64_t*)pTarget)[3]) {resNounce[0] = nounce;}
#else
uint64_t keccak_gpu_state[25];
#pragma unroll 25
for (int i=0; i<25; i++) {
if (i<9) keccak_gpu_state[i] = c_PaddedMessage80[i];
else keccak_gpu_state[i] = 0;
}
keccak_gpu_state[9] = REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce));
keccak_gpu_state[10] = 0x0000000000000001;
keccak_gpu_state[16] = 0x8000000000000000;
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
if (keccak_gpu_state[3] <= ((uint64_t*)pTarget)[3]) { resNounce[0] = nounce; }
#endif
}
}
__host__
uint32_t keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash, int order)
{
uint32_t result = UINT32_MAX;
cudaMemset(d_KNonce[thr_id], 0xff, sizeof(uint32_t));
const uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
size_t shared_size = 0;
keccak256_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNounce, d_outputHash, d_KNonce[thr_id]);
MyStreamSynchronize(NULL, order, thr_id);
cudaMemcpy(d_nounce[thr_id], d_KNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
cudaThreadSynchronize();
result = *d_nounce[thr_id];
return result;
}
__global__ __launch_bounds__(256,3)
void keccak256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
#if __CUDA_ARCH__ >= 350 /* tpr: to double check if faster on SM5+ */
uint2 keccak_gpu_state[25];
#pragma unroll 25
for (int i = 0; i<25; i++) {
if (i<4) keccak_gpu_state[i] = vectorize(outputHash[i*threads+thread]);
else keccak_gpu_state[i] = make_uint2(0, 0);
}
keccak_gpu_state[4] = make_uint2(1, 0);
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
keccak_blockv35(keccak_gpu_state, keccak_round_constants);
#pragma unroll 4
for (int i=0; i<4; i++)
outputHash[i*threads+thread] = devectorize(keccak_gpu_state[i]);
__device__ __forceinline__
uint2 chi(const uint2 a,const uint2 b,const uint2 c) { // keccak chi
uint2 result;
#if __CUDA_ARCH__ >= 500 && CUDA_VERSION >= 7050
asm ("lop3.b32 %0, %1, %2, %3, 0xD2;" : "=r"(result.x) : "r"(a.x), "r"(b.x),"r"(c.x)); //0xD2 = 0xF0 ^ ((~0xCC) & 0xAA)
asm ("lop3.b32 %0, %1, %2, %3, 0xD2;" : "=r"(result.y) : "r"(a.y), "r"(b.y),"r"(c.y)); //0xD2 = 0xF0 ^ ((~0xCC) & 0xAA)
#else
uint64_t keccak_gpu_state[25];
#pragma unroll 25
for (int i = 0; i<25; i++) {
if (i<4)
keccak_gpu_state[i] = outputHash[i*threads+thread];
else
keccak_gpu_state[i] = 0;
}
keccak_gpu_state[4] = 0x0000000000000001;
keccak_gpu_state[16] = 0x8000000000000000;
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
#pragma unroll 4
for (int i = 0; i<4; i++)
outputHash[i*threads + thread] = keccak_gpu_state[i];
result = a ^ (~b) & c;
#endif
return result;
}
__device__ __forceinline__
uint64_t xor5(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e)
{
uint64_t result;
asm("xor.b64 %0, %1, %2;" : "=l"(result) : "l"(d) ,"l"(e));
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(c));
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(b));
asm("xor.b64 %0, %0, %1;" : "+l"(result) : "l"(a));
return result;
}
#if __CUDA_ARCH__ <= 500
__global__ __launch_bounds__(TPB50, 2)
#else
__global__ __launch_bounds__(TPB52, 1)
#endif
void keccak256_gpu_hash_80(uint32_t threads, uint32_t startNonce, uint32_t *resNounce, const uint2 highTarget)
{
uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
uint2 s[25], t[5], v, w, u[5];
#if __CUDA_ARCH__ > 500
uint64_t step = gridDim.x * blockDim.x;
uint64_t maxNonce = startNonce + threads;
for(uint64_t nounce = startNonce + thread; nounce<maxNonce;nounce+=step) {
#else
uint32_t nounce = startNonce+thread;
if(thread<threads) {
#endif
s[ 9] = make_uint2(c_message48[0].x,cuda_swab32(nounce));
s[10] = keccak_round_constants[0];
t[ 4] = c_message48[1]^s[ 9];
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
u[ 0] = t[4] ^ c_mid[ 0];
u[ 1] = c_mid[ 1] ^ ROL2(t[4],1);
u[ 2] = c_mid[ 2];
/* thetarho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
s[ 7] = ROL2(s[10]^u[0], 3);
s[10] = c_mid[ 3];
w = c_mid[ 4];
s[20] = c_mid[ 5];
s[ 6] = ROL2(s[ 9]^u[2],20);
s[ 9] = c_mid[ 6];
s[22] = c_mid[ 7];
s[14] = ROL2(u[0],18);
s[ 2] = c_mid[ 8];
s[12] = ROL2(u[1],25);
s[13] = c_mid[ 9];
s[19] = ROR8(u[1]);
s[23] = ROR2(u[0],23);
s[15] = c_mid[10];
s[ 4] = c_mid[11];
s[24] = c_mid[12];
s[21] = ROR2(c_message48[2]^u[1], 9);
s[ 8] = c_mid[13];
s[16] = ROR2(c_message48[3]^u[0],28);
s[ 5] = ROL2(c_message48[4]^u[1],28);
s[ 3] = ROL2(u[1],21);
s[18] = c_mid[14];
s[17] = c_mid[15];
s[11] = c_mid[16];
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
v = c_message48[5]^u[0];
s[ 0] = chi(v,w,s[ 2]);
s[ 1] = chi(w,s[ 2],s[ 3]);
s[ 2] = chi(s[ 2],s[ 3],s[ 4]);
s[ 3] = chi(s[ 3],s[ 4],v);
s[ 4] = chi(s[ 4],v,w);
v = s[ 5]; w = s[ 6]; s[ 5] = chi(v,w,s[ 7]); s[ 6] = chi(w,s[ 7],s[ 8]); s[ 7] = chi(s[ 7],s[ 8],s[ 9]); s[ 8] = chi(s[ 8],s[ 9],v);s[ 9] = chi(s[ 9],v,w);
v = s[10]; w = s[11]; s[10] = chi(v,w,s[12]); s[11] = chi(w,s[12],s[13]); s[12] = chi(s[12],s[13],s[14]); s[13] = chi(s[13],s[14],v);s[14] = chi(s[14],v,w);
v = s[15]; w = s[16]; s[15] = chi(v,w,s[17]); s[16] = chi(w,s[17],s[18]); s[17] = chi(s[17],s[18],s[19]); s[18] = chi(s[18],s[19],v);s[19] = chi(s[19],v,w);
v = s[20]; w = s[21]; s[20] = chi(v,w,s[22]); s[21] = chi(w,s[22],s[23]); s[22] = chi(s[22],s[23],s[24]); s[23] = chi(s[23],s[24],v);s[24] = chi(s[24],v,w);
/* iota: a[0,0] ^= round constant */
s[ 0] ^=keccak_round_constants[ 0];
#if __CUDA_ARCH__ > 500
#pragma unroll 22
#else
#pragma unroll 4
#endif
for (int i = 1; i < 23; i++) {
#pragma unroll
for(int j=0;j<5;j++) {
t[ j] = vectorize(xor5(devectorize(s[ j]),devectorize(s[j+5]),devectorize(s[j+10]),devectorize(s[j+15]),devectorize(s[j+20])));
}
/*theta*/
#pragma unroll
for(int j=0;j<5;j++) {
u[j] = ROL2(t[j], 1);
}
s[ 4] = xor3x(s[ 4], t[3], u[0]);s[ 9] = xor3x(s[ 9], t[3], u[0]);s[14] = xor3x(s[14], t[3], u[0]);s[19] = xor3x(s[19], t[3], u[0]);s[24] = xor3x(s[24], t[3], u[0]);
s[ 0] = xor3x(s[ 0], t[4], u[1]);s[ 5] = xor3x(s[ 5], t[4], u[1]);s[10] = xor3x(s[10], t[4], u[1]);s[15] = xor3x(s[15], t[4], u[1]);s[20] = xor3x(s[20], t[4], u[1]);
s[ 1] = xor3x(s[ 1], t[0], u[2]);s[ 6] = xor3x(s[ 6], t[0], u[2]);s[11] = xor3x(s[11], t[0], u[2]);s[16] = xor3x(s[16], t[0], u[2]);s[21] = xor3x(s[21], t[0], u[2]);
s[ 2] = xor3x(s[ 2], t[1], u[3]);s[ 7] = xor3x(s[ 7], t[1], u[3]);s[12] = xor3x(s[12], t[1], u[3]);s[17] = xor3x(s[17], t[1], u[3]);s[22] = xor3x(s[22], t[1], u[3]);
s[ 3] = xor3x(s[ 3], t[2], u[4]);s[ 8] = xor3x(s[ 8], t[2], u[4]);s[13] = xor3x(s[13], t[2], u[4]);s[18] = xor3x(s[18], t[2], u[4]);s[23] = xor3x(s[23], t[2], u[4]);
/*rho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
v = s[ 1];
s[ 1] = ROL2(s[ 6],44); s[ 6] = ROL2(s[ 9],20); s[ 9] = ROL2(s[22],61); s[22] = ROL2(s[14],39);
s[14] = ROL2(s[20],18); s[20] = ROL2(s[ 2],62); s[ 2] = ROL2(s[12],43); s[12] = ROL2(s[13],25);
s[13] = ROL8(s[19]); s[19] = ROR8(s[23]); s[23] = ROL2(s[15],41); s[15] = ROL2(s[ 4],27);
s[ 4] = ROL2(s[24],14); s[24] = ROL2(s[21], 2); s[21] = ROL2(s[ 8],55); s[ 8] = ROL2(s[16],45);
s[16] = ROL2(s[ 5],36); s[ 5] = ROL2(s[ 3],28); s[ 3] = ROL2(s[18],21); s[18] = ROL2(s[17],15);
s[17] = ROL2(s[11],10); s[11] = ROL2(s[ 7], 6); s[ 7] = ROL2(s[10], 3); s[10] = ROL2(v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
#pragma unroll
for(int j=0;j<25;j+=5) {
v=s[j];w=s[j + 1];s[j] = chi(s[j],s[j+1],s[j+2]);s[j+1] = chi(s[j+1],s[j+2],s[j+3]);s[j+2]=chi(s[j+2],s[j+3],s[j+4]);s[j+3]=chi(s[j+3],s[j+4],v);s[j+4]=chi(s[j+4],v,w);
}
/* iota: a[0,0] ^= round constant */
s[ 0] ^=keccak_round_constants[ i];
}
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
#pragma unroll 5
for(int j=0;j<5;j++) {
t[ j] = xor3x(xor3x(s[j+0],s[j+5],s[j+10]), s[j+15], s[j+20]);
}
s[24] = xor3x(s[24],t[3],ROL2(t[0],1));
s[18] = xor3x(s[18],t[2],ROL2(t[4],1));
s[ 0] = xor3x(s[ 0],t[4],ROL2(t[1],1));
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
s[24] = ROL2(s[24],14);
s[18] = ROL2(s[18],21);
if (devectorize(chi(s[18],s[24],s[ 0])) <= devectorize(highTarget)) {
// if(chi(s[18].x,s[24].x,s[0].x)<=highTarget.x) {
// if(chi(s[18].y,s[24].y,s[0].y)<=highTarget.y) {
const uint32_t tmp = atomicExch(&resNounce[0], nounce);
if (tmp != UINT32_MAX)
resNounce[1] = tmp;
// return;
// }
}
}
}
__host__
void keccak256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, const uint2 highTarget)
{
const uint32_t threadsperblock = 256;
uint32_t tpb;
dim3 grid;
if (device_sm[device_map[thr_id]] <= 500) {
tpb = TPB50;
grid.x = (threads + tpb-1)/tpb;
} else {
tpb = TPB52;
grid.x = (threads + (NPT*tpb)-1)/(NPT*tpb);
}
const dim3 block(tpb);
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
keccak256_gpu_hash_80<<<grid, block>>>(threads, startNonce, d_nonces[thr_id], highTarget);
// cudaThreadSynchronize();
cudaMemcpy(h_nonces[thr_id], d_nonces[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost);
memcpy(resNonces, h_nonces[thr_id], NBN*sizeof(uint32_t));
}
keccak256_gpu_hash_32 <<<grid, block>>> (threads, startNounce, d_outputHash);
MyStreamSynchronize(NULL, order, thr_id);
#if 0
#if __CUDA_ARCH__ <= 500
__global__ __launch_bounds__(TPB50, 2)
#else
__global__ __launch_bounds__(TPB52, 1)
#endif
void keccak256_gpu_hash_32(uint32_t threads, uint2* outputHash)
{
uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
uint2 s[25], t[5], v, w, u[5];
if(thread < threads) {
#pragma unroll 25
for (int i = 0; i<25; i++) {
if (i<4) s[i] = __ldg(&outputHash[i*threads+thread]);
else s[i] = make_uint2(0, 0);
}
s[4] = keccak_round_constants[ 0];
s[16] = make_uint2(0, 0x80000000);
#if __CUDA_ARCH__ > 500
#pragma unroll
#else
#pragma unroll 4
#endif
for (uint32_t i = 0; i < 23; i++) {
/*theta*/
#pragma unroll 5
for(int j=0; j<5; j++) {
t[ j] = vectorize(xor5(devectorize(s[ j]),devectorize(s[j+5]),devectorize(s[j+10]),devectorize(s[j+15]),devectorize(s[j+20])));
}
/*theta*/
#pragma unroll 5
for(int j=0; j<5; j++) {
u[j] = ROL2(t[j], 1);
}
s[ 4] = xor3x(s[ 4], t[3], u[0]);s[ 9] = xor3x(s[ 9], t[3], u[0]);s[14] = xor3x(s[14], t[3], u[0]);s[19] = xor3x(s[19], t[3], u[0]);s[24] = xor3x(s[24], t[3], u[0]);
s[ 0] = xor3x(s[ 0], t[4], u[1]);s[ 5] = xor3x(s[ 5], t[4], u[1]);s[10] = xor3x(s[10], t[4], u[1]);s[15] = xor3x(s[15], t[4], u[1]);s[20] = xor3x(s[20], t[4], u[1]);
s[ 1] = xor3x(s[ 1], t[0], u[2]);s[ 6] = xor3x(s[ 6], t[0], u[2]);s[11] = xor3x(s[11], t[0], u[2]);s[16] = xor3x(s[16], t[0], u[2]);s[21] = xor3x(s[21], t[0], u[2]);
s[ 2] = xor3x(s[ 2], t[1], u[3]);s[ 7] = xor3x(s[ 7], t[1], u[3]);s[12] = xor3x(s[12], t[1], u[3]);s[17] = xor3x(s[17], t[1], u[3]);s[22] = xor3x(s[22], t[1], u[3]);
s[ 3] = xor3x(s[ 3], t[2], u[4]);s[ 8] = xor3x(s[ 8], t[2], u[4]);s[13] = xor3x(s[13], t[2], u[4]);s[18] = xor3x(s[18], t[2], u[4]);s[23] = xor3x(s[23], t[2], u[4]);
/*rho pi: b[..] = rotl(a[..] ^ d[...], ..)*/
v = s[ 1];
s[ 1] = ROL2(s[ 6],44); s[ 6] = ROL2(s[ 9],20); s[ 9] = ROL2(s[22],61); s[22] = ROL2(s[14],39);
s[14] = ROL2(s[20],18); s[20] = ROL2(s[ 2],62); s[ 2] = ROL2(s[12],43); s[12] = ROL2(s[13],25);
s[13] = ROL8(s[19]); s[19] = ROR8(s[23]); s[23] = ROL2(s[15],41); s[15] = ROL2(s[ 4],27);
s[ 4] = ROL2(s[24],14); s[24] = ROL2(s[21], 2); s[21] = ROL2(s[ 8],55); s[ 8] = ROL2(s[16],45);
s[16] = ROL2(s[ 5],36); s[ 5] = ROL2(s[ 3],28); s[ 3] = ROL2(s[18],21); s[18] = ROL2(s[17],15);
s[17] = ROL2(s[11],10); s[11] = ROL2(s[ 7], 6); s[ 7] = ROL2(s[10], 3); s[10] = ROL2(v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
#pragma unroll 5
for(int j=0; j<25; j+=5) {
v=s[j];w=s[j + 1]; s[j] = chi(v,w,s[j+2]); s[j+1] = chi(w,s[j+2],s[j+3]); s[j+2]=chi(s[j+2],s[j+3],s[j+4]); s[j+3]=chi(s[j+3],s[j+4],v); s[j+4]=chi(s[j+4],v,w);
}
/* iota: a[0,0] ^= round constant */
s[ 0] ^=keccak_round_constants[ i];
}
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
#pragma unroll 5
for(int j=0;j<5;j++) {
t[ j] = xor3x(xor3x(s[j+0],s[j+5],s[j+10]), s[j+15], s[j+20]);
}
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
#pragma unroll 5
for(int j=0;j<5;j++) {
u[j] = ROL2(t[j],1);
}
/* thetarho pi: b[..] = rotl(a[..] ^ d[...], ..) //There's no need to perform theta and -store- the result since it's unique for each a[..]*/
s[ 4] = xor3x(s[24], t[3], u[0]);
s[ 0] = xor3x(s[ 0], t[4], u[1]);
s[ 1] = xor3x(s[ 6], t[0], u[2]);
s[ 2] = xor3x(s[12], t[1], u[3]);
s[ 3] = xor3x(s[18], t[2], u[4]);
s[ 1] = ROR2(s[ 1],20);
s[ 2] = ROR2(s[ 2],21);
s[ 3] = ROL2(s[ 3],21);
s[ 4] = ROL2(s[ 4],14);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
outputHash[0*threads+thread] = chi(s[ 0],s[ 1],s[ 2]) ^ keccak_round_constants[23];
outputHash[1*threads+thread] = chi(s[ 1],s[ 2],s[ 3]);
outputHash[2*threads+thread] = chi(s[ 2],s[ 3],s[ 4]);
outputHash[3*threads+thread] = chi(s[ 3],s[ 4],s[ 0]);
}
}
__host__
void keccak256_setBlock_80(void *pdata,const void *pTargetIn)
void keccak256_cpu_hash_32(const int thr_id,const uint32_t threads, uint2* d_hash)
{
unsigned char PaddedMessage[80];
memcpy(PaddedMessage, pdata, 80);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, pTargetIn, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 10*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
uint32_t tpb = TPB52;
if (device_sm[device_map[thr_id]] == 500) tpb = TPB50;
const dim3 grid((threads + tpb-1)/tpb);
const dim3 block(tpb);
keccak256_gpu_hash_32 <<<grid, block>>> (threads, d_hash);
}
#endif
__host__
void keccak256_setBlock_80(uint64_t *endiandata)
{
uint64_t midstate[17], s[25];
uint64_t t[5], u[5];
s[10] = 1; //(uint64_t)make_uint2(1, 0);
s[16] = ((uint64_t)1)<<63; //(uint64_t)make_uint2(0, 0x80000000);
t[0] = endiandata[0] ^ endiandata[5] ^ s[10];
t[1] = endiandata[1] ^ endiandata[6] ^ s[16];
t[2] = endiandata[2] ^ endiandata[7];
t[3] = endiandata[3] ^ endiandata[8];
midstate[ 0] = ROTL64(t[1], 1); //u[0] -partial
u[1] = t[ 0] ^ ROTL64(t[2], 1); //u[1]
u[2] = t[ 1] ^ ROTL64(t[3], 1); //u[2]
midstate[ 1] = t[ 2]; //u[3] -partial
midstate[ 2] = t[ 3] ^ ROTL64(t[0], 1); //u[4]
midstate[ 3] = ROTL64(endiandata[1]^u[1], 1); //v
midstate[ 4] = ROTL64(endiandata[6]^u[1], 44);
midstate[ 5] = ROTL64(endiandata[2]^u[2], 62);
midstate[ 6] = ROTL64(u[2], 61);
midstate[ 7] = ROTL64(midstate[2], 39);
midstate[ 8] = ROTL64(u[2], 43);
midstate[ 9] = ROTL64(midstate[2], 8);
midstate[10] = ROTL64(endiandata[4]^midstate[ 2],27);
midstate[11] = ROTL64(midstate[2], 14);
midstate[12] = ROTL64(u[1], 2);
midstate[13] = ROTL64(s[16] ^ u[1], 45);
midstate[14] = ROTL64(u[2],15);
midstate[15] = ROTL64(u[1],10);
midstate[16] = ROTL64(endiandata[7]^u[2], 6);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_mid, midstate,17*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
// pass only what's needed
uint64_t message48[6];
message48[0] = endiandata[9];
message48[1] = endiandata[4];
message48[2] = endiandata[8];
message48[3] = endiandata[5];
message48[4] = endiandata[3];
message48[5] = endiandata[0];
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_message48, message48, 6*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
}
__host__
void keccak256_cpu_init(int thr_id, uint32_t threads)
void keccak256_cpu_init(int thr_id)
{
CUDA_SAFE_CALL(cudaMemcpyToSymbol(keccak_round_constants, host_keccak_round_constants,
sizeof(host_keccak_round_constants), 0, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMalloc(&d_KNonce[thr_id], sizeof(uint32_t)));
CUDA_SAFE_CALL(cudaMallocHost(&d_nounce[thr_id], 1*sizeof(uint32_t)));
CUDA_SAFE_CALL(cudaMalloc(&d_nonces[thr_id], NBN*sizeof(uint32_t)));
//CUDA_SAFE_CALL(cudaMallocHost(&h_nonces[thr_id], NBN*sizeof(uint32_t)));
h_nonces[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t));
if(h_nonces[thr_id] == NULL) {
gpulog(LOG_ERR,thr_id,"Host memory allocation failed");
exit(EXIT_FAILURE);
}
}
__host__
void keccak256_setOutput(int thr_id)
{
CUDA_SAFE_CALL(cudaMemset(d_nonces[thr_id], 0xff, NBN*sizeof(uint32_t)));
}
__host__
void keccak256_cpu_free(int thr_id)
{
cudaFree(d_nonces[thr_id]);
//cudaFreeHost(h_nonces[thr_id]);
free(h_nonces[thr_id]);
}
+303
View File
@@ -0,0 +1,303 @@
#include "miner.h"
extern "C" {
#include <stdint.h>
#include <memory.h>
}
#include "cuda_helper.h"
static const uint64_t host_keccak_round_constants[24] = {
0x0000000000000001ull, 0x0000000000008082ull,
0x800000000000808aull, 0x8000000080008000ull,
0x000000000000808bull, 0x0000000080000001ull,
0x8000000080008081ull, 0x8000000000008009ull,
0x000000000000008aull, 0x0000000000000088ull,
0x0000000080008009ull, 0x000000008000000aull,
0x000000008000808bull, 0x800000000000008bull,
0x8000000000008089ull, 0x8000000000008003ull,
0x8000000000008002ull, 0x8000000000000080ull,
0x000000000000800aull, 0x800000008000000aull,
0x8000000080008081ull, 0x8000000000008080ull,
0x0000000080000001ull, 0x8000000080008008ull
};
static uint32_t *d_KNonce[MAX_GPUS];
__constant__ uint32_t pTarget[8];
__constant__ uint64_t keccak_round_constants[24];
__constant__ uint64_t c_PaddedMessage80[10]; // padded message (80 bytes + padding?)
#if __CUDA_ARCH__ >= 350
__device__ __forceinline__
static void keccak_blockv35(uint2 *s, const uint64_t *keccak_round_constants)
{
size_t i;
uint2 t[5], u[5], v, w;
#pragma unroll
for (i = 0; i < 24; i++) {
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
u[0] = t[4] ^ ROL2(t[1], 1);
u[1] = t[0] ^ ROL2(t[2], 1);
u[2] = t[1] ^ ROL2(t[3], 1);
u[3] = t[2] ^ ROL2(t[4], 1);
u[4] = t[3] ^ ROL2(t[0], 1);
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
/* rho pi: b[..] = rotl(a[..], ..) */
v = s[1];
s[1] = ROL2(s[6], 44);
s[6] = ROL2(s[9], 20);
s[9] = ROL2(s[22], 61);
s[22] = ROL2(s[14], 39);
s[14] = ROL2(s[20], 18);
s[20] = ROL2(s[2], 62);
s[2] = ROL2(s[12], 43);
s[12] = ROL2(s[13], 25);
s[13] = ROL2(s[19], 8);
s[19] = ROL2(s[23], 56);
s[23] = ROL2(s[15], 41);
s[15] = ROL2(s[4], 27);
s[4] = ROL2(s[24], 14);
s[24] = ROL2(s[21], 2);
s[21] = ROL2(s[8], 55);
s[8] = ROL2(s[16], 45);
s[16] = ROL2(s[5], 36);
s[5] = ROL2(s[3], 28);
s[3] = ROL2(s[18], 21);
s[18] = ROL2(s[17], 15);
s[17] = ROL2(s[11], 10);
s[11] = ROL2(s[7], 6);
s[7] = ROL2(s[10], 3);
s[10] = ROL2(v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
v = s[0]; w = s[1]; s[0] ^= (~w) & s[2]; s[1] ^= (~s[2]) & s[3]; s[2] ^= (~s[3]) & s[4]; s[3] ^= (~s[4]) & v; s[4] ^= (~v) & w;
v = s[5]; w = s[6]; s[5] ^= (~w) & s[7]; s[6] ^= (~s[7]) & s[8]; s[7] ^= (~s[8]) & s[9]; s[8] ^= (~s[9]) & v; s[9] ^= (~v) & w;
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
/* iota: a[0,0] ^= round constant */
s[0] ^= vectorize(keccak_round_constants[i]);
}
}
#else
__device__ __forceinline__
static void keccak_blockv30(uint64_t *s, const uint64_t *keccak_round_constants)
{
size_t i;
uint64_t t[5], u[5], v, w;
/* absorb input */
for (i = 0; i < 24; i++) {
/* theta: c = a[0,i] ^ a[1,i] ^ .. a[4,i] */
t[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
t[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
t[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
t[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
t[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
/* theta: d[i] = c[i+4] ^ rotl(c[i+1],1) */
u[0] = t[4] ^ ROTL64(t[1], 1);
u[1] = t[0] ^ ROTL64(t[2], 1);
u[2] = t[1] ^ ROTL64(t[3], 1);
u[3] = t[2] ^ ROTL64(t[4], 1);
u[4] = t[3] ^ ROTL64(t[0], 1);
/* theta: a[0,i], a[1,i], .. a[4,i] ^= d[i] */
s[0] ^= u[0]; s[5] ^= u[0]; s[10] ^= u[0]; s[15] ^= u[0]; s[20] ^= u[0];
s[1] ^= u[1]; s[6] ^= u[1]; s[11] ^= u[1]; s[16] ^= u[1]; s[21] ^= u[1];
s[2] ^= u[2]; s[7] ^= u[2]; s[12] ^= u[2]; s[17] ^= u[2]; s[22] ^= u[2];
s[3] ^= u[3]; s[8] ^= u[3]; s[13] ^= u[3]; s[18] ^= u[3]; s[23] ^= u[3];
s[4] ^= u[4]; s[9] ^= u[4]; s[14] ^= u[4]; s[19] ^= u[4]; s[24] ^= u[4];
/* rho pi: b[..] = rotl(a[..], ..) */
v = s[ 1];
s[ 1] = ROTL64(s[ 6], 44);
s[ 6] = ROTL64(s[ 9], 20);
s[ 9] = ROTL64(s[22], 61);
s[22] = ROTL64(s[14], 39);
s[14] = ROTL64(s[20], 18);
s[20] = ROTL64(s[ 2], 62);
s[ 2] = ROTL64(s[12], 43);
s[12] = ROTL64(s[13], 25);
s[13] = ROTL64(s[19], 8);
s[19] = ROTL64(s[23], 56);
s[23] = ROTL64(s[15], 41);
s[15] = ROTL64(s[ 4], 27);
s[ 4] = ROTL64(s[24], 14);
s[24] = ROTL64(s[21], 2);
s[21] = ROTL64(s[ 8], 55);
s[ 8] = ROTL64(s[16], 45);
s[16] = ROTL64(s[ 5], 36);
s[ 5] = ROTL64(s[ 3], 28);
s[ 3] = ROTL64(s[18], 21);
s[18] = ROTL64(s[17], 15);
s[17] = ROTL64(s[11], 10);
s[11] = ROTL64(s[ 7], 6);
s[ 7] = ROTL64(s[10], 3);
s[10] = ROTL64( v, 1);
/* chi: a[i,j] ^= ~b[i,j+1] & b[i,j+2] */
v = s[ 0]; w = s[ 1]; s[ 0] ^= (~w) & s[ 2]; s[ 1] ^= (~s[ 2]) & s[ 3]; s[ 2] ^= (~s[ 3]) & s[ 4]; s[ 3] ^= (~s[ 4]) & v; s[ 4] ^= (~v) & w;
v = s[ 5]; w = s[ 6]; s[ 5] ^= (~w) & s[ 7]; s[ 6] ^= (~s[ 7]) & s[ 8]; s[ 7] ^= (~s[ 8]) & s[ 9]; s[ 8] ^= (~s[ 9]) & v; s[ 9] ^= (~v) & w;
v = s[10]; w = s[11]; s[10] ^= (~w) & s[12]; s[11] ^= (~s[12]) & s[13]; s[12] ^= (~s[13]) & s[14]; s[13] ^= (~s[14]) & v; s[14] ^= (~v) & w;
v = s[15]; w = s[16]; s[15] ^= (~w) & s[17]; s[16] ^= (~s[17]) & s[18]; s[17] ^= (~s[18]) & s[19]; s[18] ^= (~s[19]) & v; s[19] ^= (~v) & w;
v = s[20]; w = s[21]; s[20] ^= (~w) & s[22]; s[21] ^= (~s[22]) & s[23]; s[22] ^= (~s[23]) & s[24]; s[23] ^= (~s[24]) & v; s[24] ^= (~v) & w;
/* iota: a[0,0] ^= round constant */
s[0] ^= keccak_round_constants[i];
}
}
#endif
__global__ __launch_bounds__(128,5)
void keccak256_sm3_gpu_hash_80(uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t nounce = startNounce + thread;
#if __CUDA_ARCH__ >= 350
uint2 keccak_gpu_state[25];
#pragma unroll 25
for (int i=0; i<25; i++) {
if (i<9) keccak_gpu_state[i] = vectorize(c_PaddedMessage80[i]);
else keccak_gpu_state[i] = make_uint2(0, 0);
}
keccak_gpu_state[9]= vectorize(c_PaddedMessage80[9]);
keccak_gpu_state[9].y = cuda_swab32(nounce);
keccak_gpu_state[10] = make_uint2(1, 0);
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
keccak_blockv35(keccak_gpu_state,keccak_round_constants);
if (devectorize(keccak_gpu_state[3]) <= ((uint64_t*)pTarget)[3]) {resNounce[0] = nounce;}
#else
uint64_t keccak_gpu_state[25];
#pragma unroll 25
for (int i=0; i<25; i++) {
if (i<9) keccak_gpu_state[i] = c_PaddedMessage80[i];
else keccak_gpu_state[i] = 0;
}
keccak_gpu_state[9] = REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce));
keccak_gpu_state[10] = 0x0000000000000001;
keccak_gpu_state[16] = 0x8000000000000000;
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
if (keccak_gpu_state[3] <= ((uint64_t*)pTarget)[3]) { resNounce[0] = nounce; }
#endif
}
}
__host__
void keccak256_sm3_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonces, int order)
{
cudaMemset(d_KNonce[thr_id], 0xff, 2*sizeof(uint32_t));
const uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
size_t shared_size = 0;
keccak256_sm3_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNounce, d_KNonce[thr_id]);
cudaMemcpy(resNonces, d_KNonce[thr_id], 2*sizeof(uint32_t), cudaMemcpyDeviceToHost);
cudaThreadSynchronize();
}
#if 0
__global__ __launch_bounds__(256,3)
void keccak256_sm3_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
#if __CUDA_ARCH__ >= 350 /* tpr: to double check if faster on SM5+ */
uint2 keccak_gpu_state[25];
#pragma unroll 25
for (int i = 0; i<25; i++) {
if (i<4) keccak_gpu_state[i] = vectorize(outputHash[i*threads+thread]);
else keccak_gpu_state[i] = make_uint2(0, 0);
}
keccak_gpu_state[4] = make_uint2(1, 0);
keccak_gpu_state[16] = make_uint2(0, 0x80000000);
keccak_blockv35(keccak_gpu_state, keccak_round_constants);
#pragma unroll 4
for (int i=0; i<4; i++)
outputHash[i*threads+thread] = devectorize(keccak_gpu_state[i]);
#else
uint64_t keccak_gpu_state[25];
#pragma unroll 25
for (int i = 0; i<25; i++) {
if (i<4)
keccak_gpu_state[i] = outputHash[i*threads+thread];
else
keccak_gpu_state[i] = 0;
}
keccak_gpu_state[4] = 0x0000000000000001;
keccak_gpu_state[16] = 0x8000000000000000;
keccak_blockv30(keccak_gpu_state, keccak_round_constants);
#pragma unroll 4
for (int i = 0; i<4; i++)
outputHash[i*threads + thread] = keccak_gpu_state[i];
#endif
}
}
__host__
void keccak256_sm3_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
keccak256_sm3_gpu_hash_32 <<<grid, block>>> (threads, startNounce, d_outputHash);
MyStreamSynchronize(NULL, order, thr_id);
}
#endif
__host__
void keccak256_sm3_setBlock_80(void *pdata,const void *pTargetIn)
{
unsigned char PaddedMessage[80];
memcpy(PaddedMessage, pdata, 80);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, pTargetIn, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 10*sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
}
__host__
void keccak256_sm3_init(int thr_id, uint32_t threads)
{
CUDA_SAFE_CALL(cudaMemcpyToSymbol(keccak_round_constants, host_keccak_round_constants,
sizeof(host_keccak_round_constants), 0, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMalloc(&d_KNonce[thr_id], 2*sizeof(uint32_t)));
}
__host__
void keccak256_sm3_free(int thr_id)
{
cudaFree(d_KNonce[thr_id]);
}
+151 -137
View File
@@ -2,79 +2,40 @@
#include "cuda_helper.h"
static __constant__ uint64_t SKEIN_IV512_256[8] = {
0xCCD044A12FDB3E13, 0xE83590301A79A9EB,
0x55AEA0614F816E6F, 0x2A2767A4AE9B94DB,
0xEC06025E74DD7683, 0xE7A436CDC4746251,
0xC36FBAF9393AD185, 0x3EEDBA1833EDFC13
};
static __constant__ uint2 vSKEIN_IV512_256[8] = {
{ 0x2FDB3E13, 0xCCD044A1 },
{ 0x1A79A9EB, 0xE8359030 },
{ 0x4F816E6F, 0x55AEA061 },
{ 0xAE9B94DB, 0x2A2767A4 },
{ 0x74DD7683, 0xEC06025E },
{ 0xC4746251, 0xE7A436CD },
{ 0x393AD185, 0xC36FBAF9 },
{ 0x33EDFC13, 0x3EEDBA18 }
};
static __constant__ int8_t ROT256[8][4] = {
46, 36, 19, 37,
33, 27, 14, 42,
17, 49, 36, 39,
44, 9, 54, 56,
39, 30, 34, 24,
13, 50, 10, 17,
25, 29, 39, 43,
8, 35, 56, 22,
};
static __constant__ uint2 t12[6] = {
{ 0x20, 0 },
{ 0, 0xf0000000 },
{ 0x20, 0xf0000000 },
{ 0x08, 0 },
{ 0, 0xff000000 },
{ 0x08, 0xff000000 }
};
static __constant__ uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
static __constant__ uint64_t skein_ks_parity64 = 0x1BD11BDAA9FC1A22ull;
static __forceinline__ __device__
void Round512v35(uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int ROT)
void Round512v35(uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7,
const int ROT0, const int ROT1, const int ROT2, const int ROT3)
{
p0 += p1; p1 = ROL2(p1, ROT256[ROT][0]) ^ p0;
p2 += p3; p3 = ROL2(p3, ROT256[ROT][1]) ^ p2;
p4 += p5; p5 = ROL2(p5, ROT256[ROT][2]) ^ p4;
p6 += p7; p7 = ROL2(p7, ROT256[ROT][3]) ^ p6;
p0 += p1; p1 = ROL2(p1, ROT0) ^ p0;
p2 += p3; p3 = ROL2(p3, ROT1) ^ p2;
p4 += p5; p5 = ROL2(p5, ROT2) ^ p4;
p6 += p7; p7 = ROL2(p7, ROT3) ^ p6;
}
static __forceinline__ __device__
void Round_8_512v35(uint2 *ks, uint2 *ts,
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3,
uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int R)
__forceinline__ __device__
void Round_8_512v35(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int R)
{
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 0);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 1);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 2);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 3);
p0 += ks[(R+0) % 9]; /* inject the key schedule value */
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
p0 += ks[(R+0) % 9];
p1 += ks[(R+1) % 9];
p2 += ks[(R+2) % 9];
p3 += ks[(R+3) % 9];
p4 += ks[(R+4) % 9];
p5 += ks[(R+5) % 9] + ts[(R+0) % 3];
p6 += ks[(R+6) % 9] + ts[(R+1) % 3];
p7 += ks[(R+7) % 9] + make_uint2((R),0);
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 4);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 5);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 6);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 7);
p0 += ks[(R+1) % 9]; /* inject the key schedule value */
p7 += ks[(R+7) % 9] + make_uint2(R, 0);
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
p0 += ks[(R+1) % 9];
p1 += ks[(R+2) % 9];
p2 += ks[(R+3) % 9];
p3 += ks[(R+4) % 9];
@@ -84,39 +45,90 @@ void Round_8_512v35(uint2 *ks, uint2 *ts,
p7 += ks[(R+8) % 9] + make_uint2(R+1, 0);
}
__forceinline__ __device__
void Round_8_512v35_final(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
{
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
p0 += ks[8];
p1 += ks[0];
p2 += ks[1];
p3 += ks[2];
p4 += ks[3];
p5 += ks[4] + ts[2];
p6 += ks[5] + ts[0];
p7 += ks[6] + make_uint2(17, 0);
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
p0 += ks[0];
p1 += ks[1];
p2 += ks[2];
p3 += ks[3];
}
__global__ __launch_bounds__(256,3)
void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint2 h[9], t[3] = { t12[0], t12[1], t12[2] };
const uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
const uint2 t12[6] = {
{ 0x20, 0 },
{ 0, 0xf0000000 },
{ 0x20, 0xf0000000 },
{ 0x08, 0 },
{ 0, 0xff000000 },
{ 0x08, 0xff000000 }
};
h[8] = skein_ks_parity;
for (int i = 0; i<8; i++) {
h[i] = vSKEIN_IV512_256[i];
h[8] ^= h[i];
}
uint2 h[9] = {
{ 0x2FDB3E13, 0xCCD044A1 },
{ 0x1A79A9EB, 0xE8359030 },
{ 0x4F816E6F, 0x55AEA061 },
{ 0xAE9B94DB, 0x2A2767A4 },
{ 0x74DD7683, 0xEC06025E },
{ 0xC4746251, 0xE7A436CD },
{ 0x393AD185, 0xC36FBAF9 },
{ 0x33EDFC13, 0x3EEDBA18 },
{ 0xC73A4E2A, 0xB69D3CFC }
};
uint2 dt0,dt1,dt2,dt3;
uint2 p0, p1, p2, p3, p4, p5, p6, p7;
uint2 dt0 = vectorize(outputHash[thread]);
uint2 dt1 = vectorize(outputHash[threads + thread]);
uint2 dt2 = vectorize(outputHash[threads*2 + thread]);
uint2 dt3 = vectorize(outputHash[threads*3 + thread]);
LOHI(dt0.x,dt0.y,outputHash[thread]);
LOHI(dt1.x,dt1.y,outputHash[threads+thread]);
LOHI(dt2.x,dt2.y,outputHash[2*threads+thread]);
LOHI(dt3.x,dt3.y,outputHash[3*threads+thread]);
uint2 p0 = h[0] + dt0;
uint2 p1 = h[1] + dt1;
uint2 p2 = h[2] + dt2;
uint2 p3 = h[3] + dt3;
uint2 p4 = h[4];
uint2 p5 = h[5] + t[0];
uint2 p6 = h[6] + t[1];
uint2 p7 = h[7];
p0 = h[0] + dt0;
p1 = h[1] + dt1;
p2 = h[2] + dt2;
p3 = h[3] + dt3;
p4 = h[4];
p5 = h[5] + t12[0];
p6 = h[6] + t12[1];
p7 = h[7];
#pragma unroll 9
for (int i = 1; i<19; i+=2) {
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, i);
}
// forced unroll required
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 1);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 3);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 5);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 7);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 9);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 11);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 13);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 15);
Round_8_512v35(h, t12, p0, p1, p2, p3, p4, p5, p6, p7, 17);
p0 ^= dt0;
p1 ^= dt1;
@@ -131,51 +143,52 @@ void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outp
h[5] = p5;
h[6] = p6;
h[7] = p7;
h[8] = skein_ks_parity;
h[8] = skein_ks_parity ^ h[0] ^ h[1] ^ h[2] ^ h[3] ^ h[4] ^ h[5] ^ h[6] ^ h[7];
#pragma unroll 8
for (int i = 0; i<8; i++) {
h[8] ^= h[i];
}
const uint2 *t = t12+3;
p5 += t12[3]; //p5 already equal h[5]
p6 += t12[4];
t[0] = t12[3];
t[1] = t12[4];
t[2] = t12[5];
// forced unroll
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 1);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 3);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 5);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 7);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 9);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 11);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 13);
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, 15);
Round_8_512v35_final(h, t, p0, p1, p2, p3, p4, p5, p6, p7);
p5 += t[0];
p6 += t[1];
#pragma unroll 9
for (int i = 1; i<19; i+=2) {
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, i);
}
outputHash[thread] = devectorize(p0);
outputHash[threads + thread] = devectorize(p1);
outputHash[threads*2 + thread] = devectorize(p2);
outputHash[threads*3 + thread] = devectorize(p3);
outputHash[thread] = devectorize(p0);
outputHash[threads+thread] = devectorize(p1);
outputHash[2*threads+thread] = devectorize(p2);
outputHash[3*threads+thread] = devectorize(p3);
}
}
static __forceinline__ __device__
void Round512v30(uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7, int ROT)
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7,
const int ROT0, const int ROT1, const int ROT2, const int ROT3)
{
p0 += p1; p1 = ROTL64(p1, ROT256[ROT][0]) ^ p0;
p2 += p3; p3 = ROTL64(p3, ROT256[ROT][1]) ^ p2;
p4 += p5; p5 = ROTL64(p5, ROT256[ROT][2]) ^ p4;
p6 += p7; p7 = ROTL64(p7, ROT256[ROT][3]) ^ p6;
p0 += p1; p1 = ROTL64(p1, ROT0) ^ p0;
p2 += p3; p3 = ROTL64(p3, ROT1) ^ p2;
p4 += p5; p5 = ROTL64(p5, ROT2) ^ p4;
p6 += p7; p7 = ROTL64(p7, ROT3) ^ p6;
}
static __forceinline__ __device__
void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
void Round_8_512v30(uint64_t *ks, uint64_t *ts,
uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7, int R)
{
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 0);
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 1);
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 2);
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 3);
p0 += ks[(R+0) % 9]; /* inject the key schedule value */
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
p0 += ks[(R+0) % 9];
p1 += ks[(R+1) % 9];
p2 += ks[(R+2) % 9];
p3 += ks[(R+3) % 9];
@@ -183,11 +196,13 @@ void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint
p5 += ks[(R+5) % 9] + ts[(R+0) % 3];
p6 += ks[(R+6) % 9] + ts[(R+1) % 3];
p7 += ks[(R+7) % 9] + R;
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 4);
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 5);
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 6);
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 7);
p0 += ks[(R+1) % 9]; /* inject the key schedule value */
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
p0 += ks[(R+1) % 9];
p1 += ks[(R+2) % 9];
p2 += ks[(R+3) % 9];
p3 += ks[(R+4) % 9];
@@ -197,29 +212,28 @@ void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint
p7 += ks[(R+8) % 9] + R+1;
}
#define skein_ks_parity64 0x1BD11BDAA9FC1A22ull
#include <stdio.h>
__global__ __launch_bounds__(256, 3)
void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint64_t h[9], t[3];
h[8] = skein_ks_parity64;
for (int i = 0; i<8; i++) {
h[i] = SKEIN_IV512_256[i];
h[8] ^= h[i];
}
t[0] = devectorize(t12[0]);
t[1] = devectorize(t12[1]);
t[2] = devectorize(t12[2]);
uint64_t h[12] = { // SKEIN_IV512_256
0xCCD044A12FDB3E13, 0xE83590301A79A9EB,
0x55AEA0614F816E6F, 0x2A2767A4AE9B94DB,
0xEC06025E74DD7683, 0xE7A436CDC4746251,
0xC36FBAF9393AD185, 0x3EEDBA1833EDFC13,
0xb69d3cfcc73a4e2a, // skein_ks_parity64 ^ h[0..7]
0x20, 0xf000000000000000, 0xf000000000000020 // t0..2
};
uint64_t dt0 = outputHash[thread];
uint64_t dt1 = outputHash[threads + thread];
uint64_t dt2 = outputHash[threads*2 + thread];
uint64_t dt3 = outputHash[threads*3 + thread];
uint64_t *t = &h[9];
uint64_t p0 = h[0] + dt0;
uint64_t p1 = h[1] + dt1;
uint64_t p2 = h[2] + dt2;
@@ -254,9 +268,9 @@ void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *
h[8] ^= h[i];
}
t[0] = devectorize(t12[3]);
t[1] = devectorize(t12[4]);
t[2] = devectorize(t12[5]);
t[0] = 0x08;
t[1] = 0xff00000000000000;
t[2] = 0xff00000000000008;
p5 += t[0]; //p5 already equal h[5]
p6 += t[1];
@@ -270,7 +284,6 @@ void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *
outputHash[threads + thread] = p1;
outputHash[threads*2 + thread] = p2;
outputHash[threads*3 + thread] = p3;
} //thread
}
@@ -284,12 +297,13 @@ __host__
void skein256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
{
const uint32_t threadsperblock = 256;
int dev_id = device_map[thr_id];
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
// only 1kH/s perf change between kernels on a 960...
if (device_sm[device_map[thr_id]] > 300 && cuda_arch[device_map[thr_id]] > 300)
if (device_sm[dev_id] > 300 && cuda_arch[dev_id] > 300)
skein256_gpu_hash_32<<<grid, block>>>(threads, startNounce, d_outputHash);
else
skein256_gpu_hash_32_v30<<<grid, block>>>(threads, startNounce, d_outputHash);
+475
View File
@@ -0,0 +1,475 @@
/**
* Blake-256 Decred 180-Bytes input Cuda Kernel
*
* Tanguy Pruvot, Alexis Provos - Feb/Sep 2016
*/
#include <stdint.h>
#include <memory.h>
#include <miner.h>
extern "C" {
#include <sph/sph_blake.h>
}
/* threads per block */
#define TPB 640
/* max count of found nonces in one call (like sgminer) */
#define MAX_RESULTS 4
/* hash by cpu with blake 256 */
extern "C" void decred_hash(void *output, const void *input)
{
sph_blake256_context ctx;
sph_blake256_set_rounds(14);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, 180);
sph_blake256_close(&ctx, output);
}
#include <cuda_helper.h>
#ifdef __INTELLISENSE__
#define __byte_perm(x, y, b) x
#define atomicInc(p, max) (*p)++
#endif
__constant__ uint32_t _ALIGN(16) c_h[2];
__constant__ uint32_t _ALIGN(16) c_data[32];
__constant__ uint32_t _ALIGN(16) c_xors[215];
/* Buffers of candidate nonce(s) */
static uint32_t *d_resNonce[MAX_GPUS];
static uint32_t *h_resNonce[MAX_GPUS];
#define ROR8(a) __byte_perm(a, 0, 0x0321)
#define ROL16(a) __byte_perm(a, 0, 0x1032)
/* macro bodies */
#define pxorGS(a,b,c,d) { \
v[a]+= c_xors[i++] + v[b]; \
v[d] = ROL16(v[d] ^ v[a]); \
v[c]+= v[d]; \
v[b] = ROTR32(v[b] ^ v[c], 12); \
v[a]+= c_xors[i++] + v[b]; \
v[d] = ROR8(v[d] ^ v[a]); \
v[c]+= v[d]; \
v[b] = ROTR32(v[b] ^ v[c], 7); \
}
#define pxorGS2(a,b,c,d, a1,b1,c1,d1) {\
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
#define pxory1GS2(a,b,c,d, a1,b1,c1,d1) { \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= (c_xors[i++]^nonce) + v[b1]; \
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
#define pxory0GS2(a,b,c,d, a1,b1,c1,d1) { \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[ a]+= (c_xors[i++]^nonce) + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
#define pxorx1GS2(a,b,c,d, a1,b1,c1,d1) { \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= (c_xors[i++]^nonce) + v[b1]; \
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
#define pxorx0GS2(a,b,c,d, a1,b1,c1,d1) { \
v[ a]+= (c_xors[i++]^nonce) + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROL16(v[ d] ^ v[ a]); v[d1] = ROL16(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 12); v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[ a]+= c_xors[i++] + v[ b]; v[a1]+= c_xors[i++] + v[b1]; \
v[ d] = ROR8(v[ d] ^ v[ a]); v[d1] = ROR8(v[d1] ^ v[a1]); \
v[ c]+= v[ d]; v[c1]+= v[d1]; \
v[ b] = ROTR32(v[ b] ^ v[ c], 7); v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
__global__ __launch_bounds__(TPB,1)
void decred_gpu_hash_nonce(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint32_t highTarget)
{
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
uint32_t v[16];
#pragma unroll
for(int i=0; i<16; i+=4) {
*(uint4*)&v[i] = *(uint4*)&c_data[i];
}
const uint32_t nonce = startNonce + thread;
v[ 1]+= (nonce ^ 0x13198A2E);
v[13] = ROR8(v[13] ^ v[1]);
v[ 9]+= v[13];
v[ 5] = ROTR32(v[5] ^ v[9], 7);
int i = 0;
v[ 1]+= c_xors[i++];// + v[ 6];
v[ 0]+= v[5];
v[12] = ROL16(v[12] ^ v[ 1]); v[15] = ROL16(v[15] ^ v[ 0]);
v[11]+= v[12]; v[10]+= v[15];
v[ 6] = ROTR32(v[ 6] ^ v[11], 12); v[ 5] = ROTR32(v[5] ^ v[10], 12);
v[ 1]+= c_xors[i++] + v[ 6]; v[ 0]+= c_xors[i++] + v[ 5];
v[12] = ROR8(v[12] ^ v[ 1]); v[15] = ROR8(v[15] ^ v[ 0]);
v[11]+= v[12]; v[10]+= v[15];
v[ 6] = ROTR32(v[ 6] ^ v[11], 7); v[ 5] = ROTR32(v[ 5] ^ v[10], 7);
pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxory1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorx1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorx1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorx1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxory1GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxory1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorx1GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxory0GS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorx0GS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxory1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxory1GS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorGS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorx1GS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS2( 2, 7, 8, 13, 3, 4, 9, 14);
pxorx1GS2( 0, 4, 8, 12, 1, 5, 9, 13); pxorGS2( 2, 6, 10, 14, 3, 7, 11, 15); pxorGS2( 0, 5, 10, 15, 1, 6, 11, 12); pxorGS( 2, 7, 8, 13);
if ((c_h[1]^v[15]) == v[7]) {
v[ 3] += c_xors[i++] + v[4];
v[14] = ROL16(v[14] ^ v[3]);
v[ 9] += v[14];
v[ 4] = ROTR32(v[4] ^ v[9], 12);
v[ 3] += c_xors[i++] + v[4];
v[14] = ROR8(v[14] ^ v[3]);
if(cuda_swab32((c_h[0]^v[6]^v[14])) <= highTarget) {
uint32_t pos = atomicInc(&resNonce[0], UINT32_MAX)+1;
resNonce[pos] = nonce;
return;
}
}
}
}
__host__
void decred_cpu_setBlock_52(const uint32_t *input)
{
/*
Precompute everything possible and pass it on constant memory
*/
const uint32_t z[16] = {
0x243F6A88U, 0x85A308D3U, 0x13198A2EU, 0x03707344U,
0xA4093822U, 0x299F31D0U, 0x082EFA98U, 0xEC4E6C89U,
0x452821E6U, 0x38D01377U, 0xBE5466CFU, 0x34E90C6CU,
0xC0AC29B7U, 0xC97C50DDU, 0x3F84D5B5U, 0xB5470917U
};
int i=0;
uint32_t _ALIGN(64) preXOR[215];
uint32_t _ALIGN(64) data[16];
uint32_t _ALIGN(64) m[16];
uint32_t _ALIGN(64) h[ 2];
sph_blake256_context ctx;
sph_blake256_set_rounds(14);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, 128);
data[ 0] = ctx.H[0];
data[ 1] = ctx.H[1];
data[ 2] = ctx.H[2];
data[ 3] = ctx.H[3];
data[ 4] = ctx.H[4];
data[ 5] = ctx.H[5];
data[ 8] = ctx.H[6];
data[12] = swab32(input[35]);
data[13] = ctx.H[7];
// pre swab32
m[ 0] = swab32(input[32]); m[ 1] = swab32(input[33]);
m[ 2] = swab32(input[34]); m[ 3] = 0;
m[ 4] = swab32(input[36]); m[ 5] = swab32(input[37]);
m[ 6] = swab32(input[38]); m[ 7] = swab32(input[39]);
m[ 8] = swab32(input[40]); m[ 9] = swab32(input[41]);
m[10] = swab32(input[42]); m[11] = swab32(input[43]);
m[12] = swab32(input[44]); m[13] = 0x80000001;
m[14] = 0;
m[15] = 0x000005a0;
h[ 0] = data[ 8];
h[ 1] = data[13];
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_h,h, 8, 0, cudaMemcpyHostToDevice));
data[ 0]+= (m[ 0] ^ z[1]) + data[ 4];
data[12] = SPH_ROTR32(z[4] ^ SPH_C32(0x5A0) ^ data[ 0], 16);
data[ 8] = z[0]+data[12];
data[ 4] = SPH_ROTR32(data[ 4] ^ data[ 8], 12);
data[ 0]+= (m[ 1] ^ z[0]) + data[ 4];
data[12] = SPH_ROTR32(data[12] ^ data[ 0],8);
data[ 8]+= data[12];
data[ 4] = SPH_ROTR32(data[ 4] ^ data[ 8], 7);
data[ 1]+= (m[ 2] ^ z[3]) + data[ 5];
data[13] = SPH_ROTR32((z[5] ^ SPH_C32(0x5A0)) ^ data[ 1], 16);
data[ 9] = z[1]+data[13];
data[ 5] = SPH_ROTR32(data[ 5] ^ data[ 9], 12);
data[ 1]+= data[ 5]; //+nonce ^ ...
data[ 2]+= (m[ 4] ^ z[5]) + h[ 0];
data[14] = SPH_ROTR32(z[6] ^ data[ 2],16);
data[10] = z[2] + data[14];
data[ 6] = SPH_ROTR32(h[ 0] ^ data[10], 12);
data[ 2]+= (m[ 5] ^ z[4]) + data[ 6];
data[14] = SPH_ROTR32(data[14] ^ data[ 2], 8);
data[10]+= data[14];
data[ 6] = SPH_ROTR32(data[ 6] ^ data[10], 7);
data[ 3]+= (m[ 6] ^ z[7]) + h[ 1];
data[15] = SPH_ROTR32(z[7] ^ data[ 3],16);
data[11] = z[3] + data[15];
data[ 7] = SPH_ROTR32(h[ 1] ^ data[11], 12);
data[ 3]+= (m[ 7] ^ z[6]) + data[ 7];
data[15] = SPH_ROTR32(data[15] ^ data[ 3],8);
data[11]+= data[15];
data[ 7] = SPH_ROTR32(data[11] ^ data[ 7], 7);
data[ 0]+= m[ 8] ^ z[9];
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, data, 64, 0, cudaMemcpyHostToDevice));
#define precalcXORGS(x,y) { \
preXOR[i++]= (m[x] ^ z[y]); \
preXOR[i++]= (m[y] ^ z[x]); \
}
#define precalcXORGS2(x,y,x1,y1){\
preXOR[i++] = (m[ x] ^ z[ y]);\
preXOR[i++] = (m[x1] ^ z[y1]);\
preXOR[i++] = (m[ y] ^ z[ x]);\
preXOR[i++] = (m[y1] ^ z[x1]);\
}
precalcXORGS(10,11);
preXOR[ 0]+=data[ 6];
preXOR[i++] = (m[9] ^ z[8]);
precalcXORGS2(12,13,14,15);
precalcXORGS2(14,10, 4, 8);
precalcXORGS2( 9,15,13, 6);
precalcXORGS2( 1,12, 0, 2);
precalcXORGS2(11, 7, 5, 3);
precalcXORGS2(11, 8,12, 0);
precalcXORGS2( 5, 2,15,13);
precalcXORGS2(10,14, 3, 6);
precalcXORGS2( 7, 1, 9, 4);
precalcXORGS2( 7, 9, 3, 1);
precalcXORGS2(13,12,11,14);
precalcXORGS2( 2, 6, 5,10);
precalcXORGS2( 4, 0,15, 8);
precalcXORGS2( 9, 0, 5, 7);
precalcXORGS2( 2, 4,10,15);
precalcXORGS2(14, 1,11,12);
precalcXORGS2( 6, 8, 3,13);
precalcXORGS2( 2,12, 6,10);
precalcXORGS2( 0,11, 8, 3);
precalcXORGS2( 4,13, 7, 5);
precalcXORGS2(15,14, 1, 9);
precalcXORGS2(12, 5, 1,15);
precalcXORGS2(14,13, 4,10);
precalcXORGS2( 0, 7, 6, 3);
precalcXORGS2( 9, 2, 8,11);
precalcXORGS2(13,11, 7,14);
precalcXORGS2(12, 1, 3, 9);
precalcXORGS2( 5, 0,15, 4);
precalcXORGS2( 8, 6, 2,10);
precalcXORGS2( 6,15,14, 9);
precalcXORGS2(11, 3, 0, 8);
precalcXORGS2(12, 2,13, 7);
precalcXORGS2( 1, 4,10, 5);
precalcXORGS2(10, 2, 8, 4);
precalcXORGS2( 7, 6, 1, 5);
precalcXORGS2(15,11, 9,14);
precalcXORGS2( 3,12,13, 0);
precalcXORGS2( 0, 1, 2, 3);
precalcXORGS2( 4, 5, 6, 7);
precalcXORGS2( 8, 9,10,11);
precalcXORGS2(12,13,14,15);
precalcXORGS2(14,10, 4, 8);
precalcXORGS2( 9,15,13, 6);
precalcXORGS2( 1,12, 0, 2);
precalcXORGS2(11, 7, 5, 3);
precalcXORGS2(11, 8,12, 0);
precalcXORGS2( 5, 2,15,13);
precalcXORGS2(10,14, 3, 6);
precalcXORGS2( 7, 1, 9, 4);
precalcXORGS2( 7, 9, 3, 1);
precalcXORGS2(13,12,11,14);
precalcXORGS2( 2, 6, 5,10);
precalcXORGS( 4, 0);
precalcXORGS(15, 8);
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_xors, preXOR, 215*sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
}
/* ############################################################################################################################### */
static bool init[MAX_GPUS] = { 0 };
// nonce position is different in decred
#define DCR_NONCE_OFT32 35
extern "C" int scanhash_decred(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[48];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
uint32_t *pnonce = &pdata[DCR_NONCE_OFT32];
const uint32_t first_nonce = *pnonce;
const uint32_t targetHigh = opt_benchmark ? 0x1ULL : ptarget[6];
const int dev_id = device_map[thr_id];
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 29 : 25;
if (device_sm[dev_id] < 350) intensity = 22;
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
const dim3 grid((throughput + TPB-1)/(TPB));
const dim3 block(TPB);
if (!init[thr_id]) {
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
cuda_get_arch(thr_id);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], MAX_RESULTS*sizeof(uint32_t)), -1);
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], MAX_RESULTS*sizeof(uint32_t)), -1);
init[thr_id] = true;
}
memcpy(endiandata, pdata, 180);
decred_cpu_setBlock_52(endiandata);
cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
do {
uint32_t* resNonces = h_resNonce[thr_id];
if (resNonces[0]) cudaMemset(d_resNonce[thr_id], 0x00, sizeof(uint32_t));
// GPU HASH
decred_gpu_hash_nonce <<<grid, block>>> (throughput, (*pnonce), d_resNonce[thr_id], targetHigh);
*hashes_done = (*pnonce) - first_nonce + throughput;
// first cell contains the valid nonces count
cudaMemcpy(resNonces, d_resNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
if (resNonces[0])
{
uint32_t _ALIGN(64) vhash[8];
cudaMemcpy(resNonces, d_resNonce[thr_id], (resNonces[0]+1)*sizeof(uint32_t), cudaMemcpyDeviceToHost);
be32enc(&endiandata[DCR_NONCE_OFT32], resNonces[1]);
decred_hash(vhash, endiandata);
if (vhash[6] <= ptarget[6] && fulltest(vhash, ptarget))
{
work->valid_nonces = 1;
work_set_target_ratio(work, vhash);
work->nonces[0] = swab32(resNonces[1]);
*pnonce = work->nonces[0];
// search for another nonce
for(uint32_t n=2; n <= resNonces[0]; n++)
{
be32enc(&endiandata[DCR_NONCE_OFT32], resNonces[n]);
decred_hash(vhash, endiandata);
if (vhash[6] <= ptarget[6] && fulltest(vhash, ptarget)) {
work->nonces[1] = swab32(resNonces[n]);
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio[0]) {
// we really want the best first ? depends...
work->shareratio[1] = work->shareratio[0];
work->sharediff[1] = work->sharediff[0];
xchg(work->nonces[1], work->nonces[0]);
work_set_target_ratio(work, vhash);
work->valid_nonces++;
} else if (work->valid_nonces == 1) {
bn_set_target_ratio(work, vhash, 1);
work->valid_nonces++;
}
work->valid_nonces = 2; // MAX_NONCES submit limited to 2
gpulog(LOG_DEBUG, thr_id, "multiple nonces 1:%08x (%g) %u:%08x (%g)",
work->nonces[0], work->sharediff[0], n, work->nonces[1], work->sharediff[1]);
} else if (vhash[6] > ptarget[6]) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result %u for %08x does not validate on CPU!", n, resNonces[n]);
}
}
return work->valid_nonces;
} else if (vhash[6] > ptarget[6]) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", resNonces[1]);
}
}
*pnonce += throughput;
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + (*pnonce));
*hashes_done = (*pnonce) - first_nonce;
MyStreamSynchronize(NULL, 0, device_map[thr_id]);
return 0;
}
// cleanup
extern "C" void free_decred(int thr_id)
{
if (!init[thr_id])
return;
cudaDeviceSynchronize();
cudaFreeHost(h_resNonce[thr_id]);
cudaFree(d_resNonce[thr_id]);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+110 -29
View File
@@ -14,11 +14,18 @@ extern "C"
#include "cuda_helper.h"
static uint32_t *d_hash[MAX_GPUS];
// SM5+ cuda
extern void keccak256_cpu_init(int thr_id);
extern void keccak256_cpu_free(int thr_id);
extern void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, const uint2 highTarget);
extern void keccak256_setBlock_80(uint64_t *endiandata);
extern void keccak256_setOutput(int thr_id);
extern void keccak256_cpu_init(int thr_id, uint32_t threads);
extern void keccak256_setBlock_80(void *pdata,const void *ptarget);
extern uint32_t keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
// compat
extern void keccak256_sm3_init(int thr_id, uint32_t threads);
extern void keccak256_sm3_free(int thr_id);
extern void keccak256_sm3_setBlock_80(void *pdata, const void *ptarget);
extern void keccak256_sm3_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t* resNonces, int order);
// CPU Hash
extern "C" void keccak256_hash(void *state, const void *input)
@@ -34,55 +41,110 @@ extern "C" void keccak256_hash(void *state, const void *input)
}
static bool init[MAX_GPUS] = { 0 };
static bool use_compat_kernels[MAX_GPUS] = { 0 };
extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce,
unsigned long *hashes_done)
extern "C" int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 21); // 256*256*8*4
throughput = min(throughput, max_nonce - first_nonce);
const int dev_id = device_map[thr_id];
uint32_t throughput;
uint32_t intensity = 23;
if(!use_compat_kernels[thr_id]) {
if (strstr(device_name[dev_id], "GTX 1070")) intensity = 25;
if (strstr(device_name[dev_id], "GTX 1080")) intensity = 26;
}
throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x0005;
ptarget[7] = 0x000f;
if (!init[thr_id]) {
cudaSetDevice(device_map[thr_id]);
if (!init[thr_id])
{
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
CUDA_LOG_ERROR();
}
cuda_get_arch(thr_id);
use_compat_kernels[thr_id] = (cuda_arch[dev_id] < 500);
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 64));
keccak256_cpu_init(thr_id, throughput);
if(!use_compat_kernels[thr_id]) {
keccak256_cpu_init(thr_id);
} else {
// really useful ?
keccak256_sm3_init(thr_id, throughput);
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
init[thr_id] = true;
}
uint32_t endiandata[20];
for (int k=0; k < 20; k++) {
for (int k=0; k < 19; k++) {
be32enc(&endiandata[k], pdata[k]);
}
keccak256_setBlock_80((void*)endiandata, ptarget);
const uint2 highTarget = make_uint2(ptarget[6], ptarget[7]);
if(use_compat_kernels[thr_id])
keccak256_sm3_setBlock_80((void*)endiandata, ptarget);
else {
keccak256_setBlock_80((uint64_t*)endiandata);
keccak256_setOutput(thr_id);
}
do {
int order = 0;
*hashes_done = pdata[19] - first_nonce + throughput;
uint32_t foundNonce = keccak256_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
if (foundNonce != UINT32_MAX)
{
uint32_t _ALIGN(64) vhash64[8];
be32enc(&endiandata[19], foundNonce);
keccak256_hash(vhash64, endiandata);
if(use_compat_kernels[thr_id])
keccak256_sm3_hash_80(thr_id, throughput, pdata[19], work->nonces, order++);
else {
keccak256_cpu_hash_80(thr_id, throughput, pdata[19], work->nonces, highTarget);
}
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
pdata[19] = foundNonce;
return 1;
if (work->nonces[0] != UINT32_MAX && bench_algo < 0)
{
const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(64) vhash[8];
be32enc(&endiandata[19], work->nonces[0]);
keccak256_hash(vhash, endiandata);
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
work->valid_nonces = 1;
work_set_target_ratio(work, vhash);
if (!use_compat_kernels[thr_id] && work->nonces[1] != UINT32_MAX) {
be32enc(&endiandata[19], work->nonces[1]);
keccak256_hash(vhash, endiandata);
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
work->valid_nonces++;
bn_set_target_ratio(work, vhash, 1);
}
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
} else {
pdata[19] = work->nonces[0] + 1;
}
return work->valid_nonces;
}
else {
applog(LOG_WARNING, "GPU #%d: result for nounce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
pdata[19] = work->nonces[0] + 1;
//keccak256_setOutput(thr_id);
continue;
}
}
if ((uint64_t) pdata[19] + throughput > max_nonce) {
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
@@ -90,5 +152,24 @@ extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
return 0;
}
// cleanup
extern "C" void free_keccak256(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
if(!use_compat_kernels[thr_id])
keccak256_cpu_free(thr_id);
else {
keccak256_sm3_free(thr_id);
}
cudaDeviceSynchronize();
init[thr_id] = false;
}
+492
View File
@@ -0,0 +1,492 @@
/**
* Optimized Blake-256 8-rounds Cuda Kernel (Tested on SM >3.0)
* Based upon Blake-256 implementation of Tanguy Pruvot - Nov. 2014
*
* Provos Alexis - Jan. 2016
*
* Fixed CUDA 7.5 flaw
* minor code changes
* code cleanup
* increased nonces per thread
* removed SSE2 midstate computation
* Provos Alexis - Mar 2016
*/
#include <stdint.h>
#include <memory.h>
#include "miner.h"
extern "C" {
#include "sph/sph_blake.h"
}
#include "cuda_helper.h"
#ifdef __INTELLISENSE__
#define __byte_perm(x, y, b) x
#endif
/* threads per block and nonces per thread */
#define TPB 768
#define NPT 384
#define NBN 2
__constant__ uint32_t _ALIGN(16) d_data[21];
/* 16 gpu threads max */
static uint32_t *d_resNonce[MAX_GPUS];
static uint32_t *h_resNonce[MAX_GPUS];
static cudaStream_t streams[MAX_GPUS];
/* hash by cpu with blake 256 */
extern "C" void vanillahash(void *output, const void *input, int8_t blakerounds){
uchar hash[64];
sph_blake256_context ctx;
sph_blake256_set_rounds(blakerounds);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, 80);
sph_blake256_close(&ctx, hash);
memcpy(output, hash, 32);
}
#define GS4(a,b,c,d,x,y,a1,b1,c1,d1,x1,y1,a2,b2,c2,d2,x2,y2,a3,b3,c3,d3,x3,y3) { \
v[ a]+= (m[ x] ^ z[ y]) + v[ b]; \
v[a1]+= (m[x1] ^ z[y1]) + v[b1]; \
v[a2]+= (m[x2] ^ z[y2]) + v[b2]; \
v[a3]+= (m[x3] ^ z[y3]) + v[b3]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x1032); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x1032); \
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x1032); \
v[d3] = __byte_perm(v[d3] ^ v[a3], 0, 0x1032); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
v[c2]+= v[d2]; \
v[c3]+= v[d3]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 12); \
v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[b2] = ROTR32(v[b2] ^ v[c2], 12); \
v[b3] = ROTR32(v[b3] ^ v[c3], 12); \
\
v[ a]+= (m[ y] ^ z[ x]) + v[ b]; \
v[a1]+= (m[y1] ^ z[x1]) + v[b1]; \
v[a2]+= (m[y2] ^ z[x2]) + v[b2]; \
v[a3]+= (m[y3] ^ z[x3]) + v[b3]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x0321); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x0321); \
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x0321); \
v[d3] = __byte_perm(v[d3] ^ v[a3], 0, 0x0321); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
v[c2]+= v[d2]; \
v[c3]+= v[d3]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 7); \
v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
v[b2] = ROTR32(v[b2] ^ v[c2], 7); \
v[b3] = ROTR32(v[b3] ^ v[c3], 7); \
}
#define GS3(a,b,c,d,x,y,a1,b1,c1,d1,x1,y1,a2,b2,c2,d2,x2,y2) { \
v[ a]+= (m[ x] ^ z[ y]) + v[ b]; \
v[a1]+= (m[x1] ^ z[y1]) + v[b1]; \
v[a2]+= (m[x2] ^ z[y2]) + v[b2]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x1032); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x1032); \
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x1032); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
v[c2]+= v[d2]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 12); \
v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
v[b2] = ROTR32(v[b2] ^ v[c2], 12); \
\
v[ a]+= (m[ y] ^ z[ x]) + v[ b]; \
v[a1]+= (m[y1] ^ z[x1]) + v[b1]; \
v[a2]+= (m[y2] ^ z[x2]) + v[b2]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x0321); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x0321); \
v[d2] = __byte_perm(v[d2] ^ v[a2], 0, 0x0321); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
v[c2]+= v[d2]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 7); \
v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
v[b2] = ROTR32(v[b2] ^ v[c2], 7); \
}
#define GS2(a,b,c,d,x,y,a1,b1,c1,d1,x1,y1) { \
v[ a]+= (m[ x] ^ z[ y]) + v[ b]; \
v[a1]+= (m[x1] ^ z[y1]) + v[b1]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x1032); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x1032); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 12); \
v[b1] = ROTR32(v[b1] ^ v[c1], 12); \
\
v[ a]+= (m[ y] ^ z[ x]) + v[ b]; \
v[a1]+= (m[y1] ^ z[x1]) + v[b1]; \
\
v[ d] = __byte_perm(v[ d] ^ v[ a], 0, 0x0321); \
v[d1] = __byte_perm(v[d1] ^ v[a1], 0, 0x0321); \
\
v[ c]+= v[ d]; \
v[c1]+= v[d1]; \
\
v[ b] = ROTR32(v[ b] ^ v[ c], 7); \
v[b1] = ROTR32(v[b1] ^ v[c1], 7); \
}
#define GS(a,b,c,d,x,y) { \
v[a] += (m[x] ^ z[y]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x1032); \
v[c] += v[d]; \
v[b] = ROTR32(v[b] ^ v[c], 12); \
v[a] += (m[y] ^ z[x]) + v[b]; \
v[d] = __byte_perm(v[d] ^ v[a],0, 0x0321); \
v[c] += v[d]; \
v[b] = ROTR32(v[b] ^ v[c], 7); \
}
__global__ __launch_bounds__(TPB,1)
void vanilla_gpu_hash_16_8(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce,const uint64_t highTarget){
uint32_t _ALIGN(16) v[16];
uint32_t _ALIGN(16) tmp[16];
const size_t thread = blockDim.x * blockIdx.x + threadIdx.x;
const uint64_t step = gridDim.x * blockDim.x;
const uint64_t maxNonce = startNonce + threads;
const int8_t r[][16] = {
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }
};
const uint32_t z[16] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
};
//PREFETCH
#pragma unroll
for(int i=0;i<16;i++){
tmp[ i] = d_data[ i];
}
uint32_t m[16] = {
d_data[16], d_data[17], d_data[18], 0,
0x80000000UL, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 640
};
const uint32_t h7 = d_data[19];
const uint32_t h6 = d_data[20];
//END OF PREFETCH
uint64_t m3 = startNonce + thread;
loopstart:
if(m3>=maxNonce)return;
m[3] = m3;
#pragma unroll
for(int i=0;i<16;i++)
v[ i] = tmp[ i];
v[ 1]+= m[3] ^ z[2];
v[13] = __byte_perm(v[13] ^ v[1],0, 0x0321);
v[ 9]+= v[13];
v[ 5] = ROTR32(v[5] ^ v[9], 7);
v[ 0]+= v[5];
v[15] = __byte_perm(v[15] ^ v[0],0, 0x1032);
v[10]+= v[15];
v[ 5] = ROTR32(v[5] ^ v[10], 12);
v[ 0]+= z[8] + v[5];
v[15] = __byte_perm(v[15] ^ v[0],0, 0x0321);
v[10]+= v[15];
v[ 5] = ROTR32(v[5] ^ v[10], 7);
GS3( 1, 6,11,12,10,11, 2, 7, 8,13,12,13, 3, 4, 9,14,14,15);
#pragma unroll
for(int i=0;i<6;i++){
GS4(0, 4, 8,12,r[i][ 0],r[i][ 1], 1, 5, 9,13,r[i][ 2],r[i][ 3], 2, 6,10,14,r[i][ 4],r[i][ 5], 3, 7,11,15,r[i][ 6],r[i][ 7]);
GS4(0, 5,10,15,r[i][ 8],r[i][ 9], 1, 6,11,12,r[i][10],r[i][11], 2, 7, 8,13,r[i][12],r[i][13], 3, 4, 9,14,r[i][14],r[i][15]);
}
GS4(0, 4, 8,12,r[6][ 0],r[6][ 1], 1, 5, 9,13,r[6][ 2],r[6][ 3], 2, 6,10,14,r[6][ 4],r[6][ 5], 3, 7,11,15,r[6][ 6],r[6][ 7]);
v[ 0] += (m[ 5] ^ z[0]) + v[5];
v[ 2] += (m[ 8] ^ z[6]) + v[7];
v[13] = __byte_perm(v[13] ^ v[2],0, 0x1032);
v[15] = __byte_perm(v[15] ^ v[0],0, 0x1032);
v[ 8] += v[13];
v[10] += v[15];
v[ 5] = ROTR32(v[ 5] ^ v[10], 12);
v[ 7] = ROTR32(v[ 7] ^ v[ 8], 12);
v[ 0] += (m[ 0] ^ z[5]) + v[5];
v[ 2] += (m[ 6] ^ z[8]) + v[7];
v[15] = __byte_perm(v[15] ^ v[ 0],0, 0x0321);
v[13] = __byte_perm(v[13] ^ v[ 2],0, 0x0321);
v[8] += v[13];
v[7] = ROTR32(v[7] ^ v[8], 7);
// only compute h6 & 7
if((v[15]^h7)==v[7]){
v[ 1] += (m[15] ^ z[ 4]) + v[6];
v[ 3] += (m[2] ^ z[10]) + v[4];
v[12] = __byte_perm(v[12] ^ v[ 1],0, 0x1032);
v[14] = __byte_perm(v[14] ^ v[3],0, 0x1032);
v[11] += v[12];
v[ 9] += v[14];
v[ 6] = ROTR32(v[ 6] ^ v[11], 12);
v[ 1] += (m[ 4] ^ z[15]) + v[ 6];
v[ 3] += (m[10] ^ z[ 2]) + ROTR32(v[ 4] ^ v[ 9],12);
v[12] = __byte_perm(v[12] ^ v[ 1],0, 0x0321);
v[14] = __byte_perm(v[14] ^ v[ 3],0, 0x0321);
v[11] += v[12];
v[ 6] = ROTR32(v[ 6] ^ v[11], 7);
if(cuda_swab32(h6^v[6]^v[14]) <= highTarget) {
#if NBN == 2
/* keep the smallest nonce, + extra one if found */
if (m[3] < resNonce[0]){
resNonce[1] = resNonce[0];
resNonce[0] = m[3];
}
else
resNonce[1] = m[3];
#else
resNonce[0] = m[3];
#endif
return; //<-- this may cause a problem on extranonce if the extranonce is on position current_nonce + X * step where X=[1,2,3..,N]
}
}
m3+=step;
goto loopstart;
}
__host__
void vanilla_cpu_setBlock_16(const int thr_id,const uint32_t* endiandata, uint32_t *penddata){
const uint32_t _ALIGN(64) z[16] = {
SPH_C32(0x243F6A88), SPH_C32(0x85A308D3), SPH_C32(0x13198A2E), SPH_C32(0x03707344),
SPH_C32(0xA4093822), SPH_C32(0x299F31D0), SPH_C32(0x082EFA98), SPH_C32(0xEC4E6C89),
SPH_C32(0x452821E6), SPH_C32(0x38D01377), SPH_C32(0xBE5466CF), SPH_C32(0x34E90C6C),
SPH_C32(0xC0AC29B7), SPH_C32(0xC97C50DD), SPH_C32(0x3F84D5B5), SPH_C32(0xB5470917)
};
uint32_t _ALIGN(64) h[22];
sph_blake256_context ctx;
sph_blake256_set_rounds(8);
sph_blake256_init(&ctx);
sph_blake256(&ctx, endiandata, 64);
h[ 0] = ctx.H[0]; h[ 1] = ctx.H[1];
h[ 2] = ctx.H[2]; h[21] = ctx.H[3];
h[ 4] = ctx.H[4]; h[20] = ctx.H[5];
h[19] = ctx.H[6]; h[16] = ctx.H[7];
uint32_t tmp = h[20];
h[20] = h[19];
h[19] = h[16];
h[16] = penddata[ 0];
h[17] = penddata[ 1];
h[18] = penddata[ 2];
h[12] = z[ 4] ^ 640;
h[ 8] = z[ 0];
h[ 0] += (h[16] ^ z[ 1]) + h[ 4];
h[12] = SPH_ROTR32(h[12] ^ h[0],16);
h[ 8] += h[12];
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8], 12);
h[ 0] += (h[17] ^ z[ 0]) + h[ 4];
h[12] = SPH_ROTR32(h[12] ^ h[0],8);
h[ 8] += h[12];
h[ 4] = SPH_ROTR32(h[ 4] ^ h[ 8], 7);
h[1] += (h[18] ^ z[ 3]) + tmp;
h[13] = SPH_ROTR32(z[ 5] ^ 640 ^ h[1],16);
h[ 5] = ROTR32(tmp ^ (z[ 1] + h[13]), 12);
h[ 1] += h[ 5];
h[ 2] += (0x80000000UL ^ z[ 5]) + h[20];
h[14] = SPH_ROTR32(z[ 6] ^ h[2], 16);
h[ 6] = z[ 2] + h[14];
h[ 6] = SPH_ROTR32(h[20] ^ h[ 6], 12);
h[21] += z[ 7] + h[19];
h[ 0] += z[ 9];
h[ 2] += z[ 4] + h[ 6];
h[ 9] = z[ 1] + h[13];
h[10] = z[ 2] + h[14];
h[14] = SPH_ROTR32(h[14] ^ h[2],8); //0x0321
h[10]+=h[14];
h[ 6] = SPH_ROTR32(h[ 6] ^ h[10],7);
h[15] = SPH_ROTR32(z[ 7] ^ h[21],16);
h[11] = z[ 3] + h[15];
h[ 7] = SPH_ROTR32(h[19] ^ h[11], 12);
h[ 3] = h[21] + h[ 7] + z[ 6];
h[15] = SPH_ROTR32(h[15] ^ h[ 3],8);
h[11]+= h[15];
h[ 7] = ROTR32(h[ 7] ^ h[11],7);
cudaMemcpyToSymbolAsync(d_data, h, 21*sizeof(uint32_t), 0, cudaMemcpyHostToDevice, streams[thr_id]);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, const int8_t blakerounds)
{
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
const uint32_t targetHigh = ptarget[6];
int dev_id = device_map[thr_id];
int intensity = (device_sm[dev_id] > 500 && !is_windows()) ? 30 : 24;
if (device_sm[dev_id] < 350) intensity = 22;
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (!init[thr_id]) {
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
cuda_get_arch(thr_id);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), -1);
cudaStreamCreate(&streams[thr_id]);
init[thr_id] = true;
}
uint32_t _ALIGN(64) endiandata[20];
for (int k = 0; k < 16; k++)
be32enc(&endiandata[k], pdata[k]);
cudaMemsetAsync(d_resNonce[thr_id], 0xff, sizeof(uint32_t),streams[thr_id]);
vanilla_cpu_setBlock_16(thr_id,endiandata,&pdata[16]);
const dim3 grid((throughput + (NPT*TPB)-1)/(NPT*TPB));
const dim3 block(TPB);
int rc = 0;
do {
vanilla_gpu_hash_16_8<<<grid,block, 0, streams[thr_id]>>>(throughput, pdata[19], d_resNonce[thr_id], targetHigh);
cudaMemcpyAsync(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost,streams[thr_id]);
*hashes_done = pdata[19] - first_nonce + throughput;
cudaStreamSynchronize(streams[thr_id]);
if (h_resNonce[thr_id][0] != UINT32_MAX){
uint32_t vhashcpu[8];
uint32_t Htarg = (uint32_t)targetHigh;
for (int k=0; k < 19; k++)
be32enc(&endiandata[k], pdata[k]);
be32enc(&endiandata[19], h_resNonce[thr_id][0]);
vanillahash(vhashcpu, endiandata, blakerounds);
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) {
work->valid_nonces = 1;
work->nonces[0] = h_resNonce[thr_id][0];
work_set_target_ratio(work, vhashcpu);
#if NBN > 1
if (h_resNonce[thr_id][1] != UINT32_MAX) {
work->nonces[1] = h_resNonce[thr_id][1];
be32enc(&endiandata[19], h_resNonce[thr_id][1]);
vanillahash(vhashcpu, endiandata, blakerounds);
if (bn_hash_target_ratio(vhashcpu, ptarget) > work->shareratio[0]) {
work_set_target_ratio(work, vhashcpu);
xchg(work->nonces[0], work->nonces[1]);
}
work->valid_nonces = 2;
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
} else {
pdata[19] = work->nonces[0] + 1; // cursor
}
#endif
return work->valid_nonces;
}
else if (vhashcpu[6] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]);
pdata[19] = work->nonces[0] + 1;
continue;
}
}
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
MyStreamSynchronize(NULL, 0, dev_id);
return rc;
}
// cleanup
extern "C" void free_vanilla(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
cudaFreeHost(h_resNonce[thr_id]);
cudaFree(d_resNonce[thr_id]);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+97 -42
View File
@@ -1,42 +1,97 @@
You can use ./build.sh to configure and build with default options.
It is advised to run ./autogen.sh before ./configure (autoconf and automake
need to be installed on your system for autogen.sh to work)
./configure has an option named --with-cuda that allows you to specify
where your CUDA 6.5 toolkit is installed (usually /usr/local/cuda,
but some distros may have a different default location)
** How to compile on Fedora 22 (2015) **
# Step 1: gcc and dependencies
dnf install gcc gcc-c++ automake
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel pciutils-devel
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
dnf install kernel-devel
modprobe -r nouveau
./NVIDIA-Linux-x86_64-346.72.run
# Step 3: CUDA SDK (Download from nvidia archive)
dnf install cuda-repo-fedora20-6-5-prod-6.5-19.x86_64.rpm
dnf install cuda-minimal-build-6-5.x86_64
# add the nvcc binary path to the system
ln -s /usr/local/cuda-6.5 /usr/local/cuda
echo 'export PATH=$PATH:/usr/local/cuda/bin' > /etc/profile.d/cuda.sh
# add the cudart library path to the system
echo /usr/local/cuda/lib64 > /etc/ld.so.conf.d/cuda.conf
ldconfig
# Step 4: Fix the toolkit warning with gcc 5.1
edit the file /usr/local/cuda/include/host_config.h
and comment/delete the line 82 : #error -- unsupported GNU version! gcc 4.9
./build.sh
./ccminer -n
You can use ./build.sh to configure and build with default options.
It is advised to run ./autogen.sh before ./configure (autoconf and automake
need to be installed on your system for autogen.sh to work)
./configure has an option named --with-cuda that allows you to specify
where your CUDA 6.5 toolkit is installed (usually /usr/local/cuda,
but some distros may have a different default location)
** How to compile on Ubuntu (16.04 LTS)
First, install Cuda toolkit and nVidia Driver, and type `nvidia-smi` to check if your card is detected.
Install dependencies
```sudo apt-get install libcurl4-openssl-dev libssl-dev libjansson-dev automake autotools-dev build-essential```
Ubuntu is now shipped with gcc 6 or 7 so please install gcc/g++ 5 and make it the default (required by the cuda toolkit)
```
sudo apt-get install gcc-5 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1
```
Then use the helper ./build.sh in ccminer source folder, edit configure.sh and the Makefile.am if required.
```
./build.sh
./ccminer --version
```
** How to compile on Fedora 25 **
Note: You may find an alternative method via rpms :
see https://negativo17.org/nvidia-driver/ and https://negativo17.org/repos/multimedia/
# Step 1: gcc and dependencies
dnf install gcc gcc-c++ autoconf automake
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
dnf install kernel-devel
dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
dnf check-update
dnf install xorg-x11-drv-nvidia-cuda kmod-nvidia
ln -s libnvidia-ml.so.1 /usr/lib64/libnvidia-ml.so
# Step 3: CUDA SDK (Download from nvidia the generic ".run" archive)
# --override is required to ignore "too recent" gcc 6.3
# --silent is required to install only the toolkit (no kmod)
./cuda_8.0.61_375.26_linux.run --toolkit --silent --override
nvcc --version
# add the nvcc binary path to the system
ln -s /usr/local/cuda-8.0 /usr/local/cuda # (if not already made)
echo 'export PATH=$PATH:/usr/local/cuda/bin' > /etc/profile.d/cuda.sh
# add the cudart library path to the system
echo /usr/local/cuda/lib64 > /etc/ld.so.conf.d/cuda.conf
ldconfig
# Step 4: Fix the toolkit incompatibility with gcc 6
# You need to build yourself an older GCC/G++ version, i recommend the 5.4
# see https://gcc.gnu.org/mirrors.html
# Note: this manual method will override the default gcc, it could be better to use a custom toolchain prefix
wget ftp://ftp.lip6.fr/pub/gcc/releases/gcc-5.4.0/gcc-5.4.0.tar.bz2
dnf install libmpc-devel mpfr-devel gmp-devel
./configure --prefix=/usr/local --enable-languages=c,c++,lto --disable-multilib
make -j 8 && make install
(while this step, you have the time to cook something :p)
# or, for previous fedora versions, edit the file /usr/local/cuda/include/host_config.h
# and comment/delete the line 121 : #error -- unsupported GNU version! gcc versions later than 5 are not supported!
./build.sh
./ccminer -n
** How to compile on macOS **
# Step 1: download and install CUDA Toolkit 8 or more recent
# https://developer.nvidia.com/cuda-toolkit-archive
# Step 2: install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Step 3: dependencies
brew install pkg-config autoconf automake curl openssl llvm
./build.sh
./ccminer -n
+15 -2
View File
@@ -33,8 +33,9 @@ __device__ cuda_compactTestFunction_t d_JackpotTrueFunction = JackpotTrueTest, d
cuda_compactTestFunction_t h_JackpotTrueFunction[MAX_GPUS], h_JackpotFalseFunction[MAX_GPUS];
// Setup-Funktionen
__host__ void jackpot_compactTest_cpu_init(int thr_id, uint32_t threads)
// Setup-Function
__host__
void jackpot_compactTest_cpu_init(int thr_id, uint32_t threads)
{
cudaMemcpyFromSymbol(&h_JackpotTrueFunction[thr_id], d_JackpotTrueFunction, sizeof(cuda_compactTestFunction_t));
cudaMemcpyFromSymbol(&h_JackpotFalseFunction[thr_id], d_JackpotFalseFunction, sizeof(cuda_compactTestFunction_t));
@@ -51,6 +52,18 @@ __host__ void jackpot_compactTest_cpu_init(int thr_id, uint32_t threads)
cudaMalloc(&d_partSum[1][thr_id], sizeof(uint32_t) * s1); // BLOCKSIZE (Threads/Block)
}
__host__
void jackpot_compactTest_cpu_free(int thr_id)
{
cudaFree(d_tempBranch1Nonces[thr_id]);
cudaFree(d_numValid[thr_id]);
cudaFree(d_partSum[0][thr_id]);
cudaFree(d_partSum[1][thr_id]);
cudaFreeHost(h_numValid[thr_id]);
}
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 300
/**
* __shfl_up() calculates a source lane ID by subtracting delta from the caller's lane ID, and clamping to the range 0..width-1
+139 -91
View File
@@ -9,101 +9,103 @@ extern "C"
#include "miner.h"
#include "cuda_helper.h"
#include "quark/cuda_quark.h"
static uint32_t *d_hash[MAX_GPUS];
static uint32_t *d_hash[MAX_GPUS] = { 0 };
// Speicher zur Generierung der Noncevektoren für die bedingten Hashes
static uint32_t *d_jackpotNonces[MAX_GPUS] = { 0 };
static uint32_t *d_branch1Nonces[MAX_GPUS] = { 0 };
static uint32_t *d_branch2Nonces[MAX_GPUS] = { 0 };
static uint32_t *d_branch3Nonces[MAX_GPUS] = { 0 };
extern void jackpot_keccak512_cpu_init(int thr_id, uint32_t threads);
extern void jackpot_keccak512_cpu_setBlock(void *pdata, size_t inlen);
extern void jackpot_keccak512_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
extern void quark_blake512_cpu_init(int thr_id, uint32_t threads);
extern void quark_blake512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void jackpot_compactTest_cpu_init(int thr_id, uint32_t threads);
extern void jackpot_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes, uint32_t *d_validNonceTable,
uint32_t *d_nonces1, uint32_t *nrm1,
uint32_t *d_nonces2, uint32_t *nrm2,
int order);
extern void jackpot_compactTest_cpu_free(int thr_id);
extern void jackpot_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes, uint32_t *d_validNonceTable,
uint32_t *d_nonces1, uint32_t *nrm1, uint32_t *d_nonces2, uint32_t *nrm2, int order);
extern uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash, int order);
// Speicher zur Generierung der Noncevektoren für die bedingten Hashes
static uint32_t *d_jackpotNonces[MAX_GPUS];
static uint32_t *d_branch1Nonces[MAX_GPUS];
static uint32_t *d_branch2Nonces[MAX_GPUS];
static uint32_t *d_branch3Nonces[MAX_GPUS];
// Original jackpothash Funktion aus einem miner Quelltext
extern "C" unsigned int jackpothash(void *state, const void *input)
// CPU HASH JHA v8
extern "C" void jackpothash(void *state, const void *input)
{
sph_blake512_context ctx_blake;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
uint32_t hash[16];
unsigned int rnd;
uint32_t hash[16];
sph_blake512_context ctx_blake;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, input, 80);
sph_keccak512_close(&ctx_keccak, hash);
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, input, 80);
sph_keccak512_close(&ctx_keccak, hash);
unsigned int round;
for (round = 0; round < 3; round++) {
if (hash[0] & 0x01) {
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, (&hash), 64);
sph_groestl512_close(&ctx_groestl, (&hash));
}
else {
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, (&hash), 64);
sph_skein512_close(&ctx_skein, (&hash));
}
if (hash[0] & 0x01) {
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, (&hash), 64);
sph_blake512_close(&ctx_blake, (&hash));
}
else {
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, (&hash), 64);
sph_jh512_close(&ctx_jh, (&hash));
}
}
memcpy(state, hash, 32);
for (rnd = 0; rnd < 3; rnd++)
{
if (hash[0] & 0x01) {
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, (&hash), 64);
sph_groestl512_close(&ctx_groestl, (&hash));
}
else {
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, (&hash), 64);
sph_skein512_close(&ctx_skein, (&hash));
}
return round;
if (hash[0] & 0x01) {
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, (&hash), 64);
sph_blake512_close(&ctx_blake, (&hash));
}
else {
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, (&hash), 64);
sph_jh512_close(&ctx_jh, (&hash));
}
}
memcpy(state, hash, 32);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce,
unsigned long *hashes_done)
extern "C" int scanhash_jackpot(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[22];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
int dev_id = device_map[thr_id];
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 20);
throughput = min(throughput, max_nonce - first_nonce);
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 20);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x000f;
ptarget[7] = 0x000f;
if (!init[thr_id])
{
cudaSetDevice(device_map[thr_id]);
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
CUDA_LOG_ERROR();
}
cuda_get_arch(thr_id);
if (device_sm[dev_id] < 300 || cuda_arch[dev_id] < 300) {
gpulog(LOG_ERR, thr_id, "Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
proper_exit(EXIT_CODE_CUDA_ERROR);
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 16 * sizeof(uint32_t) * throughput));
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput));
jackpot_keccak512_cpu_init(thr_id, throughput);
jackpot_compactTest_cpu_init(thr_id, throughput);
@@ -114,16 +116,15 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
cuda_check_cpu_init(thr_id, throughput);
cudaMalloc(&d_branch1Nonces[thr_id], sizeof(uint32_t)*throughput*2);
cudaMalloc(&d_branch2Nonces[thr_id], sizeof(uint32_t)*throughput*2);
cudaMalloc(&d_branch3Nonces[thr_id], sizeof(uint32_t)*throughput*2);
cudaMalloc(&d_branch1Nonces[thr_id], (size_t) sizeof(uint32_t)*throughput*2);
cudaMalloc(&d_branch2Nonces[thr_id], (size_t) sizeof(uint32_t)*throughput*2);
cudaMalloc(&d_branch3Nonces[thr_id], (size_t) sizeof(uint32_t)*throughput*2);
CUDA_SAFE_CALL(cudaMalloc(&d_jackpotNonces[thr_id], sizeof(uint32_t)*throughput*2));
CUDA_SAFE_CALL(cudaMalloc(&d_jackpotNonces[thr_id], (size_t) sizeof(uint32_t)*throughput*2));
init[thr_id] = true;
}
uint32_t endiandata[22];
for (int k=0; k < 22; k++)
be32enc(&endiandata[k], pdata[k]);
@@ -209,32 +210,48 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
*hashes_done = pdata[19] - first_nonce + throughput;
uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
if (foundNonce != 0xffffffff)
CUDA_LOG_ERROR();
work->nonces[0] = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
if (work->nonces[0] != UINT32_MAX)
{
uint32_t vhash64[8];
be32enc(&endiandata[19], foundNonce);
const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(64) vhash[8];
be32enc(&endiandata[19], work->nonces[0]);
// diese jackpothash Funktion gibt die Zahl der Runden zurück
jackpothash(vhash64, endiandata);
// jackpothash function gibt die Zahl der Runden zurück
jackpothash(vhash, endiandata);
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
int res = 1;
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
if (secNonce != 0) {
pdata[21] = secNonce;
res++;
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
work->valid_nonces = 1;
work_set_target_ratio(work, vhash);
#if 0
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
if (work->nonces[1] != 0) {
be32enc(&endiandata[19], work->nonces[1]);
jackpothash(vhash, endiandata);
bn_set_target_ratio(work, vhash, 1);
work->valid_nonces++;
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
} else {
pdata[19] = work->nonces[0] + 1; // cursor
}
pdata[19] = foundNonce;
return res;
} else {
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!",
device_map[thr_id], foundNonce);
#else
pdata[19] = work->nonces[0] + 1; // cursor
#endif
return work->valid_nonces;
}
else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
pdata[19] = work->nonces[0] + 1;
continue;
}
}
if ((uint64_t) pdata[19] + throughput > max_nonce) {
*hashes_done = pdata[19] - first_nonce;
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
@@ -243,5 +260,36 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
CUDA_LOG_ERROR();
return 0;
}
// cleanup
extern "C" void free_jackpot(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
cudaFree(d_branch1Nonces[thr_id]);
cudaFree(d_branch2Nonces[thr_id]);
cudaFree(d_branch3Nonces[thr_id]);
cudaFree(d_jackpotNonces[thr_id]);
quark_blake512_cpu_free(thr_id);
quark_groestl512_cpu_free(thr_id);
jackpot_compactTest_cpu_free(thr_id);
cudaFree(d_hash[thr_id]);
cuda_check_cpu_free(thr_id);
CUDA_LOG_ERROR();
cudaDeviceSynchronize();
init[thr_id] = false;
}
+265
View File
@@ -0,0 +1,265 @@
/**
* JHA v8 algorithm - compatible implementation
* @author tpruvot@github 05-2017
*/
extern "C" {
#include "sph/sph_keccak.h"
#include "sph/sph_blake.h"
#include "sph/sph_groestl.h"
#include "sph/sph_jh.h"
#include "sph/sph_skein.h"
}
#include "miner.h"
#include "cuda_helper.h"
#include "quark/cuda_quark.h"
static uint32_t *d_hash[MAX_GPUS] = { 0 };
static uint32_t *d_hash_br2[MAX_GPUS];
static uint32_t *d_tempBranch[MAX_GPUS];
extern void jackpot_keccak512_cpu_init(int thr_id, uint32_t threads);
extern void jackpot_keccak512_cpu_setBlock(void *pdata, size_t inlen);
extern void jackpot_keccak512_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
// CPU HASH
extern "C" void jha_hash(void *output, const void *input)
{
uint32_t hash[16];
sph_blake512_context ctx_blake;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, input, 80);
sph_keccak512_close(&ctx_keccak, hash);
for (int rnd = 0; rnd < 3; rnd++)
{
if (hash[0] & 0x01) {
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, (&hash), 64);
sph_groestl512_close(&ctx_groestl, (&hash));
}
else {
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, (&hash), 64);
sph_skein512_close(&ctx_skein, (&hash));
}
if (hash[0] & 0x01) {
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, (&hash), 64);
sph_blake512_close(&ctx_blake, (&hash));
}
else {
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, (&hash), 64);
sph_jh512_close(&ctx_jh, (&hash));
}
}
memcpy(output, hash, 32);
}
__global__ __launch_bounds__(128, 8)
void jha_filter_gpu(const uint32_t threads, const uint32_t* d_hash, uint32_t* d_branch2, uint32_t* d_NonceBranch)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
const uint32_t offset = thread * 16U; // 64U / sizeof(uint32_t);
uint4 *psrc = (uint4*) (&d_hash[offset]);
d_NonceBranch[thread] = ((uint8_t*)psrc)[0] & 0x01;
if (d_NonceBranch[thread]) return;
// uint4 = 4x uint32_t = 16 bytes
uint4 *pdst = (uint4*) (&d_branch2[offset]);
pdst[0] = psrc[0];
pdst[1] = psrc[1];
pdst[2] = psrc[2];
pdst[3] = psrc[3];
}
}
__global__ __launch_bounds__(128, 8)
void jha_merge_gpu(const uint32_t threads, uint32_t* d_hash, uint32_t* d_branch2, uint32_t* const d_NonceBranch)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads && !d_NonceBranch[thread])
{
const uint32_t offset = thread * 16U;
uint4 *pdst = (uint4*) (&d_hash[offset]);
uint4 *psrc = (uint4*) (&d_branch2[offset]);
pdst[0] = psrc[0];
pdst[1] = psrc[1];
pdst[2] = psrc[2];
pdst[3] = psrc[3];
}
}
__host__
uint32_t jha_filter_cpu(const int thr_id, const uint32_t threads, const uint32_t *inpHashes, uint32_t* d_branch2)
{
const uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
// extract algo permution hashes to a second branch buffer
jha_filter_gpu <<<grid, block>>> (threads, inpHashes, d_branch2, d_tempBranch[thr_id]);
return threads;
}
__host__
void jha_merge_cpu(const int thr_id, const uint32_t threads, uint32_t *outpHashes, uint32_t* d_branch2)
{
const uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
// put back second branch hashes to the common buffer d_hash
jha_merge_gpu <<<grid, block>>> (threads, outpHashes, d_branch2, d_tempBranch[thr_id]);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_jha(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(64) endiandata[22];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
int dev_id = device_map[thr_id];
uint32_t throughput = cuda_default_throughput(thr_id, 1U << 20);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (opt_benchmark)
ptarget[7] = 0x000f;
if (!init[thr_id])
{
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
CUDA_LOG_ERROR();
}
cuda_get_arch(thr_id);
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput));
CUDA_SAFE_CALL(cudaMalloc(&d_hash_br2[thr_id], (size_t) 64 * throughput));
CUDA_SAFE_CALL(cudaMalloc(&d_tempBranch[thr_id], sizeof(uint32_t) * throughput));
jackpot_keccak512_cpu_init(thr_id, throughput);
quark_blake512_cpu_init(thr_id, throughput);
quark_groestl512_cpu_init(thr_id, throughput);
quark_jh512_cpu_init(thr_id, throughput);
quark_skein512_cpu_init(thr_id, throughput);
cuda_check_cpu_init(thr_id, throughput);
init[thr_id] = true;
}
for (int k=0; k < 22; k++)
be32enc(&endiandata[k], pdata[k]);
jackpot_keccak512_cpu_setBlock((void*)endiandata, 80);
cuda_check_cpu_setTarget(ptarget);
do {
int order = 0;
jackpot_keccak512_cpu_hash(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
for (int rnd = 0; rnd < 3; rnd++)
{
jha_filter_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash_br2[thr_id], order++);
jha_merge_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
jha_filter_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
quark_blake512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash_br2[thr_id], order++);
jha_merge_cpu(thr_id, throughput, d_hash[thr_id], d_hash_br2[thr_id]);
}
*hashes_done = pdata[19] - first_nonce + throughput;
CUDA_LOG_ERROR();
work->nonces[0] = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
if (work->nonces[0] != UINT32_MAX)
{
const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(64) vhash[8];
be32enc(&endiandata[19], work->nonces[0]);
jha_hash(vhash, endiandata);
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
work->valid_nonces = 1;
work_set_target_ratio(work, vhash);
work->nonces[1] = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
if (work->nonces[1] != 0) {
be32enc(&endiandata[19], work->nonces[1]);
jha_hash(vhash, endiandata);
bn_set_target_ratio(work, vhash, 1);
work->valid_nonces++;
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1;
} else {
pdata[19] = work->nonces[0] + 1; // cursor
}
return work->valid_nonces;
}
else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", work->nonces[0]);
pdata[19] = work->nonces[0] + 1;
continue;
}
}
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
CUDA_LOG_ERROR();
return 0;
}
// cleanup
extern "C" void free_jha(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
cudaFree(d_hash[thr_id]);
cudaFree(d_hash_br2[thr_id]);
cudaFree(d_tempBranch[thr_id]);
quark_blake512_cpu_free(thr_id);
quark_groestl512_cpu_free(thr_id);
cuda_check_cpu_free(thr_id);
CUDA_LOG_ERROR();
cudaDeviceSynchronize();
init[thr_id] = false;
}
+80 -26
View File
@@ -9,7 +9,7 @@ endif
EXTRA_DIST = autogen.sh README.md README.txt LICENSE.txt \
ccminer.sln ccminer.vcxproj ccminer.vcxproj.filters \
compat/gettimeofday.c compat/getopt/getopt_long.c cpuminer-config.h.in
compat/gettimeofday.c compat/getopt/getopt_long.c
SUBDIRS = compat
@@ -19,8 +19,11 @@ ccminer_SOURCES = elist.h miner.h compat.h \
compat/inttypes.h compat/stdbool.h compat/unistd.h \
compat/sys/time.h compat/getopt/getopt.h \
crc32.c hefty1.c \
ccminer.cpp pools.cpp util.cpp bignum.cpp \
ccminer.cpp pools.cpp util.cpp bench.cpp bignum.cpp \
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
nvsettings.cpp \
equi/equi-stratum.cpp equi/equi.cpp equi/blake2/blake2bx.cpp \
equi/equihash.cpp equi/cuda_equi.cu \
heavy/heavy.cu \
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
heavy/cuda_combine.cu heavy/cuda_combine.h \
@@ -28,34 +31,60 @@ ccminer_SOURCES = elist.h miner.h compat.h \
heavy/cuda_hefty1.cu heavy/cuda_hefty1.h \
heavy/cuda_keccak512.cu heavy/cuda_keccak512.h \
heavy/cuda_sha256.cu heavy/cuda_sha256.h \
heavy/bastion.cu heavy/cuda_bastion.cu \
fuguecoin.cpp Algo256/cuda_fugue256.cu sph/fugue.c uint256.h \
groestlcoin.cpp cuda_groestlcoin.cu cuda_groestlcoin.h \
myriadgroestl.cpp cuda_myriadgroestl.cu \
lyra2/Lyra2.c lyra2/Sponge.c \
lyra2/lyra2RE.cu lyra2/cuda_lyra2.cu \
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
Algo256/blake256.cu Algo256/keccak256.cu \
JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \
lyra2/lyra2REv3.cu lyra2/cuda_lyra2v3.cu \
lyra2/Lyra2Z.c lyra2/lyra2Z.cu lyra2/cuda_lyra2Z.cu \
lyra2/allium.cu \
Algo256/cuda_bmw256.cu Algo256/cuda_cubehash256.cu \
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu \
Algo256/cuda_keccak256_sm3.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
Algo256/blake256.cu Algo256/decred.cu Algo256/vanilla.cu Algo256/keccak256.cu \
Algo256/blake2s.cu sph/blake2s.c \
Algo256/bmw.cu Algo256/cuda_bmw.cu \
blake2b.cu \
crypto/xmr-rpc.cpp crypto/wildkeccak-cpu.cpp crypto/wildkeccak.cu \
crypto/cryptolight.cu crypto/cryptolight-core.cu crypto/cryptolight-cpu.cpp \
crypto/cryptonight.cu crypto/cryptonight-core.cu crypto/cryptonight-extra.cu \
crypto/cryptonight-cpu.cpp crypto/oaes_lib.cpp crypto/aesb.cpp crypto/cpu/c_keccak.c \
JHA/jha.cu JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
JHA/cuda_jha_compactionTest.cu cuda_checkhash.cu \
quark/cuda_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_skein512.cu \
quark/cuda_bmw512.cu quark/cuda_quark_keccak512.cu \
quark/quarkcoin.cu quark/animecoin.cu \
quark/cuda_quark_compactionTest.cu \
quark/nist5.cu \
quark/quarkcoin.cu quark/cuda_quark_compactionTest.cu \
neoscrypt/neoscrypt.cpp neoscrypt/neoscrypt-cpu.c neoscrypt/cuda_neoscrypt.cu \
cuda_nist5.cu pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
skunk/skunk.cu skunk/cuda_skunk.cu skunk/cuda_skunk_streebog.cu \
sha256/sha256d.cu sha256/cuda_sha256d.cu sha256/sha256t.cu sha256/cuda_sha256t.cu sha256/sha256q.cu sha256/cuda_sha256q.cu \
sia/sia.cu sia/sia-rpc.cpp sph/blake2b.c \
sph/bmw.c sph/blake.c sph/groestl.c sph/jh.c sph/keccak.c sph/skein.c \
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/shavite.c sph/simd.c \
sph/hamsi.c sph/hamsi_helper.c sph/sph_hamsi.h \
sph/hamsi.c sph/hamsi_helper.c sph/streebog.c \
sph/shabal.c sph/whirlpool.c sph/sha2big.c sph/haval.c \
sph/ripemd.c sph/sph_sha2.c \
polytimos.cu \
lbry/lbry.cu lbry/cuda_sha256_lbry.cu lbry/cuda_sha512_lbry.cu lbry/cuda_lbry_merged.cu \
qubit/qubit.cu qubit/qubit_luffa512.cu qubit/deep.cu qubit/luffa.cu \
x11/x11.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \
x11/cuda_x11_luffa512_Cubehash.cu \
tribus/tribus.cu tribus/cuda_echo512_final.cu \
x11/x11.cu x12/x12.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu x11/exosis.cu \
x11/cuda_x11_luffa512_Cubehash.cu x11/x11evo.cu x11/timetravel.cu x11/bitcore.cu \
x13/x13.cu x13/cuda_x13_hamsi512.cu x13/cuda_x13_fugue512.cu \
x13/hsr.cu x13/cuda_hsr_sm3.cu x13/sm3.c \
x15/x14.cu x15/x15.cu x15/cuda_x14_shabal512.cu x15/cuda_x15_whirlpool.cu \
x15/whirlpoolx.cu x15/cuda_whirlpoolx.cu \
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
x11/c11.cu x11/s3.cu
x15/whirlpool.cu x15/cuda_x15_whirlpool_sm3.cu \
x16/x16r.cu x16/x16s.cu x16/cuda_x16_echo512.cu x16/cuda_x16_fugue512.cu \
x16/cuda_x16_shabal512.cu x16/cuda_x16_simd512_80.cu \
x16/cuda_x16_echo512_64.cu \
x17/x17.cu x17/hmq17.cu x17/sonoa.cu x17/cuda_x17_haval256.cu x17/cuda_x17_sha512.cu \
phi/phi.cu phi/phi2.cu phi/cuda_phi2.cu phi/cuda_phi2_cubehash512.cu x11/cuda_streebog_maxwell.cu \
x11/c11.cu x11/s3.cu x11/sib.cu x11/veltor.cu x11/cuda_streebog.cu
# scrypt
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
@@ -74,15 +103,28 @@ ccminer_SOURCES += compat/winansi.c
endif
ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @PCILIB@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @PCIFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs)
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs)
nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"
if HAVE_OSX
ccminer_CPPFLAGS += -I/usr/local/llvm/lib/clang/4.0.0/include
ccminer_LDFLAGS += -L/usr/local/llvm/lib
ccminer_LDADD += -lomp
endif
#nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
#ccminer_CPPFLAGS += -DUSE_LIBSODIUM
#ccminer_LDFLAGS += -Lequi/lib
#ccminer_LDADD += -lsodium
ccminer_LDADD += -lcuda
nvcc_ARCH :=
#nvcc_ARCH += -gencode=arch=compute_75,code=\"sm_75,compute_75\" # CUDA 10 req.
#nvcc_ARCH += -gencode=arch=compute_70,code=\"sm_70,compute_70\" # CUDA 9.1
#nvcc_ARCH += -gencode=arch=compute_61,code=\"sm_61,compute_61\" # CUDA 8
nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
#nvcc_ARCH += -gencode=arch=compute_50,code=\"sm_50,compute_50\"
#nvcc_ARCH += -gencode=arch=compute_35,code=\"sm_35,compute_35\"
#nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\"
#nvcc_ARCH += -gencode=arch=compute_20,code=\"sm_21,compute_20\"
nvcc_FLAGS = $(nvcc_ARCH) @CUDA_INCLUDES@ -I. @CUDA_CFLAGS@
nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v"
@@ -94,6 +136,15 @@ nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v"
Algo256/blake256.o: Algo256/blake256.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
Algo256/cuda_bmw.o: Algo256/cuda_bmw.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=76 -o $@ -c $<
crypto/cryptonight-core.o: crypto/cryptonight-core.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
crypto/cryptonight-extra.o: crypto/cryptonight-extra.cu
$(NVCC) $(nvcc_FLAGS) -o $@ -c $<
heavy/cuda_hefty1.o: heavy/cuda_hefty1.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
@@ -107,6 +158,9 @@ x11/cuda_x11_luffa512.o: x11/cuda_x11_luffa512.cu
x11/cuda_x11_luffa512_Cubehash.o: x11/cuda_x11_luffa512_Cubehash.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=76 -o $@ -c $<
x11/cuda_x11_simd512.o: x11/cuda_x11_simd512.cu
$(NVCC) $(nvcc_FLAGS) -Xcompiler -Wno-unused-variable -o $@ -c $<
x13/cuda_x13_hamsi512.o: x13/cuda_x13_hamsi512.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=72 -o $@ -c $<
@@ -116,6 +170,9 @@ x17/cuda_x17_sha512.o: x17/cuda_x17_sha512.cu
quark/cuda_quark_blake512.o: quark/cuda_quark_blake512.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
quark/cuda_jh512.o: quark/cuda_jh512.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
quark/cuda_quark_keccak512.o: quark/cuda_quark_keccak512.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=88 -o $@ -c $<
@@ -127,15 +184,15 @@ JHA/cuda_jha_compactionTest.o: JHA/cuda_jha_compactionTest.cu
# This object does not use cuda device code but call the different kernels (autotune)
scrypt/salsa_kernel.o: scrypt/salsa_kernel.cu
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_21,compute_20\" -o $@ -c $<
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
# These kernels are for older devices (SM)
scrypt/test_kernel.o: scrypt/test_kernel.cu
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_20,compute_20\" -o $@ -c $<
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
scrypt/fermi_kernel.o: scrypt/fermi_kernel.cu
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_20,code=\"sm_21,compute_20\" -o $@ -c $<
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
scrypt/kepler_kernel.o: scrypt/kepler_kernel.cu
$(NVCC) $(JANSSON_INCLUDES) -I. @CUDA_INCLUDES@ @CUDA_CFLAGS@ -gencode=arch=compute_30,code=\"sm_30,compute_30\" -o $@ -c $<
@@ -149,6 +206,3 @@ scrypt/titan_kernel.o: scrypt/titan_kernel.cu
skein.o: skein.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
skein2.o: skein2.cu
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
+17 -30
View File
@@ -1,36 +1,23 @@
ccminer
=======
## ccminer
Based on Christian Buchner's &amp; Christian H.'s CUDA project, no more active on github recently.
This is a fork of https://github.com/tpruvot/ccminer.git with additions for mining LBRY. It is a CUDA miner. It requires nVidia hardware.
Early editions of ccminer included support for LBRY through the old getwork interface that is still in use by many pools. This fork also includes support for direct use of getblocktemplate (GBT).
Fork by tpruvot@github with X14,X15,X17,Blake256,BlakeCoin,Lyra2RE,Skein,ZR5 and others, check the [README.txt](README.txt)
BTC donation address: 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo
[![tip for next commit](https://tip4commit.com/projects/927.svg)](https://tip4commit.com/github/tpruvot/ccminer)
### Solo mining direct:
```
# start a lbrycrd daemon on testnet:
./lbrycrdd -server -txindex -rpcuser=ruser -rpcpassword=rpswd -testnet
A part of the recent algos were originally wrote by [djm34](https://github.com/djm34).
# in a separate console, run ccminer:
./ccminer -a lbry -o 127.0.0.1:19245 -u ruser -p rpswd -D
This variant was tested and built on Linux (ubuntu server 14.04) and VStudio 2013 on Windows 7.
Note that the x86 releases are generally faster than x64 ones on Windows.
About source code dependencies
------------------------------
This project requires some libraries to be built :
- OpenSSL (prebuilt for win)
- Curl (prebuilt for win)
- pthreads (prebuilt for win)
The tree now contains recent prebuilt openssl and curl .lib for both x86 and x64 platforms (windows).
To rebuild them, you need to clone this repository and its submodules :
git clone https://github.com/peters/curl-for-windows.git compat/curl-for-windows
On Linux, you can use the helper ./build.sh (edit it if required)
There is also an old [Tutorial for windows](http://cudamining.co.uk/url/tutorials/id/3) on [CudaMining](http://cudamining.co.uk) website.
```
This requires support for coinbasetxn in lbrycrd's getblocktemplate implementation, which is fairly new.
### Compilation:
```
./autogen.sh
./configure --with-cuda=/usr/lib/cuda-10.1/targets/x86_64-linux CXXFLAGS="-Og -march=native -g -Wfatal-errors -L/usr/lib/cuda-10.1/targets/x86_64-linux/lib" CFLAGS="-Og -march=native -g"
make -j5
```
+222 -35
View File
@@ -1,5 +1,5 @@
ccMiner release 1.6.5-C11 (Jul 2015) "Special for Chaincoin C11"
ccminer 2.3.1 "lyra2v3, exosis and sha256q"
---------------------------------------------------------------
***************************************************************
@@ -8,8 +8,7 @@ If you find this tool useful and like to support its continuous
tpruvot@github:
BTC : 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo
DRK : XeVrkPrWB7pDbdFLfKhF1Z3xpqhsx6wkH3
ZRC : ZEcubH2xp2mpuwxMjy7wZThr5AzLGu3mqT
DCR : DsUCcACGcyP8McNMRXQwbtpDxaVUYLDQDeU
DJM34:
BTC donation address: 1NENYmxwZGHsKFmyjTc5WferTn5VTFb7Ze
@@ -24,10 +23,12 @@ cbuchner v1.2:
This is a CUDA accelerated mining application which handle :
Decred (Blake256 14-rounds - 180 bytes)
HeavyCoin & MjollnirCoin
FugueCoin
GroestlCoin & Myriad-Groestl
JackpotCoin
Lbry Credits
JackpotCoin (JHA)
QuarkCoin family & AnimeCoin
TalkCoin
DarkCoin and other X11 coins
@@ -40,62 +41,95 @@ Keccak (Maxcoin)
Pentablake (Blake 512 x5)
1Coin Triple S
Neoscrypt (FeatherCoin)
x11evo (Revolver)
phi2 (LUXCoin)
Scrypt and Scrypt:N
Scrypt-Jane (Chacha)
sib (Sibcoin)
Skein (Skein + SHA)
Signatum (Skein cubehash fugue Streebog)
SonoA (Sono)
Tribus (JH, keccak, simd)
Woodcoin (Double Skein)
Vertcoin Lyra2RE
Ziftrcoin (ZR5)
Vanilla (Blake256 8-rounds - double sha256)
Vertcoin Lyra2REv3
Boolberry (Wild Keccak)
Monero (Cryptonight v7 with -a monero)
Aeon (Cryptonight-lite)
where some of these coins have a VERY NOTABLE nVidia advantage
over competing AMD (OpenCL Only) implementations.
We did not take a big effort on improving usability, so please set
your parameters carefuly.
THIS PROGRAMM IS PROVIDED "AS-IS", USE IT AT YOUR OWN RISK!
If you're interessted and read the source-code, please excuse
that the most of our comments are in german.
>>> Command Line Interface <<<
This code is based on the pooler cpuminer and inherits
The code is based on the pooler cpuminer and inherits
its command line interface and options.
-a, --algo=ALGO specify the algorithm to use
anime use to mine Animecoin
blake use to mine Saffroncoin (Blake 256)
allium use to mine Garlic
bastion use to mine Joincoin
bitcore use to mine Bitcore's Timetravel10
blake use to mine Saffroncoin (Blake256)
blakecoin use to mine Old Blake 256
blake2s use to mine Nevacoin (Blake2-S 256)
bmw use to mine Midnight
cryptolight use to mine AEON cryptonight variant 1 (MEM/2)
cryptonight use to mine original cryptonight
c11/flax use to mine Chaincoin and Flax
decred use to mine Decred 180 bytes Blake256-14
deep use to mine Deepcoin
dmd-gr use to mine Diamond-Groestl
equihash use to mine ZEC, HUSH and KMD
exosis use to mine EXO
fresh use to mine Freshcoin
fugue256 use to mine Fuguecoin
groestl use to mine Groestlcoin
heavy use to mine Heavycoin
jackpot use to mine Jackpotcoin
hsr use to mine Hshare
jackpot use to mine Sweepcoin
keccak use to mine Maxcoin
keccakc use to mine CreativeCoin
lbry use to mine LBRY Credits
luffa use to mine Joincoin
lyra2 use to mine Vertcoin
mjollnir use to mine Mjollnircoin
lyra2 use to mine CryptoCoin
lyra2v2 use to mine Monacoin
lyra2v3 use to mine Vertcoin
lyra2z use to mine Zerocoin (XZC)
monero use to mine Monero (XMR)
myr-gr use to mine Myriad-Groest
neoscrypt use to mine FeatherCoin
neoscrypt use to mine FeatherCoin, Trezarcoin, Orbitcoin, etc
nist5 use to mine TalkCoin
penta use to mine Joincoin / Pentablake
phi1612 use to mine Seraph
phi2 use to mine LUXCoin
polytimos use to mine Polytimos
quark use to mine Quarkcoin
qubit use to mine Qubit
scrypt use to mine Scrypt coins
scrypt use to mine Scrypt coins (Litecoin, Dogecoin, etc)
scrypt:N use to mine Scrypt-N (:10 for 2048 iterations)
scrypt-jane use to mine Chacha coins like Cache and Ultracoin
s3 use to mine 1coin
s3 use to mine 1coin (ONE)
sha256t use to mine OneCoin (OC)
sha256q use to mine Pyrite
sia use to mine SIA
sib use to mine Sibcoin
skein use to mine Skeincoin
skein2 use to mine Woodcoin
skunk use to mine Signatum
sonoa use to mine Sono
stellite use to mine Stellite (a cryptonight variant)
timetravel use to mine MachineCoin
tribus use to mine Denarius
x11evo use to mine Revolver
x11 use to mine DarkCoin
x14 use to mine X14Coin
x12 use to mine GalaxyCash
x13 use to mine X13
x14 use to mine X14
x15 use to mine Halcyon
x16r use to mine Raven
x16s use to mine Pigeon and Eden
x17 use to mine X17
whirlpoolx use to mine Vanilla
vanilla use to mine Vanilla (Blake256)
veltor use to mine VeltorCoin
whirlpool use to mine Joincoin
wildkeccak use to mine Boolberry (Stratum only)
zr5 use to mine ZiftrCoin
-d, --devices gives a comma separated list of CUDA device IDs
@@ -105,10 +139,9 @@ its command line interface and options.
-i, --intensity=N[,N] GPU threads per call 8-25 (2^N + F, default: 0=auto)
Decimals and multiple values are allowed for fine tuning
--cuda-schedule Set device threads scheduling mode (default: auto)
-f, --diff-factor Divide difficulty by this factor (default 1.0)
-m, --diff-multiplier Multiply difficulty by this value (default 1.0)
--vote=VOTE block reward vote (for HeavyCoin)
--trust-pool trust the max block reward vote (maxvote) sent by the pool
-o, --url=URL URL of mining server
-O, --userpass=U:P username:password pair for mining server
-u, --user=USERNAME username for mining server
@@ -119,10 +152,12 @@ its command line interface and options.
-r, --retries=N number of times to retry if a network call fails
(default: retry indefinitely)
-R, --retry-pause=N time to pause between retries, in seconds (default: 15)
--shares-limit maximum shares to mine before exiting the program.
--time-limit maximum time [s] to mine before exiting the program.
-T, --timeout=N network timeout, in seconds (default: 270)
-T, --timeout=N network timeout, in seconds (default: 300)
-s, --scantime=N upper bound on time spent scanning current work when
long polling is unavailable, in seconds (default: 5)
--submit-stale ignore stale job checks, may create more rejected shares
-n, --ndevs list cuda devices
-N, --statsavg number of samples used to display hashrate (default: 30)
--no-gbt disable getblocktemplate support (height check in solo)
@@ -132,20 +167,26 @@ its command line interface and options.
--no-color disable colored output
-D, --debug enable debug output
-P, --protocol-dump verbose dump of protocol-level activities
-b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068)
--api-remote Allow remote control
-b, --api-bind=port IP:port for the miner API (default: 127.0.0.1:4068), 0 disabled
--api-remote Allow remote control, like pool switching, imply --api-allow=0/0
--api-allow=... IP/mask of the allowed api client(s), 0/0 for all
--max-temp=N Only mine if gpu temp is less than specified value
--max-rate=N[KMG] Only mine if net hashrate is less than specified value
--max-diff=N Only mine if net difficulty is less than specified value
--max-log-rate Interval to reduce per gpu hashrate logs (default: 3)
--pstate=0 will force the Geforce 9xx to run in P0 P-State
--plimit=150W set the gpu power limit, allow multiple values for N cards
on windows this parameter use percentages (like OC tools)
--tlimit=85 Set the gpu thermal limit (windows only)
--keep-clocks prevent reset clocks and/or power limit on exit
--hide-diff Hide submitted shares diff and net difficulty
-B, --background run the miner in the background
--benchmark run in offline benchmark mode
--cputest debug hashes from cpu algorithms
--cpu-affinity set process affinity to specific cpu core(s) mask
--cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest)
-c, --config=FILE load a JSON-format configuration file
can be from an url with the http:// prefix
-V, --version display version information and exit
-h, --help display this help text and exit
@@ -159,8 +200,23 @@ Scrypt specific options:
-L, --lookup-gap Divides the per-hash memory requirement by this factor
by storing only every N'th value in the scratchpad.
Default is 1.
--texture-cache comma separated list of flags (0/1/2) specifying
which of the CUDA devices shall use the texture
cache for mining. Kepler devices may profit.
--no-autotune disable auto-tuning of kernel launch parameters
CryptoNight specific options:
-l, --launch-config gives the launch configuration for each kernel
in a comma separated list, one per device.
--bfactor=[0-12] Run Cryptonight core kernel in smaller pieces,
From 0 (ui freeze) to 12 (smooth), win default is 11
This is a per-device setting like the launch config.
Wildkeccak specific:
-l, --launch-config gives the launch configuration for each kernel
in a comma separated list, one per device.
-k, --scratchpad url Url used to download the scratchpad cache.
>>> Examples <<<
@@ -184,6 +240,8 @@ Example for Fuguecoin pool mining on dwarfpool.com with all your GPUs
Example for Groestlcoin solo mining
ccminer -q -s 1 -a groestl -o http://127.0.0.1:1441/ -u USERNAME -p PASSWORD
Example for Boolberry
ccminer -a wildkeccak -o stratum+tcp://bbr.suprnova.cc:7777 -u tpruvot.donate -p x -k http://bbr.suprnova.cc/scratchpad.bin -l 64x360
Example for Scrypt-N (2048) on Nicehash
ccminer -a scrypt:10 -o stratum+tcp://stratum.nicehash.com:3335 -u 3EujYFcoBzWvpUEvbe3obEG95mBuU88QBD -p x
@@ -222,9 +280,138 @@ so we can more efficiently implement new algorithms using the latest hardware
features.
>>> RELEASE HISTORY <<<
Jan. 30th 2019 v2.3.1
Handle Lyra2v3 algo
Handle sha256q algo
Handle exosis algo
Handle blake2b standard algo
August 2015...
Restore WhirlpoolX algo
June 23th 2018 v2.3
Handle phi2 header variation for smart contracts
Handle monero, stellite, graft and cryptolight variants
Handle SonoA algo
June 10th 2018 v2.2.6
New phi2 algo for LUX
New allium algo for Garlic
Apr. 02nd 2018 v2.2.5
New x16r algo for Raven
New x16s algo for Pigeon and Eden
New x12 algo for Galaxycash
Equihash (SIMT) sync issues for the Volta generation
Jan. 04th 2018 v2.2.4
Improve lyra2v2
Higher keccak default intensity
Drop SM 2.x support by default, for CUDA 9 and more recent
Dec. 04th 2017 v2.2.3
Polytimos Algo
Handle keccakc variant (with refreshed sha256d merkle)
Optimised keccak for SM5+, based on alexis improvements
Oct. 09th 2017 v2.2.2
Import and clean the hsr algo (x13 + custom hash)
Import and optimise phi algo from LuxCoin repository
Improve sib algo too for maxwell and pascal cards
Small fix to handle more than 9 cards on linux (-d 10+)
Attempt to free equihash memory "properly"
--submit-stale parameter for supernova pool (which change diff too fast)
Sep. 01st 2017 v2.2.1
Improve tribus algo on recent cards (up to +10%)
Aug. 13th 2017 v2.2
New skunk algo, using the heavy streebog algorithm
Enhance tribus algo (+10%)
equihash protocol enhancement on yiimp.ccminer.org and zpool.ca
June 16th 2017 v2.1-tribus
Interface equihash algo with djeZo solver (from nheqminer 0.5c)
New api parameters (and multicast announces for local networks)
New tribus algo
May. 14th 2017 v2.0
Handle cryptonight, wildkeccak and cryptonight-lite
Add a serie of new algos: timetravel, bastion, hmq1725, sha256t
Import lyra2z from djm34 work...
Rework the common skein512 (used in most algos except skein ;)
Upgrade whirlpool algo with alexis version (2x faster)
Store the share diff of second nonce(s) in most algos
Hardware monitoring thread to get more accurate power readings
Small changes for the quiet mode & max-log-rate to reduce logs
Add bitcore and a compatible jha algo
Dec. 21th 2016 v1.8.4
Improve streebog based algos, veltor and sib (from alexis work)
Blake2s greetly improved (3x), thanks to alexis too...
Sep. 28th 2016 v1.8.3
show intensity on startup for each cards
show-diff is now used by default, use --hide-diff if not wanted
Sep. 22th 2016 v1.8.2
lbry improvements by Alexis Provos
Prevent Windows hibernate while mining
veltor algo (basic implementation)
Aug. 10th 2016 v1.8.1
SIA Blake2-B Algo (getwork over stratum for Suprnova)
SIA Nanopool RPC (getwork over http)
Update also the older lyra2 with Nanashi version
July 20th 2016 v1.8.0
Pascal support with cuda 8
lbry new multi sha / ripemd algo (LBC)
x11evo algo (XRE)
Lyra2v2, Neoscrypt and Decred improvements
Enhance windows NVAPI clock and power limits
Led support for mining/shares activity on windows
May 18th 2016 v1.7.6
Decred vote support
X17 cleanup and improvement
Add mining.ping stratum method and handle unknown methods
Implement a pool stats/benchmark mode (-p stats on yiimp)
Add --shares-limit parameter, can be used for benchmarks
Mar. 13th 2016 v1.7.5
Blake2S Algo (NEVA/OXEN)
Feb. 28th 2016 v1.7.4 (1.7.3 was a preview, not official)
Decred simplified stratum (getwork over stratum)
Vanilla kernel by MrMad
Drop/Disable WhirlpoolX
Feb. 11th 2016 v1.7.2
Decred Algo (longpoll only)
Blake256 improvements/cleanup
Jan. 26th 2016 v1.7.1
Implement sib algo (X11 + Russian Streebog-512/GOST)
Whirlpool speed x2 with the midstate precompute
Small bug fixes about device ids mapping (and vendor names)
Add Vanilla algo (Blake256 8-rounds - double sha256)
Nov. 06th 2015 v1.7
Improve old devices compatibility (x11, lyra2v2, quark, qubit...)
Add windows support for SM 2.1 and drop SM 3.5 (x86)
Improve lyra2 (v1/v2) cuda implementations
Improve most common algos on SM5+ with sp blake kernel
Restore whirlpool algo (and whirlcoin variant)
Prepare algo/pool switch ability, trivial method
Add --benchmark alone to run a benchmark for all algos
Add --cuda-schedule parameter
Add --show-diff parameter, which display shares diff,
and is able to detect real solved blocks on pools.
Aug. 28th 2015 v1.6.6
Allow to load remote config with curl (-c http://...)
Add Lyra2REv2 algo (Vertcoin/Zoom)
Restore WhirlpoolX algo (VNL)
Drop Animecoin support
Add bmw (Midnight) algo
July 06th 2015 v1.6.5-C11
Nvml api power limits
+252
View File
@@ -0,0 +1,252 @@
#ifndef ALGOS_H
#define ALGOS_H
#include <string.h>
#include "compat.h"
enum sha_algos {
ALGO_BLAKECOIN = 0,
ALGO_BLAKE,
ALGO_BLAKE2B,
ALGO_BLAKE2S,
ALGO_ALLIUM,
ALGO_BMW,
ALGO_BASTION,
ALGO_C11,
ALGO_CRYPTOLIGHT,
ALGO_CRYPTONIGHT,
ALGO_DEEP,
ALGO_DECRED,
ALGO_DMD_GR,
ALGO_EQUIHASH,
ALGO_EXOSIS,
ALGO_FRESH,
ALGO_FUGUE256, /* Fugue256 */
ALGO_GROESTL,
ALGO_HEAVY, /* Heavycoin hash */
ALGO_HMQ1725,
ALGO_HSR,
ALGO_KECCAK,
ALGO_KECCAKC, /* refreshed Keccak with pool factor 256 */
ALGO_JACKPOT,
ALGO_JHA,
ALGO_LBRY,
ALGO_LUFFA,
ALGO_LYRA2,
ALGO_LYRA2v2,
ALGO_LYRA2v3,
ALGO_LYRA2Z,
ALGO_MJOLLNIR, /* Hefty hash */
ALGO_MYR_GR,
ALGO_NEOSCRYPT,
ALGO_NIST5,
ALGO_PENTABLAKE,
ALGO_PHI,
ALGO_PHI2,
ALGO_POLYTIMOS,
ALGO_QUARK,
ALGO_QUBIT,
ALGO_SCRYPT,
ALGO_SCRYPT_JANE,
ALGO_SHA256D,
ALGO_SHA256T,
ALGO_SHA256Q,
ALGO_SIA,
ALGO_SIB,
ALGO_SKEIN,
ALGO_SKEIN2,
ALGO_SKUNK,
ALGO_SONOA,
ALGO_S3,
ALGO_TIMETRAVEL,
ALGO_TRIBUS,
ALGO_BITCORE,
ALGO_X11EVO,
ALGO_X11,
ALGO_X12,
ALGO_X13,
ALGO_X14,
ALGO_X15,
ALGO_X16R,
ALGO_X16S,
ALGO_X17,
ALGO_VANILLA,
ALGO_VELTOR,
ALGO_WHIRLCOIN,
ALGO_WHIRLPOOL,
ALGO_WHIRLPOOLX,
ALGO_WILDKECCAK,
ALGO_ZR5,
ALGO_MONERO,
ALGO_GRAFT,
ALGO_STELLITE,
ALGO_AUTO,
ALGO_COUNT
};
extern volatile enum sha_algos opt_algo;
static const char *algo_names[] = {
"blakecoin",
"blake",
"blake2b",
"blake2s",
"allium",
"bmw",
"bastion",
"c11",
"cryptolight",
"cryptonight",
"deep",
"decred",
"dmd-gr",
"equihash",
"exosis",
"fresh",
"fugue256",
"groestl",
"heavy",
"hmq1725",
"hsr",
"keccak",
"keccakc",
"jackpot",
"jha",
"lbry",
"luffa",
"lyra2",
"lyra2v2",
"lyra2v3",
"lyra2z",
"mjollnir",
"myr-gr",
"neoscrypt",
"nist5",
"penta",
"phi",
"phi2",
"polytimos",
"quark",
"qubit",
"scrypt",
"scrypt-jane",
"sha256d",
"sha256t",
"sha256q",
"sia",
"sib",
"skein",
"skein2",
"skunk",
"sonoa",
"s3",
"timetravel",
"tribus",
"bitcore",
"x11evo",
"x11",
"x12",
"x13",
"x14",
"x15",
"x16r",
"x16s",
"x17",
"vanilla",
"veltor",
"whirlcoin",
"whirlpool",
"whirlpoolx",
"wildkeccak",
"zr5",
"monero",
"graft",
"stellite",
"auto", /* reserved for multi algo */
""
};
// string to int/enum
static inline int algo_to_int(char* arg)
{
int i;
for (i = 0; i < ALGO_COUNT; i++) {
if (algo_names[i] && !strcasecmp(arg, algo_names[i])) {
return i;
}
}
if (i == ALGO_COUNT) {
// some aliases...
if (!strcasecmp("all", arg))
i = ALGO_AUTO;
else if (!strcasecmp("cryptonight-light", arg))
i = ALGO_CRYPTOLIGHT;
else if (!strcasecmp("cryptonight-lite", arg))
i = ALGO_CRYPTOLIGHT;
else if (!strcasecmp("flax", arg))
i = ALGO_C11;
else if (!strcasecmp("diamond", arg))
i = ALGO_DMD_GR;
else if (!strcasecmp("equi", arg))
i = ALGO_EQUIHASH;
else if (!strcasecmp("doom", arg))
i = ALGO_LUFFA;
else if (!strcasecmp("hmq17", arg))
i = ALGO_HMQ1725;
else if (!strcasecmp("hshare", arg))
i = ALGO_HSR;
else if (!strcasecmp("lyra2re", arg))
i = ALGO_LYRA2;
else if (!strcasecmp("lyra2rev2", arg))
i = ALGO_LYRA2v2;
else if (!strcasecmp("lyra2rev3", arg))
i = ALGO_LYRA2v3;
else if (!strcasecmp("phi1612", arg))
i = ALGO_PHI;
else if (!strcasecmp("bitcoin", arg))
i = ALGO_SHA256D;
else if (!strcasecmp("sha256", arg))
i = ALGO_SHA256D;
else if (!strcasecmp("thorsriddle", arg))
i = ALGO_VELTOR;
else if (!strcasecmp("timetravel10", arg))
i = ALGO_BITCORE;
else if (!strcasecmp("whirl", arg))
i = ALGO_WHIRLPOOL;
else if (!strcasecmp("ziftr", arg))
i = ALGO_ZR5;
else
i = -1;
}
return i;
}
static inline int get_cryptonight_algo(int fork)
{
int algo = ALGO_COUNT;
switch (fork) {
case 8:
algo = ALGO_GRAFT;
break;
case 7:
algo = ALGO_MONERO;
break;
case 3:
algo = ALGO_STELLITE;
break;
default:
algo = ALGO_CRYPTONIGHT;
break;
}
return algo;
}
#endif
+444 -98
View File
@@ -8,7 +8,7 @@
* Software Foundation; either version 2 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#define APIVERSION "1.6"
#define APIVERSION "1.9"
#ifdef WIN32
# define _WINSOCK_DEPRECATED_NO_WARNINGS
@@ -33,6 +33,7 @@
#include "miner.h"
#include "nvml.h"
#include "algos.h"
#ifndef WIN32
# include <errno.h>
@@ -85,13 +86,20 @@ static struct IP4ACCESS *ipaccess = NULL;
#define ALLIP4 "0.0.0.0"
static const char *localaddr = "127.0.0.1";
static const char *UNAVAILABLE = " - API will not be available";
static const char *MUNAVAILABLE = " - API multicast listener will not be available";
static char *buffer = NULL;
static time_t startup = 0;
static int bye = 0;
extern char *opt_api_bind;
extern int opt_api_port;
extern char *opt_api_allow;
extern int opt_api_listen; /* port */
extern int opt_api_remote;
extern char *opt_api_groups;
extern bool opt_api_mcast;
extern char *opt_api_mcast_addr;
extern char *opt_api_mcast_code;
extern char *opt_api_mcast_des;
extern int opt_api_mcast_port;
// current stratum...
extern struct stratum_ctx stratum;
@@ -100,9 +108,6 @@ extern struct stratum_ctx stratum;
extern int num_cpus;
extern float cpu_temp(int);
extern uint32_t cpu_clock(int);
// cuda.cpp
int cuda_num_devices();
int cuda_gpu_clocks(struct cgpu_info *gpu);
char driver_version[32] = { 0 };
@@ -114,34 +119,45 @@ static void gpustatus(int thr_id)
if (thr_id >= 0 && thr_id < opt_n_threads) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
double khashes_per_watt = 0;
int gpuid = cgpu->gpu_id;
char buf[512]; *buf = '\0';
char* card;
cuda_gpu_info(cgpu);
cgpu->gpu_plimit = device_plimit[cgpu->gpu_id];
#ifdef USE_WRAPNVML
cgpu->has_monitoring = true;
cgpu->gpu_bus = gpu_busid(cgpu);
cgpu->gpu_temp = gpu_temp(cgpu);
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
cgpu->gpu_power = gpu_power(cgpu);
cgpu->gpu_power = gpu_power(cgpu); // mWatts
cgpu->gpu_plimit = gpu_plimit(cgpu); // mW or %
#endif
cuda_gpu_clocks(cgpu);
// todo: per gpu
cgpu->accepted = p->accepted_count;
cgpu->rejected = p->rejected_count;
cgpu->khashes = stats_get_speed(thr_id, 0.0) / 1000.0;
if (cgpu->monitor.gpu_power) {
cgpu->gpu_power = cgpu->monitor.gpu_power;
khashes_per_watt = (double)cgpu->khashes / cgpu->monitor.gpu_power;
khashes_per_watt *= 1000; // power in mW
//gpulog(LOG_BLUE, thr_id, "KHW: %g", khashes_per_watt);
}
card = device_name[gpuid];
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;TEMP=%.1f;"
"POWER=%u;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
"POWER=%u;FAN=%hu;RPM=%hu;"
"FREQ=%u;MEMFREQ=%u;GPUF=%u;MEMF=%u;"
"KHS=%.2f;KHW=%.5f;PLIM=%u;"
"ACC=%u;REJ=%u;HWF=%u;I=%.1f;THR=%u|",
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp,
cgpu->gpu_power, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
cgpu->gpu_clock, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity, cgpu->throughput);
cgpu->gpu_clock/1000, cgpu->gpu_memclock/1000, // base freqs in MHz
cgpu->monitor.gpu_clock, cgpu->monitor.gpu_memclock, // current
cgpu->khashes, khashes_per_watt, cgpu->gpu_plimit,
cgpu->accepted, (unsigned) cgpu->rejected, (unsigned) cgpu->hw_errors,
cgpu->intensity, cgpu->throughput);
// append to buffer for multi gpus
strcat(buffer, buf);
@@ -166,14 +182,16 @@ static char *getthreads(char *params)
*/
static char *getsummary(char *params)
{
char algo[64]; *algo = '\0';
char algo[64] = { 0 };
time_t ts = time(NULL);
double accps, uptime = difftime(ts, startup);
uint32_t wait_time = 0, accepted_count = 0, rejected_count = 0;
uint32_t wait_time = 0, solved_count = 0;
uint32_t accepted_count = 0, rejected_count = 0;
for (int p = 0; p < num_pools; p++) {
wait_time += pools[p].wait_time;
accepted_count += pools[p].accepted_count;
rejected_count += pools[p].rejected_count;
solved_count += pools[p].solved_count;
}
accps = (60.0 * accepted_count) / (uptime ? uptime : 1.0);
@@ -181,12 +199,12 @@ static char *getsummary(char *params)
*buffer = '\0';
sprintf(buffer, "NAME=%s;VER=%s;API=%s;"
"ALGO=%s;GPUS=%d;KHS=%.2f;ACC=%d;REJ=%d;"
"ALGO=%s;GPUS=%d;KHS=%.2f;SOLV=%d;ACC=%d;REJ=%d;"
"ACCMN=%.3f;DIFF=%.6f;NETKHS=%.0f;"
"POOLS=%u;WAIT=%u;UPTIME=%.0f;TS=%u|",
PACKAGE_NAME, PACKAGE_VERSION, APIVERSION,
algo, active_gpus, (double)global_hashrate / 1000.,
accepted_count, rejected_count,
solved_count, accepted_count, rejected_count,
accps, net_diff > 1e-6 ? net_diff : stratum_diff, (double)net_hashrate / 1000.,
num_pools, wait_time, uptime, (uint32_t) ts);
return buffer;
@@ -199,9 +217,12 @@ static char *getpoolnfo(char *params)
{
char *s = buffer;
char jobid[128] = { 0 };
char nonce[128] = { 0 };
char extra[96] = { 0 };
int pooln = params ? atoi(params) % num_pools : cur_pooln;
struct pool_infos *p = &pools[pooln];
uint32_t last_share = 0;
if (p->last_share_time)
last_share = (uint32_t) (time(NULL) - p->last_share_time);
*s = '\0';
@@ -209,17 +230,25 @@ static char *getpoolnfo(char *params)
strncpy(jobid, stratum.job.job_id, sizeof(stratum.job.job_id));
if (stratum.job.xnonce2) {
/* used temporary to be sure all is ok */
sprintf(nonce, "0x");
cbin2hex(&nonce[2], (const char*) stratum.job.xnonce2, stratum.xnonce2_size);
sprintf(extra, "0x");
if (p->algo == ALGO_DECRED) {
char compat[32] = { 0 };
cbin2hex(&extra[2], (const char*) stratum.xnonce1, min(36, stratum.xnonce2_size));
cbin2hex(compat, (const char*) stratum.job.xnonce2, 4);
memcpy(&extra[2], compat, 8); // compat extranonce
} else {
cbin2hex(&extra[2], (const char*) stratum.job.xnonce2, stratum.xnonce2_size);
}
}
snprintf(s, MYBUFSIZ, "URL=%s;USER=%s;ACC=%d;REJ=%d;H=%u;JOB=%s;DIFF=%.6f;"
"N2SZ=%d;N2=%s;PING=%u;DISCO=%u;WAIT=%u;UPTIME=%u|",
snprintf(s, MYBUFSIZ, "POOL=%s;ALGO=%s;URL=%s;USER=%s;SOLV=%d;ACC=%d;REJ=%d;STALE=%u;H=%u;JOB=%s;DIFF=%.6f;"
"BEST=%.6f;N2SZ=%d;N2=%s;PING=%u;DISCO=%u;WAIT=%u;UPTIME=%u;LAST=%u|",
strlen(p->name) ? p->name : p->short_url, algo_names[p->algo],
p->url, p->type & POOL_STRATUM ? p->user : "",
p->accepted_count, p->rejected_count,
stratum.job.height, jobid, stratum_diff,
(int) stratum.xnonce2_size, nonce, stratum.answer_msec,
p->disconnects, p->wait_time, p->work_time);
p->solved_count, p->accepted_count, p->rejected_count, p->stales_count,
stratum.job.height, jobid, stratum_diff, p->best_share,
(int) stratum.xnonce2_size, extra, stratum.answer_msec,
p->disconnects, p->wait_time, p->work_time, last_share);
return s;
}
@@ -228,7 +257,7 @@ static char *getpoolnfo(char *params)
static void gpuhwinfos(int gpu_id)
{
char buf[256];
char buf[512];
char pstate[8];
char* card;
struct cgpu_info *cgpu = NULL;
@@ -243,6 +272,9 @@ static void gpuhwinfos(int gpu_id)
if (cgpu == NULL)
return;
cuda_gpu_info(cgpu);
cgpu->gpu_plimit = device_plimit[cgpu->gpu_id];
#ifdef USE_WRAPNVML
cgpu->has_monitoring = true;
cgpu->gpu_bus = gpu_busid(cgpu);
@@ -251,10 +283,12 @@ static void gpuhwinfos(int gpu_id)
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
cgpu->gpu_pstate = (int16_t) gpu_pstate(cgpu);
cgpu->gpu_power = gpu_power(cgpu);
cgpu->gpu_plimit = gpu_plimit(cgpu);
gpu_info(cgpu);
#ifdef WIN32
if (opt_debug) nvapi_pstateinfo(cgpu->gpu_id);
#endif
#endif
cuda_gpu_clocks(cgpu);
memset(pstate, 0, sizeof(pstate));
if (cgpu->gpu_pstate != -1)
@@ -262,13 +296,15 @@ static void gpuhwinfos(int gpu_id)
card = device_name[gpu_id];
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%u;MEM=%lu;"
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;POWER=%u;"
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%hu;MEM=%u;"
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%u;MEMFREQ=%u;GPUF=%u;MEMF=%u;"
"PST=%s;POWER=%u;PLIM=%u;"
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;SN=%s;BIOS=%s|",
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, cgpu->gpu_mem,
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, (uint32_t) cgpu->gpu_mem,
cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
cgpu->gpu_clock, cgpu->gpu_memclock,
pstate, cgpu->gpu_power,
cgpu->gpu_clock/1000U, cgpu->gpu_memclock/1000U, // base clocks
cgpu->monitor.gpu_clock, cgpu->monitor.gpu_memclock, // current
pstate, cgpu->gpu_power, cgpu->gpu_plimit,
cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
cgpu->gpu_sn, cgpu->gpu_desc);
@@ -285,8 +321,12 @@ static const char* os_name()
return "windows";
#else
FILE *fd = fopen("/proc/version", "r");
if (!fd || !fscanf(fd, "Linux version %48s", &os_version[6]))
if (!fd)
return "linux";
if (!fscanf(fd, "Linux version %48s", &os_version[6])) {
fclose(fd);
return "linux";
}
fclose(fd);
os_version[48] = '\0';
return (const char*) os_version;
@@ -305,7 +345,7 @@ static void syshwinfos()
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "OS=%s;NVDRIVER=%s;CPUS=%d;CPUTEMP=%d;CPUFREQ=%d|",
os_name(), driver_version, num_cpus, cputc, cpuclk);
os_name(), driver_version, num_cpus, cputc, cpuclk/1000);
strcat(buffer, buf);
}
@@ -336,7 +376,7 @@ static char *gethistory(char *params)
*buffer = '\0';
for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat;
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%.6f;"
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%g;"
"COUNT=%u;FOUND=%u;ID=%u;TS=%u|",
data[i].gpu_id, data[i].height, data[i].hashrate, data[i].difficulty,
data[i].hashcount, data[i].hashfound, data[i].uid, (uint32_t)ts);
@@ -345,7 +385,7 @@ static char *gethistory(char *params)
}
/**
* Returns the job scans ranges (debug purpose)
* Returns the job scans ranges (debug purpose, only with -D)
*/
static char *getscanlog(char *params)
{
@@ -355,9 +395,11 @@ static char *getscanlog(char *params)
*buffer = '\0';
for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_upd;
p += sprintf(p, "H=%u;P=%u;JOB=%u;N=%u;FROM=0x%x;SCANTO=0x%x;"
p += sprintf(p, "H=%u;P=%u;JOB=%u;ID=%d;DIFF=%g;"
"N=0x%x;FROM=0x%x;SCANTO=0x%x;"
"COUNT=0x%x;FOUND=%u;TS=%u|",
data[i].height, data[i].npool, data[i].njobid, data[i].nonce, data[i].scanned_from, data[i].scanned_to,
data[i].height, data[i].npool, data[i].njobid, (int)data[i].job_nonce_id, data[i].sharediff,
data[i].nonce, data[i].scanned_from, data[i].scanned_to,
(data[i].scanned_to - data[i].scanned_from), data[i].tm_sent ? 1 : 0, (uint32_t)ts);
}
return buffer;
@@ -384,15 +426,6 @@ static char *getmeminfo(char *params)
/*****************************************************************************/
/**
* Remote control allowed ?
* TODO: ip filters
*/
static bool check_remote_access(void)
{
return (opt_api_remote > 0);
}
/**
* Set pool by index (pools array in json config)
* switchpool|1|
@@ -401,17 +434,15 @@ static char *remote_switchpool(char *params)
{
bool ret = false;
*buffer = '\0';
if (!check_remote_access())
return buffer;
if (!params || strlen(params) == 0) {
// rotate pool test
ret = pool_switch_next();
ret = pool_switch_next(-1);
} else {
int n = atoi(params);
if (n == cur_pooln)
ret = true;
else if (n < num_pools)
ret = pool_switch(n);
ret = pool_switch(-1, n);
}
sprintf(buffer, "%s|", ret ? "ok" : "fail");
return buffer;
@@ -425,11 +456,9 @@ static char *remote_seturl(char *params)
{
bool ret;
*buffer = '\0';
if (!check_remote_access())
return buffer;
if (!params || strlen(params) == 0) {
// rotate pool test
ret = pool_switch_next();
ret = pool_switch_next(-1);
} else {
ret = pool_switch_url(params);
}
@@ -443,8 +472,6 @@ static char *remote_seturl(char *params)
static char *remote_quit(char *params)
{
*buffer = '\0';
if (!check_remote_access())
return buffer;
bye = 1;
sprintf(buffer, "%s", "bye|");
return buffer;
@@ -456,22 +483,23 @@ static char *gethelp(char *params);
struct CMDS {
const char *name;
char *(*func)(char *);
bool iswritemode;
} cmds[] = {
{ "summary", getsummary },
{ "threads", getthreads },
{ "pool", getpoolnfo },
{ "histo", gethistory },
{ "hwinfo", gethwinfos },
{ "meminfo", getmeminfo },
{ "scanlog", getscanlog },
{ "summary", getsummary, false },
{ "threads", getthreads, false },
{ "pool", getpoolnfo, false },
{ "histo", gethistory, false },
{ "hwinfo", gethwinfos, false },
{ "meminfo", getmeminfo, false },
{ "scanlog", getscanlog, false },
/* remote functions */
{ "seturl", remote_seturl }, /* prefer switchpool, deprecated */
{ "switchpool", remote_switchpool },
{ "quit", remote_quit },
{ "seturl", remote_seturl, true }, /* prefer switchpool, deprecated */
{ "switchpool", remote_switchpool, true },
{ "quit", remote_quit, true },
/* keep it the last */
{ "help", gethelp },
{ "help", gethelp, false },
};
#define CMDMAX ARRAY_SIZE(cmds)
@@ -479,8 +507,10 @@ static char *gethelp(char *params)
{
*buffer = '\0';
char * p = buffer;
for (int i = 0; i < CMDMAX-1; i++)
p += sprintf(p, "%s\n", cmds[i].name);
for (int i = 0; i < CMDMAX-1; i++) {
bool displayed = !cmds[i].iswritemode || opt_api_allow;
if (displayed) p += sprintf(p, "%s\n", cmds[i].name);
}
sprintf(p, "|");
return buffer;
}
@@ -643,6 +673,146 @@ static int websocket_handshake(SOCKETTYPE c, char *result, char *clientkey)
return 0;
}
/*
* Interpret --api-groups G:cmd1:cmd2:cmd3,P:cmd4,*,...
*/
static void setup_groups()
{
const char *api_groups = opt_api_groups ? opt_api_groups : "";
char *buf, *cmd, *ptr, *next, *colon;
char commands[512] = { 0 };
char cmdbuf[128] = { 0 };
char group;
bool addstar;
int i;
buf = (char *)calloc(1, strlen(api_groups) + 1);
if (unlikely(!buf))
proper_exit(1); //, "Failed to malloc ipgroups buf");
strcpy(buf, api_groups);
next = buf;
// for each group defined
while (next && *next) {
ptr = next;
next = strchr(ptr, ',');
if (next)
*(next++) = '\0';
// Validate the group
if (*(ptr+1) != ':') {
colon = strchr(ptr, ':');
if (colon)
*colon = '\0';
proper_exit(1); //, "API invalid group name '%s'", ptr);
}
group = GROUP(*ptr);
if (!VALIDGROUP(group))
proper_exit(1); //, "API invalid group name '%c'", *ptr);
if (group == PRIVGROUP)
proper_exit(1); //, "API group name can't be '%c'", PRIVGROUP);
if (group == NOPRIVGROUP)
proper_exit(1); //, "API group name can't be '%c'", NOPRIVGROUP);
if (apigroups[GROUPOFFSET(group)].commands != NULL)
proper_exit(1); //, "API duplicate group name '%c'", *ptr);
ptr += 2;
// Validate the command list (and handle '*')
cmd = &(commands[0]);
*(cmd++) = '|';
*cmd = '\0';
addstar = false;
while (ptr && *ptr) {
colon = strchr(ptr, ':');
if (colon)
*(colon++) = '\0';
if (strcmp(ptr, "*") == 0)
addstar = true;
else {
bool did = false;
for (i = 0; i < CMDMAX-1; i++) {
if (strcasecmp(ptr, cmds[i].name) == 0) {
did = true;
break;
}
}
if (did) {
// skip duplicates
sprintf(cmdbuf, "|%s|", cmds[i].name);
if (strstr(commands, cmdbuf) == NULL) {
strcpy(cmd, cmds[i].name);
cmd += strlen(cmds[i].name);
*(cmd++) = '|';
*cmd = '\0';
}
} else {
proper_exit(1); //, "API unknown command '%s' in group '%c'", ptr, group);
}
}
ptr = colon;
}
// * = allow all non-iswritemode commands
if (addstar) {
for (i = 0; i < CMDMAX-1; i++) {
if (cmds[i].iswritemode == false) {
// skip duplicates
sprintf(cmdbuf, "|%s|", cmds[i].name);
if (strstr(commands, cmdbuf) == NULL) {
strcpy(cmd, cmds[i].name);
cmd += strlen(cmds[i].name);
*(cmd++) = '|';
*cmd = '\0';
}
}
}
}
ptr = apigroups[GROUPOFFSET(group)].commands = (char *)calloc(1, strlen(commands) + 1);
if (unlikely(!ptr))
proper_exit(1); //, "Failed to malloc group commands buf");
strcpy(ptr, commands);
}
// Now define R (NOPRIVGROUP) as all non-iswritemode commands
cmd = &(commands[0]);
*(cmd++) = '|';
*cmd = '\0';
for (i = 0; i < CMDMAX-1; i++) {
if (cmds[i].iswritemode == false) {
strcpy(cmd, cmds[i].name);
cmd += strlen(cmds[i].name);
*(cmd++) = '|';
*cmd = '\0';
}
}
ptr = apigroups[GROUPOFFSET(NOPRIVGROUP)].commands = (char *)calloc(1, strlen(commands) + 1);
if (unlikely(!ptr))
proper_exit(1); //, "Failed to malloc noprivgroup commands buf");
strcpy(ptr, commands);
// W (PRIVGROUP) is handled as a special case since it simply means all commands
free(buf);
return;
}
/*
* Interpret [W:]IP[/Prefix][,[R|W:]IP2[/Prefix2][,...]] --api-allow option
* special case of 0/0 allows /0 (means all IP addresses)
*/
#define ALLIPS "0/0"
/*
* N.B. IP4 addresses are by Definition 32bit big endian on all platforms
*/
@@ -692,7 +862,7 @@ static void setup_ipaccess()
ipaccess[ips].group = group;
if (strcmp(ptr, ALLIP4) == 0)
if (strcmp(ptr, ALLIPS) == 0 || strcmp(ptr, ALLIP4) == 0)
ipaccess[ips].ip = ipaccess[ips].mask = 0;
else
{
@@ -755,16 +925,184 @@ static bool check_connect(struct sockaddr_in *cli, char **connectaddr, char *gro
}
}
}
else if (strcmp(opt_api_bind, ALLIP4) == 0)
addrok = true;
else
addrok = (strcmp(*connectaddr, localaddr) == 0);
return addrok;
}
static void mcast()
{
struct sockaddr_in listen;
struct ip_mreq grp;
struct sockaddr_in came_from;
time_t bindstart;
char *binderror;
SOCKETTYPE mcast_sock;
SOCKETTYPE reply_sock;
socklen_t came_from_siz;
char *connectaddr;
ssize_t rep;
int bound;
int count;
int reply_port;
bool addrok;
char group;
char expect[] = "ccminer-"; // first 8 bytes constant
char *expect_code;
size_t expect_code_len;
char buf[1024];
char replybuf[1024];
memset(&grp, 0, sizeof(grp));
grp.imr_multiaddr.s_addr = inet_addr(opt_api_mcast_addr);
if (grp.imr_multiaddr.s_addr == INADDR_NONE)
proper_exit(1); //, "Invalid Multicast Address");
grp.imr_interface.s_addr = INADDR_ANY;
mcast_sock = socket(AF_INET, SOCK_DGRAM, 0);
int optval = 1;
if (SOCKETFAIL(setsockopt(mcast_sock, SOL_SOCKET, SO_REUSEADDR, (const char *)(&optval), sizeof(optval)))) {
applog(LOG_ERR, "API mcast setsockopt SO_REUSEADDR failed (%s)%s", strerror(errno), MUNAVAILABLE);
goto die;
}
memset(&listen, 0, sizeof(listen));
listen.sin_family = AF_INET;
listen.sin_addr.s_addr = INADDR_ANY;
listen.sin_port = htons(opt_api_mcast_port);
// try for more than 1 minute ... in case the old one hasn't completely gone yet
bound = 0;
bindstart = time(NULL);
while (bound == 0) {
if (SOCKETFAIL(bind(mcast_sock, (struct sockaddr *)(&listen), sizeof(listen)))) {
binderror = strerror(errno);;
if ((time(NULL) - bindstart) > 61)
break;
else
sleep(30);
}
else
bound = 1;
}
if (bound == 0) {
applog(LOG_ERR, "API mcast bind to port %d failed (%s)%s", opt_api_port, binderror, MUNAVAILABLE);
goto die;
}
if (SOCKETFAIL(setsockopt(mcast_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)(&grp), sizeof(grp)))) {
applog(LOG_ERR, "API mcast join failed (%s)%s", strerror(errno), MUNAVAILABLE);
goto die;
}
expect_code_len = sizeof(expect) + strlen(opt_api_mcast_code);
expect_code = (char *)calloc(1, expect_code_len + 1);
if (!expect_code)
proper_exit(1); //, "Failed to malloc mcast expect_code");
snprintf(expect_code, expect_code_len + 1, "%s%s-", expect, opt_api_mcast_code);
count = 0;
while (42) {
sleep(1);
count++;
came_from_siz = sizeof(came_from);
if (SOCKETFAIL(rep = recvfrom(mcast_sock, buf, sizeof(buf) - 1,
0, (struct sockaddr *)(&came_from), &came_from_siz))) {
applog(LOG_DEBUG, "API mcast failed count=%d (%s) (%d)",
count, strerror(errno), (int)mcast_sock);
continue;
}
addrok = check_connect(&came_from, &connectaddr, &group);
applog(LOG_DEBUG, "API mcast from %s - %s",
connectaddr, addrok ? "Accepted" : "Ignored");
if (!addrok) {
continue;
}
buf[rep] = '\0';
if (rep > 0 && buf[rep - 1] == '\n')
buf[--rep] = '\0';
applog(LOG_DEBUG, "API mcast request rep=%d (%s) from %s:%d",
(int)rep, buf,
inet_ntoa(came_from.sin_addr),
ntohs(came_from.sin_port));
if ((size_t)rep > expect_code_len && memcmp(buf, expect_code, expect_code_len) == 0) {
reply_port = atoi(&buf[expect_code_len]);
if (reply_port < 1 || reply_port > 65535) {
applog(LOG_DEBUG, "API mcast request ignored - invalid port (%s)",
&buf[expect_code_len]);
}
else {
applog(LOG_DEBUG, "API mcast request OK port %s=%d",
&buf[expect_code_len], reply_port);
came_from.sin_port = htons(reply_port);
reply_sock = socket(AF_INET, SOCK_DGRAM, 0);
snprintf(replybuf, sizeof(replybuf),
"ccm-%s-%d-%s", opt_api_mcast_code, opt_api_port, opt_api_mcast_des);
rep = sendto(reply_sock, replybuf, (int) strlen(replybuf) + 1,
0, (struct sockaddr *)(&came_from), (int) sizeof(came_from));
if (SOCKETFAIL(rep)) {
applog(LOG_DEBUG, "API mcast send reply failed (%s) (%d)",
strerror(errno), (int)reply_sock);
} else {
applog(LOG_DEBUG, "API mcast send reply (%s) succeeded (%d) (%d)",
replybuf, (int)rep, (int)reply_sock);
}
CLOSESOCKET(reply_sock);
}
}
else
applog(LOG_DEBUG, "API mcast request was no good");
}
die:
CLOSESOCKET(mcast_sock);
}
static void *mcast_thread(void *userdata)
{
struct thr_info *mythr = (struct thr_info *)userdata;
pthread_detach(pthread_self());
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
mcast();
//PTH(mythr) = 0L;
return NULL;
}
void mcast_init()
{
struct thr_info *thr;
thr = (struct thr_info *)calloc(1, sizeof(*thr));
if (!thr)
proper_exit(1); //, "Failed to calloc mcast thr");
if (unlikely(pthread_create(&thr->pth, NULL, mcast_thread, thr)))
proper_exit(1); //, "API mcast thread create failed");
}
static void api()
{
const char *addr = opt_api_allow;
unsigned short port = (unsigned short) opt_api_listen; // 4068
const char *addr = opt_api_bind;
unsigned short port = (unsigned short) opt_api_port; // 4068
char buf[MYBUFSIZ];
int n, bound;
char *connectaddr;
@@ -782,11 +1120,13 @@ static void api()
SOCKETTYPE c;
SOCKETTYPE *apisock;
if (!opt_api_listen && opt_debug) {
if (!opt_api_port && opt_debug) {
applog(LOG_DEBUG, "API disabled");
return;
}
setup_groups();
if (opt_api_allow) {
setup_ipaccess();
if (ips == 0) {
@@ -807,9 +1147,10 @@ static void api()
memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr(addr);
serv.sin_addr.s_addr = inet_addr(addr); // TODO: allow bind to ip/interface
if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) {
applog(LOG_ERR, "API initialisation 2 failed (%s)%s", strerror(errno), UNAVAILABLE);
// free(apisock); FIXME!!
return;
}
@@ -837,7 +1178,7 @@ static void api()
binderror = strerror(errno);
if ((time(NULL) - bindstart) > 61)
break;
else if (opt_api_listen == 4068) {
else if (opt_api_port == 4068) {
/* when port is default one, use first available */
if (opt_debug)
applog(LOG_DEBUG, "API bind to port %d failed, trying port %u",
@@ -854,10 +1195,10 @@ static void api()
}
else {
bound = 1;
if (opt_api_listen != port) {
if (opt_api_port != port) {
applog(LOG_WARNING, "API bind to port %d failed - using port %u",
opt_api_listen, (uint32_t) port);
opt_api_listen = port;
opt_api_port, (uint32_t)port);
opt_api_port = port;
}
}
}
@@ -875,10 +1216,20 @@ static void api()
return;
}
if (opt_api_allow && strcmp(opt_api_bind, "127.0.0.1") == 0)
applog(LOG_WARNING, "API open locally in full access mode on port %d", opt_api_port);
else if (opt_api_allow)
applog(LOG_WARNING, "API open in full access mode to %s on port %d", opt_api_allow, opt_api_port);
else if (strcmp(opt_api_bind, "127.0.0.1") != 0)
applog(LOG_INFO, "API open to the network in read-only mode on port %d", opt_api_port);
if (opt_api_mcast)
mcast_init();
buffer = (char *) calloc(1, MYBUFSIZ + 1);
counter = 0;
while (bye == 0) {
while (bye == 0 && !abort_flag) {
counter++;
clisiz = sizeof(cli);
@@ -901,7 +1252,7 @@ static void api()
char *wskey = NULL;
n = recv(c, &buf[0], SOCK_REC_BUFSZ, 0);
fail = SOCKETFAIL(n);
fail = SOCKETFAIL(n) || n < 0;
if (fail)
buf[0] = '\0';
else if (n > 0 && buf[n-1] == '\n') {
@@ -910,7 +1261,7 @@ static void api()
if (n > 0 && buf[n-1] == '\r')
buf[n-1] = '\0';
}
buf[n] = '\0';
else buf[n] = '\0';
//if (opt_debug && opt_protocol && n > 0)
// applog(LOG_DEBUG, "API: recv command: (%d) '%s'+char(%x)", n, buf, buf[n-1]);
@@ -961,8 +1312,8 @@ static void api()
break;
}
}
CLOSESOCKET(c);
}
CLOSESOCKET(c);
}
}
@@ -991,17 +1342,12 @@ void *api_thread(void *userdata)
/* to be able to report the default value set in each algo */
void api_set_throughput(int thr_id, uint32_t throughput)
{
if (&thr_info[thr_id]) {
if (thr_id < MAX_GPUS && thr_info) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
uint32_t ws = throughput;
uint8_t i = 0;
cgpu->throughput = throughput;
while (ws > 1 && i++ < 32)
ws = ws >> 1;
cgpu->intensity_int = i;
cgpu->intensity = (float) i;
if (i && (1U << i) < throughput) {
cgpu->intensity += ((float) (throughput-(1U << i)) / (1U << i));
}
cgpu->intensity = throughput2intensity(throughput);
if (cgpu->throughput != throughput) cgpu->throughput = throughput;
}
// to display in bench results
if (opt_benchmark)
bench_set_throughput(thr_id, throughput);
}
+23 -6
View File
@@ -1,5 +1,5 @@
<?php
/* ccminer API sample UI (API 1.5) */
/* ccminer API sample UI (API 1.9) */
$host = 'http://localhost/api/'; // 'http://'.$_SERVER['SERVER_NAME'].'/api/';
$configs = array(
@@ -28,7 +28,7 @@ function ignoreField($key)
{
$ignored = array(
'API','VER','GPU','BUS','POOLS',
'CARD','GPUS','CPU','TS',
'CARD','GPUS','CPU','TS','URL',
);
return in_array($key, $ignored);
}
@@ -46,6 +46,10 @@ function translateField($key)
$intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn';
$intl['REJ'] = 'Rejected';
$intl['SOLV'] = 'Solved';
$intl['BEST'] = 'Best share';
$intl['STALE'] = 'Stale shares';
$intl['LAST'] = 'Last share';
$intl['DIFF'] = 'Difficulty';
$intl['NETKHS'] = 'Net Rate';
$intl['UPTIME'] = 'Miner up time';
@@ -53,16 +57,22 @@ function translateField($key)
$intl['THR'] = 'Throughput';
$intl['WAIT'] = 'Wait time';
$intl['H'] = 'Bloc height';
$intl['I'] = 'Intensity';
$intl['HWF'] = 'Failures';
$intl['POOL'] = 'Pool';
$intl['POOLS'] = 'Pools';
$intl['TEMP'] = 'T°c';
$intl['FAN'] = 'Fan %';
$intl['FREQ'] = 'Freq.';
$intl['CPUFREQ'] = 'CPU Freq.';
$intl['FREQ'] = 'Base Freq.';
$intl['MEMFREQ'] = 'Mem. Freq.';
$intl['GPUF'] = 'Curr Freq.';
$intl['MEMF'] = 'Mem. Freq.';
$intl['KHW'] = 'Efficiency';
$intl['POWER'] = 'Power';
$intl['PLIM'] = 'P.Limit';
$intl['PST'] = 'P-State';
// pool infos
@@ -94,8 +104,12 @@ function translateValue($key,$val,$data=array())
case 'NAME':
$val = $data['NAME'].'&nbsp;'.$data['VER'];
break;
case 'CPUFREQ':
case 'FREQ':
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
case 'MEMFREQ':
case 'GPUF':
case 'MEMF':
$val = sprintf("%d MHz", $val);
break;
case 'POWER':
$val = sprintf("%d W", round(floatval($val)/1000.0));
@@ -107,6 +121,9 @@ function translateValue($key,$val,$data=array())
case 'NETKHS':
$val = '<span class="bold">'.$val.'</span> kH/s';
break;
case 'KHW':
$val = $val.' kH/W';
break;
case 'NAME':
case 'POOL';
case 'USER':
@@ -231,7 +248,7 @@ div#footer {
#header h1 { padding: 12px; font-size: 20px; }
#footer p { margin: 12px 24px; }
table.stats { width: 280px; margin: 4px 16px; display: inline-block; }
table.stats { width: 280px; margin: 4px 16px; display: inline-block; vertical-align: top; }
th.machine { color: darkcyan; padding: 16px 0px 0px 0px; text-align: left; border-bottom: 1px solid gray; }
th.gpu { color: white; padding: 3px 3px; font: bolder; text-align: left; background: rgba(65, 65, 65, 0.85); }
td.key { width: 99px; max-width: 180px; }
Executable
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/perl
# sample script to query ccminer API
my $command = "summary|";
use Socket;
use IO::Socket::INET;
my $sock = new IO::Socket::INET (
PeerAddr => '127.0.0.1',
PeerPort => 4068,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 10,
);
if ($sock) {
print $sock $command;
my $res = "";
while(<$sock>) {
$res .= $_;
}
close($sock);
print("$res\n");
} else {
print("ccminer socket failed\n");
}
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
+265
View File
@@ -0,0 +1,265 @@
/**
* Made to benchmark and test algo switch
*
* 2015 - tpruvot@github
*/
#include <unistd.h>
#include "miner.h"
#include "algos.h"
#include <cuda_runtime.h>
#ifdef __APPLE__
#include "compat/pthreads/pthread_barrier.hpp"
#endif
int bench_algo = -1;
static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 };
static uint32_t algo_throughput[MAX_GPUS][ALGO_COUNT] = { 0 };
static int algo_mem_used[MAX_GPUS][ALGO_COUNT] = { 0 };
static int device_mem_free[MAX_GPUS] = { 0 };
static pthread_barrier_t miner_barr;
static pthread_barrier_t algo_barr;
static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
extern double thr_hashrates[MAX_GPUS];
void bench_init(int threads)
{
bench_algo = opt_algo = (enum sha_algos) 0; /* first */
applog(LOG_BLUE, "Starting benchmark mode with %s", algo_names[opt_algo]);
pthread_barrier_init(&miner_barr, NULL, threads);
pthread_barrier_init(&algo_barr, NULL, threads);
// required for usage of first algo.
for (int n=0; n < opt_n_threads; n++) {
device_mem_free[n] = cuda_available_memory(n);
}
}
void bench_free()
{
pthread_barrier_destroy(&miner_barr);
pthread_barrier_destroy(&algo_barr);
}
// required to switch algos
void algo_free_all(int thr_id)
{
// only initialized algos will be freed
free_allium(thr_id);
free_bastion(thr_id);
free_bitcore(thr_id);
free_blake256(thr_id);
free_blake2b(thr_id);
free_blake2s(thr_id);
free_bmw(thr_id);
free_c11(thr_id);
free_cryptolight(thr_id);
free_cryptonight(thr_id);
free_decred(thr_id);
free_deep(thr_id);
free_equihash(thr_id);
free_exosis(thr_id);
free_keccak256(thr_id);
free_fresh(thr_id);
free_fugue256(thr_id);
free_groestlcoin(thr_id);
#ifdef WITH_HEAVY_ALGO
free_heavy(thr_id);
#endif
free_hmq17(thr_id);
free_hsr(thr_id);
free_jackpot(thr_id);
free_jha(thr_id);
free_lbry(thr_id);
free_luffa(thr_id);
free_lyra2(thr_id);
free_lyra2v2(thr_id);
free_lyra2v3(thr_id);
free_lyra2Z(thr_id);
free_myriad(thr_id);
free_neoscrypt(thr_id);
free_nist5(thr_id);
free_pentablake(thr_id);
free_phi(thr_id);
free_phi2(thr_id);
free_polytimos(thr_id);
free_quark(thr_id);
free_qubit(thr_id);
free_skeincoin(thr_id);
free_skein2(thr_id);
free_skunk(thr_id);
free_sha256d(thr_id);
free_sha256t(thr_id);
free_sha256q(thr_id);
free_sia(thr_id);
free_sib(thr_id);
free_sonoa(thr_id);
free_s3(thr_id);
free_vanilla(thr_id);
free_veltor(thr_id);
free_whirl(thr_id);
//free_whirlx(thr_id);
free_wildkeccak(thr_id);
free_x11evo(thr_id);
free_x11(thr_id);
free_x12(thr_id);
free_x13(thr_id);
free_x14(thr_id);
free_x15(thr_id);
free_x16r(thr_id);
free_x16s(thr_id);
free_x17(thr_id);
free_zr5(thr_id);
free_scrypt(thr_id);
free_scrypt_jane(thr_id);
free_timetravel(thr_id);
free_tribus(thr_id);
free_bitcore(thr_id);
}
// benchmark all algos (called once per mining thread)
bool bench_algo_switch_next(int thr_id)
{
int algo = (int) opt_algo;
int prev_algo = algo;
int dev_id = device_map[thr_id % MAX_GPUS];
int mfree, mused;
// doesnt seems enough to prevent device slow down
// after some algo switchs
bool need_reset = (gpu_threads == 1);
algo++;
// skip some duplicated algos
if (algo == ALGO_C11) algo++; // same as x11
if (algo == ALGO_DMD_GR) algo++; // same as groestl
if (algo == ALGO_HEAVY) algo++; // dead
if (algo == ALGO_MJOLLNIR) algo++; // same as heavy
if (algo == ALGO_KECCAKC) algo++; // same as keccak
if (algo == ALGO_WHIRLCOIN) algo++; // same as whirlpool
if (algo == ALGO_WHIRLPOOLX) algo++; // disabled
// todo: algo switch from RPC 2.0
if (algo == ALGO_CRYPTOLIGHT) algo++;
if (algo == ALGO_CRYPTONIGHT) algo++;
if (algo == ALGO_WILDKECCAK) algo++;
if (algo == ALGO_QUARK) algo++; // to fix
if (algo == ALGO_LBRY && CUDART_VERSION < 7000) algo++;
if (device_sm[dev_id] && device_sm[dev_id] < 300) {
// incompatible SM 2.1 kernels...
if (algo == ALGO_GROESTL) algo++;
if (algo == ALGO_MYR_GR) algo++;
if (algo == ALGO_NEOSCRYPT) algo++;
if (algo == ALGO_WHIRLPOOLX) algo++;
}
// and unwanted ones...
if (algo == ALGO_SCRYPT) algo++;
if (algo == ALGO_SCRYPT_JANE) algo++;
// Set cryptonight variant
switch (algo) {
case ALGO_MONERO:
cryptonight_fork = 7;
break;
case ALGO_GRAFT:
cryptonight_fork = 8;
break;
case ALGO_STELLITE:
cryptonight_fork = 3;
break;
case ALGO_CRYPTONIGHT:
cryptonight_fork = 1;
break;
}
// free current algo memory and track mem usage
mused = cuda_available_memory(thr_id);
algo_free_all(thr_id);
CUDA_LOG_ERROR();
// device can take some time to free
mfree = cuda_available_memory(thr_id);
if (device_mem_free[thr_id] > mfree) {
sleep(1);
mfree = cuda_available_memory(thr_id);
}
// we need to wait completion on all cards before the switch
if (opt_n_threads > 1) {
pthread_barrier_wait(&miner_barr);
}
char rate[32] = { 0 };
double hashrate = stats_get_speed(thr_id, thr_hashrates[thr_id]);
format_hashrate(hashrate, rate);
gpulog(LOG_NOTICE, thr_id, "%s hashrate = %s", algo_names[prev_algo], rate);
// ensure memory leak is still real after the barrier
if (device_mem_free[thr_id] > mfree) {
mfree = cuda_available_memory(thr_id);
}
// check if there is memory leak
if (device_mem_free[thr_id] - mfree > 1) {
gpulog(LOG_WARNING, thr_id, "possible %d MB memory leak in %s! %d MB free",
(device_mem_free[thr_id] - mfree), algo_names[prev_algo], mfree);
cuda_reset_device(thr_id, NULL); // force to free the leak
need_reset = false;
mfree = cuda_available_memory(thr_id);
}
// store used memory per algo
algo_mem_used[thr_id][opt_algo] = device_mem_free[thr_id] - mused;
device_mem_free[thr_id] = mfree;
// store to dump a table per gpu later
algo_hashrates[thr_id][prev_algo] = hashrate;
// wait the other threads to display logs correctly
if (opt_n_threads > 1) {
pthread_barrier_wait(&algo_barr);
}
if (algo == ALGO_AUTO)
return false; // all algos done
// mutex primary used for the stats purge
pthread_mutex_lock(&bench_lock);
stats_purge_all();
opt_algo = (enum sha_algos) algo;
global_hashrate = 0;
thr_hashrates[thr_id] = 0; // reset for minmax64
pthread_mutex_unlock(&bench_lock);
if (need_reset)
cuda_reset_device(thr_id, NULL);
if (thr_id == 0)
applog(LOG_BLUE, "Benchmark algo %s...", algo_names[algo]);
return true;
}
void bench_set_throughput(int thr_id, uint32_t throughput)
{
algo_throughput[thr_id][opt_algo] = throughput;
}
void bench_display_results()
{
for (int n=0; n < opt_n_threads; n++)
{
int dev_id = device_map[n];
applog(LOG_BLUE, "Benchmark results for GPU #%d - %s:", dev_id, device_name[dev_id]);
for (int i=0; i < ALGO_COUNT-1; i++) {
double rate = algo_hashrates[n][i];
if (rate == 0.0) continue;
applog(LOG_INFO, "%12s : %12.1f kH/s, %5d MB, %8u thr.", algo_names[i],
rate / 1024., algo_mem_used[n][i], algo_throughput[n][i]);
}
}
}
+74
View File
@@ -5,7 +5,13 @@
#include <stdio.h>
#include "uint256.h"
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include "compat/bignum_ssl10.hpp"
#else
#include "bignum.hpp"
#endif
#include "miner.h" // hex2bin
@@ -24,3 +30,71 @@ extern "C" void bn_nbits_to_uchar(const uint32_t nBits, unsigned char *target)
snprintf(buff, 65, "%s\n", bn.ToString().c_str()); buff[64] = '\0';
hex2bin(target, buff, 32);
}
// unused, but should allow more than 256bits targets
#if 0
extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target)
{
double dhash;
if (!opt_showdiff)
return 0.0;
CBigNum h(0), t(0);
std::vector<unsigned char> vch(32);
memcpy(&vch[0], (void*) target, 32);
t.setvch(vch);
memcpy(&vch[0], (void*) hash, 32);
h.setvch(vch);
dhash = h.getuint256().getdouble();
if (dhash > 0.)
return t.getuint256().getdouble() / dhash;
else
return dhash;
}
#endif
// compute the diff ratio between a found hash and the target
extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target)
{
uint256 h, t;
double dhash;
if (!opt_showdiff)
return 0.0;
memcpy(&t, (void*) target, 32);
memcpy(&h, (void*) hash, 32);
dhash = h.getdouble();
if (dhash > 0.)
return t.getdouble() / dhash;
else
return dhash;
}
// store ratio in work struct
extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work, int nonce)
{
// only if the option is enabled (to reduce cpu usage)
if (!opt_showdiff) return;
if (nonce < 0 || nonce >= MAX_NONCES) return;
work->shareratio[nonce] = bn_hash_target_ratio(hash, target);
work->sharediff[nonce] = work->targetdiff * work->shareratio[nonce];
}
// new method to save all nonce(s) share diff/ration
extern "C" void bn_set_target_ratio(struct work* work, uint32_t* hash, int nonce)
{
bn_store_hash_target_ratio(hash, work->target, work, nonce);
}
// compat (only store single nonce share diff per work)
extern "C" void work_set_target_ratio(struct work* work, uint32_t* hash)
{
bn_store_hash_target_ratio(hash, work->target, work, work->submit_nonce_id);
}
+105 -123
View File
@@ -9,20 +9,13 @@
#define PROTOCOL_VERSION 70001
#endif
#include <map>
#include <limits>
#include <algorithm>
#include <stdexcept>
#include <vector>
#include "uint256.h"
#include <openssl/bn.h>
#include "serialize.hpp"
using namespace std;
/** Errors thrown by the bignum class */
class bignum_error : public std::runtime_error
{
@@ -60,75 +53,90 @@ public:
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
class CBigNum : public BIGNUM
class CBigNum
{
private:
BIGNUM *self = NULL;
void init()
{
if (self)
BN_clear_free(self);
self = BN_new();
if (!self)
throw bignum_error("CBigNum::init(): BN_new() returned NULL");
}
public:
BIGNUM *get() { return self; }
const BIGNUM *getc() const { return self; }
CBigNum()
{
BN_init(this);
init();
}
CBigNum(const CBigNum& b)
{
BN_init(this);
if (!BN_copy(this, &b))
init();
if (!BN_copy(self, b.getc()))
{
BN_clear_free(this);
BN_clear_free(self);
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
}
}
CBigNum& operator=(const CBigNum& b)
{
if (!BN_copy(this, &b))
if (!BN_copy(self, b.getc()))
throw bignum_error("CBigNum::operator= : BN_copy failed");
return (*this);
}
~CBigNum()
{
BN_clear_free(this);
BN_clear_free(self);
}
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int64 n) { BN_init(this); setint64(n); }
CBigNum(unsigned char n) { BN_init(this); setulong(n); }
CBigNum(unsigned short n) { BN_init(this); setulong(n); }
CBigNum(unsigned int n) { BN_init(this); setulong(n); }
CBigNum(unsigned long n) { BN_init(this); setulong(n); }
CBigNum(uint64 n) { BN_init(this); setuint64(n); }
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
CBigNum(signed char n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(long n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int64 n) { init(); setint64(n); }
CBigNum(unsigned char n) { init(); setulong(n); }
CBigNum(unsigned short n) { init(); setulong(n); }
CBigNum(unsigned int n) { init(); setulong(n); }
CBigNum(unsigned long n) { init(); setulong(n); }
CBigNum(uint64 n) { init(); setuint64(n); }
explicit CBigNum(uint256 n) { init(); setuint256(n); }
explicit CBigNum(const std::vector<unsigned char>& vch)
{
BN_init(this);
init();
setvch(vch);
}
void setulong(unsigned long n)
{
if (!BN_set_word(this, n))
if (!BN_set_word(self, n))
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
}
unsigned long getulong() const
{
return BN_get_word(this);
return BN_get_word(self);
}
unsigned int getuint() const
{
return BN_get_word(this);
return BN_get_word(self);
}
int getint() const
{
unsigned long n = BN_get_word(this);
if (!BN_is_negative(this))
unsigned long n = BN_get_word(self);
if (!BN_is_negative(self))
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
else
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
@@ -143,9 +151,7 @@ public:
if (sn < (int64)0)
{
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
// and it's not well-defined what happens if you make it unsigned before negating it,
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
// Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
n = -(sn + 1);
++n;
fNegative = true;
@@ -176,7 +182,22 @@ public:
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, p - pch, this);
BN_mpi2bn(pch, p - pch, self);
}
uint64 getuint64()
{
unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(self, &vch[0]);
if (vch.size() > 4)
vch[4] &= 0x7f;
uint64 n = 0;
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
((unsigned char*)&n)[i] = vch[j];
return n;
}
void setuint64(uint64 n)
@@ -203,7 +224,7 @@ public:
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, p - pch, this);
BN_mpi2bn(pch, p - pch, self);
}
void setuint256(uint256 n)
@@ -231,16 +252,16 @@ public:
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize >> 0) & 0xff;
BN_mpi2bn(pch, p - pch, this);
BN_mpi2bn(pch, p - pch, self);
}
uint256 getuint256() const
uint256 getuint256()
{
unsigned int nSize = BN_bn2mpi(this, NULL);
unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
BN_bn2mpi(self, &vch[0]);
if (vch.size() > 4)
vch[4] &= 0x7f;
uint256 n = 0;
@@ -249,6 +270,7 @@ public:
return n;
}
void setvch(const std::vector<unsigned char>& vch)
{
std::vector<unsigned char> vch2(vch.size() + 4);
@@ -261,83 +283,43 @@ public:
vch2[3] = (nSize >> 0) & 0xff;
// swap data to big endian
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
BN_mpi2bn(&vch2[0], vch2.size(), this);
BN_mpi2bn(&vch2[0], vch2.size(), self);
}
std::vector<unsigned char> getvch() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize <= 4)
return std::vector<unsigned char>();
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
BN_bn2mpi(self, &vch[0]);
vch.erase(vch.begin(), vch.begin() + 4);
reverse(vch.begin(), vch.end());
return vch;
}
// The "compact" format is a representation of a whole
// number N using an unsigned 32bit number similar to a
// floating point format.
// The most significant 8 bits are the unsigned exponent of base 256.
// This exponent can be thought of as "number of bytes of N".
// The lower 23 bits are the mantissa.
// Bit number 24 (0x800000) represents the sign of N.
// N = (-1^sign) * mantissa * 256^(exponent-3)
//
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
// MPI uses the most significant bit of the first byte as sign.
// Thus 0x1234560000 is compact (0x05123456)
// and 0xc0de000000 is compact (0x0600c0de)
// (0x05c0de00) would be -0x40de000000
//
// Bitcoin only uses this "compact" format for encoding difficulty
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
//
// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
CBigNum& SetCompact(unsigned int nCompact)
{
unsigned int nSize = nCompact >> 24;
bool fNegative =(nCompact & 0x00800000) != 0;
unsigned int nWord = nCompact & 0x007fffff;
if (nSize <= 3)
{
nWord >>= 8*(3-nSize);
BN_set_word(this, nWord);
}
else
{
BN_set_word(this, nWord);
BN_lshift(this, this, 8*(nSize-3));
}
BN_set_negative(this, fNegative);
std::vector<unsigned char> vch(4 + nSize);
vch[3] = nSize;
if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
BN_mpi2bn(&vch[0], vch.size(), self);
return *this;
}
unsigned int GetCompact() const
{
unsigned int nSize = BN_num_bytes(this);
unsigned int nCompact = 0;
if (nSize <= 3)
nCompact = BN_get_word(this) << 8*(3-nSize);
else
{
CBigNum bn;
BN_rshift(&bn, this, 8*(nSize-3));
nCompact = BN_get_word(&bn);
}
// The 0x00800000 bit denotes the sign.
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
if (nCompact & 0x00800000)
{
nCompact >>= 8;
nSize++;
}
nCompact |= nSize << 24;
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
unsigned int nSize = BN_bn2mpi(self, NULL);
std::vector<unsigned char> vch(nSize);
nSize -= 4;
BN_bn2mpi(self, &vch[0]);
unsigned int nCompact = nSize << 24;
if (nSize >= 1) nCompact |= (vch[4] << 16);
if (nSize >= 2) nCompact |= (vch[5] << 8);
if (nSize >= 3) nCompact |= (vch[6] << 0);
return nCompact;
}
@@ -378,20 +360,20 @@ public:
CBigNum bn0 = 0;
std::string str;
CBigNum bn = *this;
BN_set_negative(&bn, false);
BN_set_negative(bn.get(), false);
CBigNum dv;
CBigNum rem;
if (BN_cmp(&bn, &bn0) == 0)
if (BN_cmp(bn.getc(), bn0.getc()) == 0)
return "0";
while (BN_cmp(&bn, &bn0) > 0)
while (BN_cmp(bn.getc(), bn0.getc()) > 0)
{
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
if (!BN_div(dv.get(), rem.get(), bn.getc(), bnBase.getc(), pctx))
throw bignum_error("CBigNum::ToString() : BN_div failed");
bn = dv;
unsigned int c = rem.getulong();
str += "0123456789abcdef"[c];
}
if (BN_is_negative(this))
if (BN_is_negative(self))
str += "-";
reverse(str.begin(), str.end());
return str;
@@ -424,12 +406,12 @@ public:
bool operator!() const
{
return BN_is_zero(this);
return BN_is_zero(self);
}
CBigNum& operator+=(const CBigNum& b)
{
if (!BN_add(this, this, &b))
if (!BN_add(self, self, b.getc()))
throw bignum_error("CBigNum::operator+= : BN_add failed");
return *this;
}
@@ -443,7 +425,7 @@ public:
CBigNum& operator*=(const CBigNum& b)
{
CAutoBN_CTX pctx;
if (!BN_mul(this, this, &b, pctx))
if (!BN_mul(self, self, b.getc(), pctx))
throw bignum_error("CBigNum::operator*= : BN_mul failed");
return *this;
}
@@ -462,7 +444,7 @@ public:
CBigNum& operator<<=(unsigned int shift)
{
if (!BN_lshift(this, this, shift))
if (!BN_lshift(self, self, shift))
throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
return *this;
}
@@ -473,13 +455,13 @@ public:
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
CBigNum a = 1;
a <<= shift;
if (BN_cmp(&a, this) > 0)
if (BN_cmp(a.getc(), self) > 0)
{
*this = 0;
return *this;
}
if (!BN_rshift(this, this, shift))
if (!BN_rshift(self, self, shift))
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
return *this;
}
@@ -488,7 +470,7 @@ public:
CBigNum& operator++()
{
// prefix operator
if (!BN_add(this, this, BN_value_one()))
if (!BN_add(self, self, BN_value_one()))
throw bignum_error("CBigNum::operator++ : BN_add failed");
return *this;
}
@@ -505,7 +487,7 @@ public:
{
// prefix operator
CBigNum r;
if (!BN_sub(&r, this, BN_value_one()))
if (!BN_sub(r.get(), self, BN_value_one()))
throw bignum_error("CBigNum::operator-- : BN_sub failed");
*this = r;
return *this;
@@ -530,7 +512,7 @@ public:
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_add(&r, &a, &b))
if (!BN_add(r.get(), a.getc(), b.getc()))
throw bignum_error("CBigNum::operator+ : BN_add failed");
return r;
}
@@ -538,7 +520,7 @@ inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_sub(&r, &a, &b))
if (!BN_sub(r.get(), a.getc(), b.getc()))
throw bignum_error("CBigNum::operator- : BN_sub failed");
return r;
}
@@ -546,7 +528,7 @@ inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator-(const CBigNum& a)
{
CBigNum r(a);
BN_set_negative(&r, !BN_is_negative(&r));
BN_set_negative(r.get(), !BN_is_negative(r.getc()));
return r;
}
@@ -554,7 +536,7 @@ inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mul(&r, &a, &b, pctx))
if (!BN_mul(r.get(), a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator* : BN_mul failed");
return r;
}
@@ -563,7 +545,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_div(&r, NULL, &a, &b, pctx))
if (!BN_div(r.get(), NULL, a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator/ : BN_div failed");
return r;
}
@@ -572,7 +554,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mod(&r, &a, &b, pctx))
if (!BN_mod(r.get(), a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator% : BN_div failed");
return r;
}
@@ -580,7 +562,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
{
CBigNum r;
if (!BN_lshift(&r, &a, shift))
if (!BN_lshift(r.get(), a.getc(), shift))
throw bignum_error("CBigNum:operator<< : BN_lshift failed");
return r;
}
@@ -592,11 +574,11 @@ inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
return r;
}
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) == 0); }
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) != 0); }
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) <= 0); }
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) > 0); }
#endif
+273
View File
@@ -0,0 +1,273 @@
/**
* Blake2-B CUDA Implementation
*
* tpruvot@github July 2016
*
*/
#include <miner.h>
#include <string.h>
#include <stdint.h>
#include <sph/blake2b.h>
#include <cuda_helper.h>
#include <cuda_vector_uint2x4.h>
#define TPB 512
#define NBN 2
static uint32_t *d_resNonces[MAX_GPUS];
__device__ uint64_t d_data[10];
static __constant__ const int8_t blake2b_sigma[12][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 } ,
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
};
// host mem align
#define A 64
extern "C" void blake2b_hash(void *output, const void *input)
{
uint8_t _ALIGN(A) hash[32];
blake2b_ctx ctx;
blake2b_init(&ctx, 32, NULL, 0);
blake2b_update(&ctx, input, 80);
blake2b_final(&ctx, hash);
memcpy(output, hash, 32);
}
// ----------------------------------------------------------------
__device__ __forceinline__
static void G(const int r, const int i, uint64_t &a, uint64_t &b, uint64_t &c, uint64_t &d, uint64_t const m[16])
{
a = a + b + m[ blake2b_sigma[r][2*i] ];
((uint2*)&d)[0] = SWAPUINT2( ((uint2*)&d)[0] ^ ((uint2*)&a)[0] );
c = c + d;
((uint2*)&b)[0] = ROR24( ((uint2*)&b)[0] ^ ((uint2*)&c)[0] );
a = a + b + m[ blake2b_sigma[r][2*i+1] ];
((uint2*)&d)[0] = ROR16( ((uint2*)&d)[0] ^ ((uint2*)&a)[0] );
c = c + d;
((uint2*)&b)[0] = ROR2( ((uint2*)&b)[0] ^ ((uint2*)&c)[0], 63U);
}
#define ROUND(r) \
G(r, 0, v[0], v[4], v[ 8], v[12], m); \
G(r, 1, v[1], v[5], v[ 9], v[13], m); \
G(r, 2, v[2], v[6], v[10], v[14], m); \
G(r, 3, v[3], v[7], v[11], v[15], m); \
G(r, 4, v[0], v[5], v[10], v[15], m); \
G(r, 5, v[1], v[6], v[11], v[12], m); \
G(r, 6, v[2], v[7], v[ 8], v[13], m); \
G(r, 7, v[3], v[4], v[ 9], v[14], m);
__global__
//__launch_bounds__(128, 8) /* to force 64 regs */
void blake2b_gpu_hash(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce, const uint2 target2)
{
const uint32_t nonce = (blockDim.x * blockIdx.x + threadIdx.x) + startNonce;
uint64_t m[16];
m[0] = d_data[0];
m[1] = d_data[1];
m[2] = d_data[2];
m[3] = d_data[3];
m[4] = d_data[4];
m[5] = d_data[5];
m[6] = d_data[6];
m[7] = d_data[7];
m[8] = d_data[8];
((uint32_t*)m)[18] = AS_U32(&d_data[9]);
((uint32_t*)m)[19] = nonce;
m[10] = m[11] = 0;
m[12] = m[13] = 0;
m[14] = m[15] = 0;
uint64_t v[16] = {
0x6a09e667f2bdc928, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
0x510e527fade68281, 0x9b05688c2b3e6c1f, 0xe07c265404be4294, 0x5be0cd19137e2179
};
ROUND( 0);
ROUND( 1);
ROUND( 2);
ROUND( 3);
ROUND( 4);
ROUND( 5);
ROUND( 6);
ROUND( 7);
ROUND( 8);
ROUND( 9);
ROUND(10);
ROUND(11);
uint2 last = vectorize(v[3] ^ v[11] ^ 0xa54ff53a5f1d36f1);
if (last.y <= target2.y && last.x <= target2.x) {
resNonce[1] = resNonce[0];
resNonce[0] = nonce;
}
}
__host__
uint32_t blake2b_hash_cuda(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint2 target2, uint32_t &secNonce)
{
uint32_t resNonces[NBN] = { UINT32_MAX, UINT32_MAX };
uint32_t result = UINT32_MAX;
dim3 grid((threads + TPB-1)/TPB);
dim3 block(TPB);
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
if (cudaMemset(d_resNonces[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
return result;
blake2b_gpu_hash <<<grid, block, 8>>> (threads, startNonce, d_resNonces[thr_id], target2);
cudaThreadSynchronize();
if (cudaSuccess == cudaMemcpy(resNonces, d_resNonces[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
result = resNonces[0];
secNonce = resNonces[1];
if (secNonce == result) secNonce = UINT32_MAX;
}
return result;
}
__host__
void blake2b_setBlock(uint32_t *data)
{
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, data, 80, 0, cudaMemcpyHostToDevice));
}
static bool init[MAX_GPUS] = { 0 };
int scanhash_blake2b(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(A) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t first_nonce = pdata[19];
int dev_id = device_map[thr_id];
int intensity = (device_sm[dev_id] >= 500 && !is_windows()) ? 28 : 25;
if (device_sm[dev_id] >= 520 && is_windows()) intensity = 26;
if (device_sm[dev_id] < 350) intensity = 22;
uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity);
if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce);
if (!init[thr_id])
{
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
CUDA_LOG_ERROR();
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonces[thr_id], NBN * sizeof(uint32_t)), -1);
init[thr_id] = true;
}
for (int i=0; i < 20; i++)
be32enc(&endiandata[i], pdata[i]);
const uint2 target = make_uint2(ptarget[6], ptarget[7]);
blake2b_setBlock(endiandata);
do {
work->nonces[0] = blake2b_hash_cuda(thr_id, throughput, pdata[19], target, work->nonces[1]);
*hashes_done = pdata[19] - first_nonce + throughput;
if (work->nonces[0] != UINT32_MAX)
{
const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(A) vhash[8];
work->valid_nonces = 0;
endiandata[19] = work->nonces[0];
blake2b_hash(vhash, endiandata);
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
work_set_target_ratio(work, vhash);
work->valid_nonces++;
pdata[19] = work->nonces[0] + 1;
} else {
gpu_increment_reject(thr_id);
}
if (work->nonces[1] != UINT32_MAX) {
endiandata[19] = work->nonces[1];
blake2b_hash(vhash, endiandata);
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio[0]) {
work->sharediff[1] = work->sharediff[0];
work->shareratio[1] = work->shareratio[0];
xchg(work->nonces[1], work->nonces[0]);
work_set_target_ratio(work, vhash);
} else {
bn_set_target_ratio(work, vhash, 1);
}
work->valid_nonces++;
pdata[19] = max(work->nonces[0], work->nonces[1]) + 1; // next scan start
} else {
gpu_increment_reject(thr_id);
}
}
if (work->valid_nonces) {
work->nonces[0] = cuda_swab32(work->nonces[0]);
work->nonces[1] = cuda_swab32(work->nonces[1]);
return work->valid_nonces;
}
}
if ((uint64_t) throughput + pdata[19] >= max_nonce) {
pdata[19] = max_nonce;
break;
}
pdata[19] += throughput;
} while (!work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce;
return 0;
}
// cleanup
extern "C" void free_blake2b(int thr_id)
{
if (!init[thr_id])
return;
//cudaThreadSynchronize();
cudaFree(d_resNonces[thr_id]);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+6 -5
View File
@@ -2,18 +2,19 @@
"_comment1" : "Possible keys are the long options (ccminer --help)",
"_comment2" : "todo: support /* comments */",
"algo" : "blake",
"intensity": 19,
"algo" : "lbry",
"intensity": 22,
"api-bind": "127.0.0.1:4068",
"statsavg": 20,
"max-log-rate": 60,
"quiet" : false,
"debug" : false,
"protocol" : false,
"cpu-priority" : 3,
"url" : "stratum+tcp://stratum.eu.miners-pool.eu:8421",
"user" : "ShGCAFrspnLDo414EzUyJm4k5Qr2Kkrmvh",
"pass" : "x"
"url" : "stratum+tcp://yiimp.ccminer.org:3334",
"user" : "bK2wcSFJv2nnNjFvTN5Q7VX8X8unJktJsa",
"pass" : "donate"
}
+1952 -595
View File
File diff suppressed because it is too large. Load diff
+190 -70
View File
@@ -23,26 +23,23 @@
<RootNamespace>ccminer</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>false</CLRSupport>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>false</CLRSupport>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.props" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -115,7 +112,7 @@
<MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_50,sm_50</CodeGeneration>
<CodeGeneration>compute_52,sm_52</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
@@ -135,6 +132,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<OpenMPSupport>true</OpenMPSupport>
@@ -157,8 +155,8 @@
<MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30;compute_35,sm_35</CodeGeneration>
<AdditionalOptions>--ptxas-options="-O2" %(AdditionalOptions)</AdditionalOptions>
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30</CodeGeneration>
<AdditionalOptions>--ptxas-options="-O2" --Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
<Optimization>O2</Optimization>
</CudaCompile>
<CudaLink>
@@ -180,6 +178,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<MinimalRebuild>true</MinimalRebuild>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
@@ -199,10 +198,11 @@
<MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_35,sm_35;compute_30,sm_30</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include</Include>
<Optimization>O3</Optimization>
<TargetMachinePlatform>64</TargetMachinePlatform>
<AdditionalOptions>--Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
</CudaCompile>
<CudaLink>
<Optimization>O3</Optimization>
@@ -222,13 +222,31 @@
<ClCompile Include="compat\jansson\strconv.c" />
<ClCompile Include="compat\jansson\utf.c" />
<ClCompile Include="compat\jansson\value.c" />
<ClInclude Include="compat\pthreads\pthread.h" />
<ClCompile Include="compat\winansi.c" />
<ClCompile Include="ccminer.cpp">
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
</ClCompile>
<ClCompile Include="crypto\mman.c" />
<ClCompile Include="crypto\wildkeccak-cpu.cpp" />
<ClCompile Include="crypto\xmr-rpc.cpp" />
<ClCompile Include="crypto\aesb.cpp" />
<ClCompile Include="crypto\oaes_lib.cpp" />
<ClCompile Include="crypto\cryptolight-cpu.cpp" />
<ClCompile Include="crypto\cryptonight-cpu.cpp" />
<ClCompile Include="crypto\cpu\c_keccak.c" />
<ClCompile Include="equi\blake2\blake2bx.cpp">
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">StreamingSIMDExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<ClCompile Include="equi\equi-stratum.cpp" />
<ClCompile Include="equi\equi.cpp" />
<ClCompile Include="equi\equihash.cpp" />
<ClCompile Include="nvapi.cpp" />
<ClCompile Include="nvsettings.cpp" />
<ClCompile Include="pools.cpp" />
<ClCompile Include="util.cpp" />
<ClCompile Include="bench.cpp" />
<ClCompile Include="bignum.cpp" />
<ClInclude Include="bignum.hpp" />
<ClCompile Include="fuguecoin.cpp" />
@@ -243,40 +261,78 @@
<ClCompile Include="myriadgroestl.cpp" />
<ClCompile Include="lyra2\Lyra2.c" />
<ClCompile Include="lyra2\Sponge.c" />
<ClCompile Include="lyra2\Lyra2Z.c" />
<ClInclude Include="equi\eqcuda.hpp" />
<ClInclude Include="equi\equihash.h" />
<ClInclude Include="neoscrypt\neoscrypt.h" />
<ClCompile Include="neoscrypt\neoscrypt.cpp" />
<ClCompile Include="neoscrypt\neoscrypt-cpu.c" />
<ClInclude Include="neoscrypt\cuda_vectors.h" />
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu" />
<ClInclude Include="x11\cuda_x11_simd512_sm2.cuh" />
<ClInclude Include="x16\cuda_x16.h" />
<CudaCompile Include="Algo256\bmw.cu" />
<CudaCompile Include="Algo256\cuda_bmw.cu">
<MaxRegCount>76</MaxRegCount>
</CudaCompile>
<CudaCompile Include="crypto\cryptolight.cu" />
<CudaCompile Include="crypto\cryptolight-core.cu">
<MaxRegCount>64</MaxRegCount>
</CudaCompile>
<CudaCompile Include="crypto\cryptonight.cu" />
<CudaCompile Include="crypto\cryptonight-core.cu">
<MaxRegCount>64</MaxRegCount>
</CudaCompile>
<CudaCompile Include="crypto\cryptonight-extra.cu">
<MaxRegCount>255</MaxRegCount>
</CudaCompile>
<ClInclude Include="crypto\cn_aes.cuh" />
<ClInclude Include="crypto\cn_blake.cuh" />
<ClInclude Include="crypto\cn_groestl.cuh" />
<ClInclude Include="crypto\cn_jh.cuh" />
<ClInclude Include="crypto\cn_keccak.cuh" />
<ClInclude Include="crypto\cn_skein.cuh" />
<CudaCompile Include="crypto\wildkeccak.cu">
<MaxRegCount>128</MaxRegCount>
</CudaCompile>
<CudaCompile Include="equi\cuda_equi.cu">
<CodeGeneration>compute_52,sm_52;compute_50,sm_50;compute_30,sm_30</CodeGeneration>
<AdditionalOptions> -Xptxas -dlcm=ca -Xptxas -dscm=cs %(AdditionalOptions)</AdditionalOptions>
<MaxRegCount>0</MaxRegCount>
<CodeGeneration Condition="'$(Configuration)|$(Platform)'=='Release|x64'">compute_61,sm_61;compute_52,sm_52;compute_50,sm_50;compute_30,sm_30</CodeGeneration>
</CudaCompile>
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
<MaxRegCount>160</MaxRegCount>
</CudaCompile>
<ClCompile Include="scrypt-jane.cpp" />
<ClCompile Include="scrypt.cpp" />
<ClCompile Include="sia\sia-rpc.cpp" />
<ClCompile Include="skein2.cpp" />
<ClCompile Include="sph\aes_helper.c" />
<ClCompile Include="sph\blake.c" />
<ClCompile Include="sph\blake2b.c" />
<ClCompile Include="sph\blake2s.c" />
<ClCompile Include="sph\bmw.c" />
<ClCompile Include="sph\cubehash.c" />
<ClCompile Include="sph\echo.c" />
<ClCompile Include="sph\fugue.c" />
<ClCompile Include="sph\groestl.c" />
<ClCompile Include="sph\haval.c" />
<ClCompile Include="sph\haval_helper.c">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="sph\jh.c" />
<ClCompile Include="sph\keccak.c" />
<ClCompile Include="sph\luffa.c" />
<ClCompile Include="sph\md_helper.c">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="sph\ripemd.c" />
<ClCompile Include="sph\sph_sha2.c" />
<ClCompile Include="sph\sha2.c" />
<ClCompile Include="sph\sha2big.c" />
<ClCompile Include="sph\shabal.c" />
<ClCompile Include="sph\shavite.c" />
<ClCompile Include="sph\simd.c" />
<ClCompile Include="sph\skein.c" />
<ClCompile Include="sph\streebog.c" />
<ClCompile Include="sph\hamsi.c" />
<ClCompile Include="sph\hamsi_helper.c" />
<ClCompile Include="sph\whirlpool.c" />
<ClCompile Include="x13\sm3.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="compat.h" />
@@ -296,17 +352,29 @@
<ClInclude Include="compat\sys\time.h" />
<ClInclude Include="compat\unistd.h" />
<ClInclude Include="compat\winansi.h" />
<ClInclude Include="cpuminer-config.h" />
<ClInclude Include="compat\ccminer-config.h" />
<ClInclude Include="crypto\cryptolight.h" />
<ClInclude Include="crypto\cryptonight.h" />
<ClInclude Include="crypto\mman.h" />
<ClInclude Include="crypto\wildkeccak.h" />
<ClInclude Include="crypto\xmr-rpc.h" />
<ClInclude Include="cuda_groestlcoin.h" />
<ClInclude Include="cuda_helper.h" />
<ClInclude Include="cuda_vector.h" />
<ClInclude Include="cuda_vector_uint2x4.h" />
<ClInclude Include="elist.h" />
<ClInclude Include="heavy\heavy.h" />
<ClInclude Include="hefty1.h" />
<ClInclude Include="algos.h" />
<ClInclude Include="miner.h" />
<ClInclude Include="nvml.h" />
<ClInclude Include="quark\cuda_bmw512_sm3.cuh" />
<ClInclude Include="quark\cuda_quark_groestl512_sm2.cuh" />
<ClInclude Include="quark\cuda_quark_blake512_sp.cuh" />
<ClInclude Include="res\resource.h" />
<ClInclude Include="sia\sia-rpc.h" />
<ClInclude Include="scrypt\salsa_kernel.h" />
<ClInclude Include="sph\blake2b.h" />
<ClInclude Include="sph\blake2s.h" />
<ClInclude Include="sph\sph_blake.h" />
<ClInclude Include="sph\sph_bmw.h" />
<ClInclude Include="sph\sph_cubehash.h" />
@@ -322,29 +390,31 @@
<ClInclude Include="sph\sph_shavite.h" />
<ClInclude Include="sph\sph_simd.h" />
<ClInclude Include="sph\sph_skein.h" />
<ClInclude Include="sph\sph_streebog.h" />
<ClInclude Include="sph\sph_hamsi.h" />
<ClInclude Include="sph\sph_types.h" />
<ClInclude Include="sph\sph_whirlpool.h" />
<ClInclude Include="uint256.h" />
<ClInclude Include="lyra2\Lyra2.h" />
<ClInclude Include="lyra2\Sponge.h" />
<ClInclude Include="lyra2\Lyra2Z.h" />
<ClInclude Include="quark\groestl_transf_quad.h" />
<ClInclude Include="quark\groestl_functions_quad.h" />
<ClInclude Include="quark\cuda_quark.h" />
<ClInclude Include="x11\cuda_x11.h" />
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cpp" />
<CudaCompile Include="cuda_groestlcoin.cu" />
<CudaCompile Include="cuda_myriadgroestl.cu" />
<CudaCompile Include="cuda_nist5.cu">
</CudaCompile>
<CudaCompile Include="scrypt\blake.cu" />
<CudaCompile Include="scrypt\keccak.cu" />
<CudaCompile Include="scrypt\sha256.cu" />
<CudaCompile Include="scrypt\salsa_kernel.cu">
<CodeGeneration>compute_20,sm_21</CodeGeneration>
<CodeGeneration>compute_30,sm_30</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\fermi_kernel.cu">
<CodeGeneration>compute_20,sm_21</CodeGeneration>
<CodeGeneration>compute_30,sm_30</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\kepler_kernel.cu">
<CodeGeneration>compute_30,sm_30</CodeGeneration>
@@ -356,11 +426,17 @@
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\test_kernel.cu">
<CodeGeneration>compute_20,sm_21</CodeGeneration>
<CodeGeneration>compute_30,sm_30</CodeGeneration>
</CudaCompile>
<CudaCompile Include="scrypt\titan_kernel.cu">
<CodeGeneration>compute_35,sm_35;compute_50,sm_50</CodeGeneration>
</CudaCompile>
<CudaCompile Include="sha256\cuda_sha256d.cu" />
<CudaCompile Include="sha256\sha256d.cu" />
<CudaCompile Include="sha256\cuda_sha256t.cu" />
<CudaCompile Include="sha256\sha256t.cu" />
<CudaCompile Include="sha256\cuda_sha256q.cu" />
<CudaCompile Include="sha256\sha256q.cu" />
<CudaCompile Include="zr5.cu" />
<CudaCompile Include="heavy\cuda_blake512.cu">
</CudaCompile>
@@ -377,34 +453,46 @@
</CudaCompile>
<CudaCompile Include="heavy\heavy.cu">
</CudaCompile>
<CudaCompile Include="heavy\bastion.cu" />
<CudaCompile Include="heavy\cuda_bastion.cu" />
<CudaCompile Include="JHA\jha.cu" />
<CudaCompile Include="JHA\jackpotcoin.cu" />
<CudaCompile Include="JHA\cuda_jha_compactionTest.cu">
<AdditionalOptions Condition="'$(Configuration)'=='Release'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)'=='Debug'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
</CudaCompile>
<CudaCompile Include="JHA\cuda_jha_keccak512.cu">
</CudaCompile>
<CudaCompile Include="JHA\jackpotcoin.cu">
</CudaCompile>
<CudaCompile Include="blake2b.cu" />
<CudaCompile Include="Algo256\blake256.cu">
<MaxRegCount>64</MaxRegCount>
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options="-dlcm=cg" %(AdditionalOptions)</AdditionalOptions>
<FastMath>true</FastMath>
</CudaCompile>
<CudaCompile Include="Algo256\blake2s.cu" />
<CudaCompile Include="Algo256\decred.cu">
<MaxRegCount>128</MaxRegCount>
</CudaCompile>
<CudaCompile Include="Algo256\vanilla.cu" />
<CudaCompile Include="Algo256\keccak256.cu" />
<CudaCompile Include="Algo256\cuda_blake256.cu" />
<CudaCompile Include="Algo256\cuda_bmw256.cu" />
<CudaCompile Include="Algo256\cuda_cubehash256.cu" />
<CudaCompile Include="Algo256\cuda_fugue256.cu" />
<CudaCompile Include="Algo256\cuda_groestl256.cu" />
<CudaCompile Include="Algo256\cuda_keccak256.cu">
<CudaCompile Include="Algo256\cuda_keccak256.cu" />
<CudaCompile Include="Algo256\cuda_keccak256_sm3.cu">
<MaxRegCount>92</MaxRegCount>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_skein256.cu" />
<CudaCompile Include="lbry\cuda_sha256_lbry.cu" />
<CudaCompile Include="lbry\cuda_sha512_lbry.cu" />
<CudaCompile Include="lbry\cuda_lbry_merged.cu" />
<CudaCompile Include="lbry\lbry.cu" />
<CudaCompile Include="pentablake.cu">
<MaxRegCount>80</MaxRegCount>
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options="-dlcm=cg" %(AdditionalOptions)</AdditionalOptions>
<FastMath>true</FastMath>
</CudaCompile>
<CudaCompile Include="quark\animecoin.cu">
</CudaCompile>
<CudaCompile Include="quark\cuda_bmw512.cu">
<MaxRegCount>128</MaxRegCount>
</CudaCompile>
@@ -428,27 +516,50 @@
</CudaCompile>
<CudaCompile Include="quark\cuda_skein512.cu">
</CudaCompile>
<CudaCompile Include="quark\quarkcoin.cu">
</CudaCompile>
<CudaCompile Include="qubit\deep.cu">
</CudaCompile>
<CudaCompile Include="qubit\luffa.cu">
</CudaCompile>
<CudaCompile Include="qubit\qubit.cu">
</CudaCompile>
<CudaCompile Include="qubit\qubit_luffa512.cu">
</CudaCompile>
<CudaCompile Include="quark\quarkcoin.cu" />
<CudaCompile Include="quark\nist5.cu" />
<CudaCompile Include="qubit\deep.cu" />
<CudaCompile Include="qubit\luffa.cu" />
<CudaCompile Include="qubit\qubit.cu" />
<CudaCompile Include="qubit\qubit_luffa512.cu" />
<CudaCompile Include="lyra2\allium.cu" />
<CudaCompile Include="lyra2\lyra2RE.cu" />
<CudaCompile Include="lyra2\cuda_lyra2.cu" />
<CudaCompile Include="lyra2\lyra2REv2.cu" />
<CudaCompile Include="lyra2\cuda_lyra2v2.cu" />
<ClInclude Include="lyra2\cuda_lyra2_sm2.cuh" />
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh" />
<ClInclude Include="lyra2\cuda_lyra2v2_sm3.cuh" />
<CudaCompile Include="lyra2\lyra2REv3.cu" />
<CudaCompile Include="lyra2\cuda_lyra2v3.cu" />
<ClInclude Include="lyra2\cuda_lyra2v3_sm3.cuh" />
<CudaCompile Include="lyra2\lyra2Z.cu" />
<CudaCompile Include="lyra2\cuda_lyra2Z.cu" />
<ClInclude Include="lyra2\cuda_lyra2Z_sm5.cuh" />
<CudaCompile Include="polytimos.cu" />
<CudaCompile Include="sia\sia.cu" />
<CudaCompile Include="skein.cu">
<MaxRegCount>64</MaxRegCount>
</CudaCompile>
<CudaCompile Include="cuda_skeincoin.cu">
<MaxRegCount>48</MaxRegCount>
</CudaCompile>
<CudaCompile Include="x11\cuda_x11_aes.cu">
<ExcludedFromBuild>true</ExcludedFromBuild>
<CudaCompile Include="phi\phi.cu" />
<CudaCompile Include="phi\phi2.cu" />
<CudaCompile Include="phi\cuda_phi2.cu" />
<CudaCompile Include="phi\cuda_phi2_cubehash512.cu" />
<CudaCompile Include="skunk\skunk.cu" />
<CudaCompile Include="skunk\cuda_skunk.cu">
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
<MaxRegCount>64</MaxRegCount>
</CudaCompile>
<CudaCompile Include="skunk\cuda_skunk_streebog.cu" />
<ClInclude Include="tribus\cuda_echo512_aes.cuh" />
<CudaCompile Include="tribus\cuda_echo512_final.cu">
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
</CudaCompile>
<CudaCompile Include="tribus\tribus.cu" />
<ClInclude Include="x11\cuda_x11_aes.cuh" />
<CudaCompile Include="x11\cuda_x11_cubehash512.cu" />
<CudaCompile Include="x11\cuda_x11_echo.cu">
</CudaCompile>
@@ -459,45 +570,54 @@
<CudaCompile Include="x11\cuda_x11_shavite512.cu">
<MaxRegCount>128</MaxRegCount>
</CudaCompile>
<ClInclude Include="x11\cuda_x11_simd512_func.cuh" />
<CudaCompile Include="x11\cuda_x11_simd512.cu">
<MaxRegCount>64</MaxRegCount>
</CudaCompile>
<CudaCompile Include="x11\cuda_streebog.cu" />
<CudaCompile Include="x11\cuda_streebog_maxwell.cu" />
<CudaCompile Include="x11\c11.cu" />
<CudaCompile Include="x11\fresh.cu" />
<CudaCompile Include="x11\sib.cu" />
<CudaCompile Include="x11\s3.cu" />
<CudaCompile Include="x11\simd_functions.cu">
<ExcludedFromBuild>true</ExcludedFromBuild>
</CudaCompile>
<CudaCompile Include="x11\x11.cu">
</CudaCompile>
<CudaCompile Include="x11\timetravel.cu" />
<CudaCompile Include="x11\bitcore.cu" />
<CudaCompile Include="x11\exosis.cu" />
<CudaCompile Include="x11\veltor.cu" />
<CudaCompile Include="x11\x11.cu" />
<CudaCompile Include="x11\x11evo.cu" />
<CudaCompile Include="x12\x12.cu" />
<CudaCompile Include="x13\cuda_x13_hamsi512.cu">
<MaxRegCount>72</MaxRegCount>
</CudaCompile>
<CudaCompile Include="x13\cuda_x13_fugue512.cu">
</CudaCompile>
<CudaCompile Include="x13\x13.cu">
<CudaCompile Include="x13\x13.cu" />
<CudaCompile Include="x13\cuda_hsr_sm3.cu" />
<CudaCompile Include="x13\hsr.cu" />
<CudaCompile Include="x15\x14.cu" />
<CudaCompile Include="x15\cuda_x14_shabal512.cu" />
<CudaCompile Include="x15\cuda_x15_whirlpool.cu" />
<CudaCompile Include="x15\x15.cu" />
<CudaCompile Include="x15\whirlpool.cu" />
<CudaCompile Include="x15\cuda_x15_whirlpool_sm3.cu" />
<CudaCompile Include="x16\x16r.cu" />
<CudaCompile Include="x16\x16s.cu" />
<CudaCompile Include="x16\cuda_x16_echo512.cu" />
<CudaCompile Include="x16\cuda_x16_fugue512.cu" />
<CudaCompile Include="x16\cuda_x16_shabal512.cu" />
<CudaCompile Include="x16\cuda_x16_simd512_80.cu" />
<CudaCompile Include="x16\cuda_x16_echo512_64.cu">
<CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration>
</CudaCompile>
<CudaCompile Include="x15\x14.cu">
</CudaCompile>
<CudaCompile Include="x15\cuda_x14_shabal512.cu">
</CudaCompile>
<CudaCompile Include="x15\x15.cu">
</CudaCompile>
<CudaCompile Include="x15\cuda_whirlpoolx.cu" />
<CudaCompile Include="x15\whirlpoolx.cu" />
<CudaCompile Include="x17\x17.cu">
</CudaCompile>
<CudaCompile Include="x17\cuda_x17_haval512.cu">
<CudaCompile Include="x17\hmq17.cu" />
<CudaCompile Include="x17\sonoa.cu" />
<CudaCompile Include="x17\x17.cu" />
<CudaCompile Include="x17\cuda_x17_haval256.cu">
</CudaCompile>
<CudaCompile Include="x17\cuda_x17_sha512.cu">
<MaxRegCount>80</MaxRegCount>
</CudaCompile>
<CudaCompile Include="x15\x14.cu">
</CudaCompile>
<CudaCompile Include="x15\x15.cu">
</CudaCompile>
<CudaCompile Include="x17\x17.cu">
</CudaCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\ccminer.ico" />
@@ -510,7 +630,7 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.targets" />
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.targets" />
</ImportGroup>
<!-- Copy the required dlls -->
<Target Name="AfterBuild">
+431 -29
View File
@@ -46,6 +46,9 @@
<Filter Include="Source Files\CUDA\qubit">
<UniqueIdentifier>{f3ed23a2-8ce7-41a5-b051-6da56047dc35}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\skunk">
<UniqueIdentifier>{23ed23a2-8e7a-65a2-b051-8aa63047d352}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\x11">
<UniqueIdentifier>{dd751f2d-bfd6-42c1-8f9b-cbe94e539353}</UniqueIdentifier>
</Filter>
@@ -55,6 +58,9 @@
<Filter Include="Source Files\CUDA\x15">
<UniqueIdentifier>{a2403c22-6777-46ab-a55a-3fcc7386c974}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\x16">
<UniqueIdentifier>{55dfae6a-66ba-43e2-8ceb-98ee70cbdf16}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\x17">
<UniqueIdentifier>{85dfae6a-66ca-4332-8cec-98ee70cbdf2f}</UniqueIdentifier>
</Filter>
@@ -79,6 +85,42 @@
<Filter Include="Source Files\neoscrypt">
<UniqueIdentifier>{2037fd0d-e7a2-4da8-956c-150aec726a99}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\lyra2">
<UniqueIdentifier>{1613763f-895c-4321-b58b-6f5849868956}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\lbry">
<UniqueIdentifier>{3079ea1f-f768-455a-acd6-f517fac535b4}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\sha256">
<UniqueIdentifier>{86a896c0-1688-4854-98e3-285d166069a3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\sia">
<UniqueIdentifier>{86a896c0-1688-4854-98e0-285d166069a3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\crypto">
<UniqueIdentifier>{fea0fce3-c0fe-42f7-aa37-0cbba10b008a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\crypto\xmr">
<UniqueIdentifier>{af52b078-ed91-4c6e-b07a-e9243acc85d2}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\crypto\bbr">
<UniqueIdentifier>{af387eac-e9e6-4e91-a5e8-637b1e7a8d93}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\xmr">
<UniqueIdentifier>{0f9aec5e-5409-488f-992a-2c108590d1ac}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\equi">
<UniqueIdentifier>{031afae7-2a78-4e32-9738-4b589b6f7ff3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\tribus">
<UniqueIdentifier>{1e548d79-c217-4203-989a-a592fe2b2de3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\phi">
<UniqueIdentifier>{311e8d79-1612-4f0f-8591-23a592f2b2d3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CUDA\x12">
<UniqueIdentifier>{xde48d89-fx12-1323-129a-b592fe2b2de3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="compat\jansson\dump.c">
@@ -123,6 +165,12 @@
<ClCompile Include="sph\blake.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\blake2b.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\blake2s.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\bmw.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
@@ -147,9 +195,6 @@
<ClCompile Include="sph\luffa.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\md_helper.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\sha2.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
@@ -177,12 +222,21 @@
<ClCompile Include="sph\haval.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\haval_helper.c">
<ClCompile Include="sph\ripemd.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\sph_sha2.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\sha2big.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="sph\streebog.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="x13\sm3.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="compat\winansi.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -213,12 +267,18 @@
<ClCompile Include="compat\jansson\error.c">
<Filter>Source Files\jansson</Filter>
</ClCompile>
<ClInclude Include="compat\pthreads\pthread.h">
<Filter>Header Files\compat</Filter>
</ClInclude>
<ClCompile Include="lyra2\Lyra2.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="lyra2\Sponge.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="lyra2\Lyra2Z.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="scrypt.cpp">
<Filter>Source Files\CUDA\scrypt</Filter>
</ClCompile>
@@ -246,14 +306,65 @@
<ClCompile Include="hefty1.c">
<Filter>Source Files\CUDA\heavy</Filter>
</ClCompile>
<ClCompile Include="bench.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bignum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nvapi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nvsettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="sia\sia-rpc.cpp">
<Filter>Source Files\sia</Filter>
</ClCompile>
<ClCompile Include="crypto\xmr-rpc.cpp">
<Filter>Source Files\crypto</Filter>
</ClCompile>
<ClCompile Include="crypto\aesb.cpp">
<Filter>Source Files\crypto\xmr</Filter>
</ClCompile>
<ClCompile Include="crypto\cpu\c_keccak.c">
<Filter>Source Files\crypto\xmr</Filter>
</ClCompile>
<ClCompile Include="crypto\oaes_lib.cpp">
<Filter>Source Files\crypto\xmr</Filter>
</ClCompile>
<ClCompile Include="crypto\cryptolight-cpu.cpp">
<Filter>Source Files\crypto\xmr</Filter>
</ClCompile>
<ClCompile Include="crypto\cryptonight-cpu.cpp">
<Filter>Source Files\crypto\xmr</Filter>
</ClCompile>
<ClCompile Include="crypto\mman.c">
<Filter>Source Files\crypto\bbr</Filter>
</ClCompile>
<ClCompile Include="crypto\wildkeccak-cpu.cpp">
<Filter>Source Files\crypto\bbr</Filter>
</ClCompile>
<ClCompile Include="equi\equi.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\equihash.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\equi-stratum.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
<ClCompile Include="equi\blake2\blake2bx.cpp">
<Filter>Source Files\equi</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="compat.h">
<ClInclude Include="algos.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="compat.h">
<Filter>Header Files\compat</Filter>
</ClInclude>
<ClInclude Include="elist.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -275,8 +386,8 @@
<ClInclude Include="compat\stdbool.h">
<Filter>Header Files\compat</Filter>
</ClInclude>
<ClInclude Include="cpuminer-config.h">
<Filter>Header Files</Filter>
<ClInclude Include="compat\ccminer-config.h">
<Filter>Header Files\compat</Filter>
</ClInclude>
<ClInclude Include="uint256.h">
<Filter>Header Files</Filter>
@@ -284,6 +395,18 @@
<ClInclude Include="cuda_groestlcoin.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
<ClInclude Include="quark\cuda_quark.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
<ClInclude Include="x11\cuda_x11.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
<ClInclude Include="sph\blake2b.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
<ClInclude Include="sph\blake2s.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
<ClInclude Include="sph\sph_blake.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
@@ -329,7 +452,7 @@
<ClInclude Include="cuda_helper.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
<ClInclude Include="cuda_vector.h">
<ClInclude Include="cuda_vector_uint2x4.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
<ClInclude Include="sph\sph_hamsi.h">
@@ -338,6 +461,9 @@
<ClInclude Include="sph\sph_shabal.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
<ClInclude Include="sph\sph_streebog.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
<ClInclude Include="sph\sph_whirlpool.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
@@ -386,6 +512,9 @@
<ClInclude Include="lyra2\Lyra2.h">
<Filter>Header Files\lyra2</Filter>
</ClInclude>
<ClInclude Include="lyra2\Lyra2Z.h">
<Filter>Header Files\lyra2</Filter>
</ClInclude>
<ClInclude Include="lyra2\Sponge.h">
<Filter>Header Files\lyra2</Filter>
</ClInclude>
@@ -413,6 +542,75 @@
<ClInclude Include="bignum.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lyra2\cuda_lyra2v2_sm3.cuh">
<Filter>Source Files\CUDA\lyra2</Filter>
</ClInclude>
<ClInclude Include="lyra2\cuda_lyra2_sm2.cuh">
<Filter>Source Files\CUDA\lyra2</Filter>
</ClInclude>
<ClInclude Include="lyra2\cuda_lyra2_sm5.cuh">
<Filter>Source Files\CUDA\lyra2</Filter>
</ClInclude>
<ClInclude Include="lyra2\cuda_lyra2Z_sm5.cuh">
<Filter>Source Files\CUDA\lyra2</Filter>
</ClInclude>
<ClInclude Include="quark\cuda_quark_blake512_sp.cuh">
<Filter>Source Files\CUDA\quark</Filter>
</ClInclude>
<ClInclude Include="quark\cuda_bmw512_sm3.cuh">
<Filter>Source Files\CUDA\quark</Filter>
</ClInclude>
<ClInclude Include="quark\cuda_quark_groestl512_sm2.cuh">
<Filter>Source Files\CUDA\quark</Filter>
</ClInclude>
<ClInclude Include="x11\cuda_x11_simd512_sm2.cuh">
<Filter>Source Files\CUDA\x11</Filter>
</ClInclude>
<ClInclude Include="sia\sia-rpc.h">
<Filter>Source Files\sia</Filter>
</ClInclude>
<ClInclude Include="crypto\xmr-rpc.h">
<Filter>Source Files\crypto</Filter>
</ClInclude>
<ClInclude Include="crypto\mman.h">
<Filter>Source Files\crypto\bbr</Filter>
</ClInclude>
<ClInclude Include="crypto\wildkeccak.h">
<Filter>Source Files\crypto\bbr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_aes.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_blake.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_groestl.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_jh.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_keccak.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cn_skein.cuh">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cryptolight.h">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="crypto\cryptonight.h">
<Filter>Source Files\CUDA\xmr</Filter>
</ClInclude>
<ClInclude Include="equi\eqcuda.hpp">
<Filter>Source Files\equi</Filter>
</ClInclude>
<ClInclude Include="equi\equihash.h">
<Filter>Source Files\equi</Filter>
</ClInclude>
<ClInclude Include="x16\cuda_x16.h">
<Filter>Header Files\CUDA</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cpp">
@@ -424,6 +622,9 @@
<CudaCompile Include="JHA\cuda_jha_keccak512.cu">
<Filter>Source Files\CUDA\JHA</Filter>
</CudaCompile>
<CudaCompile Include="JHA\jha.cu">
<Filter>Source Files\CUDA\JHA</Filter>
</CudaCompile>
<CudaCompile Include="JHA\jackpotcoin.cu">
<Filter>Source Files\CUDA\JHA</Filter>
</CudaCompile>
@@ -466,8 +667,11 @@
<CudaCompile Include="heavy\heavy.cu">
<Filter>Source Files\CUDA\heavy</Filter>
</CudaCompile>
<CudaCompile Include="quark\animecoin.cu">
<Filter>Source Files\CUDA\quark</Filter>
<CudaCompile Include="heavy\bastion.cu">
<Filter>Source Files\CUDA\heavy</Filter>
</CudaCompile>
<CudaCompile Include="heavy\cuda_bastion.cu">
<Filter>Source Files\CUDA\heavy</Filter>
</CudaCompile>
<CudaCompile Include="quark\cuda_bmw512.cu">
<Filter>Source Files\CUDA\quark</Filter>
@@ -478,6 +682,9 @@
<CudaCompile Include="quark\cuda_quark_keccak512.cu">
<Filter>Source Files\CUDA\quark</Filter>
</CudaCompile>
<CudaCompile Include="quark\nist5.cu">
<Filter>Source Files\CUDA\quark</Filter>
</CudaCompile>
<CudaCompile Include="quark\quarkcoin.cu">
<Filter>Source Files\CUDA\quark</Filter>
</CudaCompile>
@@ -493,12 +700,9 @@
<CudaCompile Include="qubit\qubit_luffa512.cu">
<Filter>Source Files\CUDA\qubit</Filter>
</CudaCompile>
<CudaCompile Include="cuda_nist5.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="x11\cuda_x11_aes.cu">
<ClInclude Include="x11\cuda_x11_aes.cuh">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
</ClInclude>
<CudaCompile Include="x11\cuda_x11_cubehash512.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
@@ -517,6 +721,9 @@
<CudaCompile Include="x11\cuda_x11_simd512.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<ClInclude Include="x11\cuda_x11_simd512_func.cuh">
<Filter>Source Files\CUDA\x11</Filter>
</ClInclude>
<CudaCompile Include="x11\c11.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
@@ -526,7 +733,7 @@
<CudaCompile Include="x11\x11.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\simd_functions.cu">
<CudaCompile Include="x11\x11evo.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x13\cuda_x13_fugue512.cu">
@@ -538,6 +745,12 @@
<CudaCompile Include="x13\x13.cu">
<Filter>Source Files\CUDA\x13</Filter>
</CudaCompile>
<CudaCompile Include="x13\cuda_hsr_sm3.cu">
<Filter>Source Files\CUDA\x13</Filter>
</CudaCompile>
<CudaCompile Include="x13\hsr.cu">
<Filter>Source Files\CUDA\x13</Filter>
</CudaCompile>
<CudaCompile Include="cuda_checkhash.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
@@ -553,36 +766,108 @@
<CudaCompile Include="x15\cuda_x15_whirlpool.cu">
<Filter>Source Files\CUDA\x15</Filter>
</CudaCompile>
<CudaCompile Include="x15\cuda_whirlpoolx.cu">
<CudaCompile Include="x15\whirlpool.cu">
<Filter>Source Files\CUDA\x15</Filter>
</CudaCompile>
<CudaCompile Include="x15\whirlpoolx.cu">
<Filter>Source Files\CUDA\x15</Filter>
</CudaCompile>
<CudaCompile Include="x17\cuda_x17_haval512.cu">
<CudaCompile Include="x17\cuda_x17_haval256.cu">
<Filter>Source Files\CUDA\x17</Filter>
</CudaCompile>
<CudaCompile Include="x17\cuda_x17_sha512.cu">
<Filter>Source Files\CUDA\x17</Filter>
</CudaCompile>
<CudaCompile Include="x17\hmq17.cu">
<Filter>Source Files\CUDA\x17</Filter>
</CudaCompile>
<CudaCompile Include="x17\sonoa.cu">
<Filter>Source Files\CUDA\x17</Filter>
</CudaCompile>
<CudaCompile Include="x17\x17.cu">
<Filter>Source Files\CUDA\x17</Filter>
</CudaCompile>
<CudaCompile Include="pentablake.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="polytimos.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="phi\phi.cu">
<Filter>Source Files\CUDA\phi</Filter>
</CudaCompile>
<CudaCompile Include="phi\phi2.cu">
<Filter>Source Files\CUDA\phi</Filter>
</CudaCompile>
<CudaCompile Include="phi\cuda_phi2.cu">
<Filter>Source Files\CUDA\phi</Filter>
</CudaCompile>
<CudaCompile Include="phi\cuda_phi2_cubehash512.cu">
<Filter>Source Files\CUDA\phi</Filter>
</CudaCompile>
<CudaCompile Include="skunk\skunk.cu">
<Filter>Source Files\CUDA\skunk</Filter>
</CudaCompile>
<CudaCompile Include="skunk\cuda_skunk.cu">
<Filter>Source Files\CUDA\skunk</Filter>
</CudaCompile>
<CudaCompile Include="skunk\cuda_skunk_streebog.cu">
<Filter>Source Files\CUDA\skunk</Filter>
</CudaCompile>
<CudaCompile Include="tribus\tribus.cu">
<Filter>Source Files\CUDA\tribus</Filter>
</CudaCompile>
<CudaCompile Include="tribus\cuda_echo512_final.cu">
<Filter>Source Files\CUDA\tribus</Filter>
</CudaCompile>
<ClInclude Include="tribus\cuda_echo512_aes.cuh">
<Filter>Source Files\CUDA\tribus</Filter>
</ClInclude>
<CudaCompile Include="x11\sib.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\cuda_streebog.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\cuda_streebog_maxwell.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\s3.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x12\x12.cu">
<Filter>Source Files\CUDA\x12</Filter>
</CudaCompile>
<CudaCompile Include="x11\timetravel.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\bitcore.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\exosis.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="x11\veltor.cu">
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\blake256.cu">
<Filter>Source Files\CUDA</Filter>
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\decred.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\vanilla.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\keccak256.cu">
<Filter>Source Files\CUDA</Filter>
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_blake256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_bmw256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_cubehash256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_fugue256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
@@ -592,14 +877,11 @@
<CudaCompile Include="Algo256\cuda_keccak256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_skein256.cu">
<CudaCompile Include="Algo256\cuda_keccak256_sm3.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\cuda_lyra2.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\lyra2RE.cu">
<Filter>Source Files\CUDA</Filter>
<CudaCompile Include="Algo256\cuda_skein256.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="zr5.cu">
<Filter>Source Files\CUDA</Filter>
@@ -643,6 +925,126 @@
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
<Filter>Source Files\neoscrypt</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\bmw.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\cuda_bmw.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\allium.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\cuda_lyra2.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\cuda_lyra2v2.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\lyra2RE.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\lyra2REv2.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\cuda_lyra2v3.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<ClInclude Include="lyra2\cuda_lyra2v3_sm3.cuh">
<Filter>Source Files\CUDA\lyra2</Filter>
</ClInclude>
<CudaCompile Include="lyra2\lyra2REv3.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\cuda_lyra2Z.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="lyra2\lyra2Z.cu">
<Filter>Source Files\CUDA\lyra2</Filter>
</CudaCompile>
<CudaCompile Include="blake2b.cu">
<Filter>Source Files\CUDA\</Filter>
</CudaCompile>
<CudaCompile Include="Algo256\blake2s.cu">
<Filter>Source Files\CUDA\Algo256</Filter>
</CudaCompile>
<CudaCompile Include="lbry\cuda_sha256_lbry.cu">
<Filter>Source Files\CUDA\lbry</Filter>
</CudaCompile>
<CudaCompile Include="lbry\cuda_sha512_lbry.cu">
<Filter>Source Files\CUDA\lbry</Filter>
</CudaCompile>
<CudaCompile Include="lbry\cuda_lbry_merged.cu">
<Filter>Source Files\CUDA\lbry</Filter>
</CudaCompile>
<CudaCompile Include="lbry\lbry.cu">
<Filter>Source Files\CUDA\lbry</Filter>
</CudaCompile>
<CudaCompile Include="sha256\cuda_sha256d.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sha256\sha256d.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sha256\cuda_sha256t.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sha256\sha256t.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sha256\cuda_sha256q.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sha256\sha256q.cu">
<Filter>Source Files\CUDA\sha256</Filter>
</CudaCompile>
<CudaCompile Include="sia\sia.cu">
<Filter>Source Files\sia</Filter>
</CudaCompile>
<CudaCompile Include="crypto\cryptolight.cu">
<Filter>Source Files\CUDA\xmr</Filter>
</CudaCompile>
<CudaCompile Include="crypto\cryptolight-core.cu">
<Filter>Source Files\CUDA\xmr</Filter>
</CudaCompile>
<CudaCompile Include="crypto\cryptonight.cu">
<Filter>Source Files\CUDA\xmr</Filter>
</CudaCompile>
<CudaCompile Include="crypto\cryptonight-core.cu">
<Filter>Source Files\CUDA\xmr</Filter>
</CudaCompile>
<CudaCompile Include="crypto\cryptonight-extra.cu">
<Filter>Source Files\CUDA\xmr</Filter>
</CudaCompile>
<CudaCompile Include="crypto\wildkeccak.cu">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="equi\cuda_equi.cu">
<Filter>Source Files\equi</Filter>
</CudaCompile>
<CudaCompile Include="x15\cuda_x15_whirlpool_sm3.cu">
<Filter>Source Files\CUDA\x15</Filter>
</CudaCompile>
<CudaCompile Include="x16\cuda_x16_echo512.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\cuda_x16_echo512_64.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\cuda_x16_fugue512.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\cuda_x16_shabal512.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\cuda_x16_simd512_80.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\x16r.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
<CudaCompile Include="x16\x16s.cu">
<Filter>Source Files\CUDA\x16</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\ccminer.ico">
+15 -1
View File
@@ -4,8 +4,9 @@
#ifdef WIN32
#include <windows.h>
#include <time.h>
extern int opt_priority;
#define localtime_r(src, dst) localtime_s(dst, src)
static __inline void sleep(int secs)
{
@@ -16,6 +17,8 @@ enum {
PRIO_PROCESS = 0,
};
extern int opt_priority;
static __inline int setpriority(int which, int who, int prio)
{
switch (opt_priority) {
@@ -48,6 +51,17 @@ static __inline int setpriority(int which, int who, int prio)
#define strcasecmp(x,y) _stricmp(x,y)
typedef int ssize_t;
__inline int msver(void) {
switch (_MSC_VER) {
case 1500: return 2008;
case 1600: return 2010;
case 1700: return 2012;
case 1800: return 2013;
case 1900: return 2015;
default: return (_MSC_VER/100);
}
}
#include <stdlib.h>
static __inline char * dirname(char *file) {
char buffer[_MAX_PATH] = { 0 };
+602
View File
@@ -0,0 +1,602 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BIGNUM_H
#define BITCOIN_BIGNUM_H
#ifndef PROTOCOL_VERSION
#define PROTOCOL_VERSION 70001
#endif
#include <map>
#include <limits>
#include <algorithm>
#include <stdexcept>
#include <vector>
#include "uint256.h"
#include <openssl/bn.h>
#include "serialize.hpp"
using namespace std;
/** Errors thrown by the bignum class */
class bignum_error : public std::runtime_error
{
public:
explicit bignum_error(const std::string& str) : std::runtime_error(str) {}
};
/** RAII encapsulated BN_CTX (OpenSSL bignum context) */
class CAutoBN_CTX
{
protected:
BN_CTX* pctx;
BN_CTX* operator=(BN_CTX* pnew) { return pctx = pnew; }
public:
CAutoBN_CTX()
{
pctx = BN_CTX_new();
if (pctx == NULL)
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
}
~CAutoBN_CTX()
{
if (pctx != NULL)
BN_CTX_free(pctx);
}
operator BN_CTX*() { return pctx; }
BN_CTX& operator*() { return *pctx; }
BN_CTX** operator&() { return &pctx; }
bool operator!() { return (pctx == NULL); }
};
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
class CBigNum : public BIGNUM
{
public:
CBigNum()
{
BN_init(this);
}
CBigNum(const CBigNum& b)
{
BN_init(this);
if (!BN_copy(this, &b))
{
BN_clear_free(this);
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
}
}
CBigNum& operator=(const CBigNum& b)
{
if (!BN_copy(this, &b))
throw bignum_error("CBigNum::operator= : BN_copy failed");
return (*this);
}
~CBigNum()
{
BN_clear_free(this);
}
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int64 n) { BN_init(this); setint64(n); }
CBigNum(unsigned char n) { BN_init(this); setulong(n); }
CBigNum(unsigned short n) { BN_init(this); setulong(n); }
CBigNum(unsigned int n) { BN_init(this); setulong(n); }
CBigNum(unsigned long n) { BN_init(this); setulong(n); }
CBigNum(uint64 n) { BN_init(this); setuint64(n); }
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
explicit CBigNum(const std::vector<unsigned char>& vch)
{
BN_init(this);
setvch(vch);
}
void setulong(unsigned long n)
{
if (!BN_set_word(this, n))
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
}
unsigned long getulong() const
{
return (unsigned long) BN_get_word(this);
}
unsigned int getuint() const
{
return (unsigned int) BN_get_word(this);
}
int getint() const
{
unsigned long n = (unsigned long) BN_get_word(this);
if (!BN_is_negative(this))
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
else
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
}
void setint64(int64 sn)
{
unsigned char pch[sizeof(sn) + 6];
unsigned char* p = pch + 4;
bool fNegative;
uint64 n;
if (sn < 0LL)
{
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
// and it's not well-defined what happens if you make it unsigned before negating it,
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
n = -(sn + 1);
++n;
fNegative = true;
} else {
n = sn;
fNegative = false;
}
bool fLeadingZeroes = true;
for (int i = 0; i < 8; i++)
{
unsigned char c = (n >> 56) & 0xff;
n <<= 8;
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = (fNegative ? 0x80 : 0);
else if (fNegative)
c |= 0x80;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
void setuint64(uint64 n)
{
unsigned char pch[sizeof(n) + 6];
unsigned char* p = pch + 4;
bool fLeadingZeroes = true;
for (int i = 0; i < 8; i++)
{
unsigned char c = (n >> 56) & 0xff;
n <<= 8;
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = 0;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
void setuint256(uint256 n)
{
unsigned char pch[sizeof(n) + 6];
unsigned char* p = pch + 4;
bool fLeadingZeroes = true;
unsigned char* pbegin = (unsigned char*)&n;
unsigned char* psrc = pbegin + sizeof(n);
while (psrc != pbegin)
{
unsigned char c = *(--psrc);
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = 0;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize >> 0) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
uint256 getuint256() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
if (vch.size() > 4)
vch[4] &= 0x7f;
uint256 n = 0;
for (unsigned int i = 0, j = (unsigned int) vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
((unsigned char*)&n)[i] = vch[j];
return n;
}
void setvch(const std::vector<unsigned char>& vch)
{
std::vector<unsigned char> vch2(vch.size() + 4);
unsigned int nSize = (unsigned int) vch.size();
// BIGNUM's byte stream format expects 4 bytes of
// big endian size data info at the front
vch2[0] = (nSize >> 24) & 0xff;
vch2[1] = (nSize >> 16) & 0xff;
vch2[2] = (nSize >> 8) & 0xff;
vch2[3] = (nSize >> 0) & 0xff;
// swap data to big endian
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
BN_mpi2bn(&vch2[0], (int) vch2.size(), this);
}
std::vector<unsigned char> getvch() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
if (nSize <= 4)
return std::vector<unsigned char>();
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
vch.erase(vch.begin(), vch.begin() + 4);
reverse(vch.begin(), vch.end());
return vch;
}
// The "compact" format is a representation of a whole
// number N using an unsigned 32bit number similar to a
// floating point format.
// The most significant 8 bits are the unsigned exponent of base 256.
// This exponent can be thought of as "number of bytes of N".
// The lower 23 bits are the mantissa.
// Bit number 24 (0x800000) represents the sign of N.
// N = (-1^sign) * mantissa * 256^(exponent-3)
//
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
// MPI uses the most significant bit of the first byte as sign.
// Thus 0x1234560000 is compact (0x05123456)
// and 0xc0de000000 is compact (0x0600c0de)
// (0x05c0de00) would be -0x40de000000
//
// Bitcoin only uses this "compact" format for encoding difficulty
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
//
// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
CBigNum& SetCompact(unsigned int nCompact)
{
unsigned int nSize = nCompact >> 24;
bool fNegative =(nCompact & 0x00800000) != 0;
unsigned int nWord = nCompact & 0x007fffff;
if (nSize <= 3)
{
nWord >>= 8*(3-nSize);
BN_set_word(this, nWord);
}
else
{
BN_set_word(this, nWord);
BN_lshift(this, this, 8*(nSize-3));
}
BN_set_negative(this, fNegative);
return *this;
}
unsigned int GetCompact() const
{
unsigned int nSize = BN_num_bytes(this);
unsigned int nCompact = 0;
if (nSize <= 3)
nCompact = (unsigned int) BN_get_word(this) << 8*(3-nSize);
else
{
CBigNum bn;
BN_rshift(&bn, this, 8*(nSize-3));
nCompact = (unsigned int) BN_get_word(&bn);
}
// The 0x00800000 bit denotes the sign.
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
if (nCompact & 0x00800000)
{
nCompact >>= 8;
nSize++;
}
nCompact |= nSize << 24;
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
return nCompact;
}
void SetHex(const std::string& str)
{
// skip 0x
const char* psz = str.c_str();
while (isspace(*psz))
psz++;
bool fNegative = false;
if (*psz == '-')
{
fNegative = true;
psz++;
}
if (psz[0] == '0' && tolower(psz[1]) == 'x')
psz += 2;
while (isspace(*psz))
psz++;
// hex string to bignum
static const signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
*this = 0;
while (isxdigit(*psz))
{
*this <<= 4;
int n = phexdigit[(unsigned char)*psz++];
*this += n;
}
if (fNegative)
*this = 0 - *this;
}
std::string ToString(int nBase=10) const
{
CAutoBN_CTX pctx;
CBigNum bnBase = nBase;
CBigNum bn0 = 0;
std::string str;
CBigNum bn = *this;
BN_set_negative(&bn, false);
CBigNum dv;
CBigNum rem;
if (BN_cmp(&bn, &bn0) == 0)
return "0";
while (BN_cmp(&bn, &bn0) > 0)
{
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
throw bignum_error("CBigNum::ToString() : BN_div failed");
bn = dv;
unsigned int c = rem.getulong();
str += "0123456789abcdef"[c];
}
if (BN_is_negative(this))
str += "-";
reverse(str.begin(), str.end());
return str;
}
std::string GetHex() const
{
return ToString(16);
}
unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
{
return ::GetSerializeSize(getvch(), nType, nVersion);
}
template<typename Stream>
void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const
{
::Serialize(s, getvch(), nType, nVersion);
}
template<typename Stream>
void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION)
{
std::vector<unsigned char> vch;
::Unserialize(s, vch, nType, nVersion);
setvch(vch);
}
bool operator!() const
{
return BN_is_zero(this);
}
CBigNum& operator+=(const CBigNum& b)
{
if (!BN_add(this, this, &b))
throw bignum_error("CBigNum::operator+= : BN_add failed");
return *this;
}
CBigNum& operator-=(const CBigNum& b)
{
*this = *this - b;
return *this;
}
CBigNum& operator*=(const CBigNum& b)
{
CAutoBN_CTX pctx;
if (!BN_mul(this, this, &b, pctx))
throw bignum_error("CBigNum::operator*= : BN_mul failed");
return *this;
}
CBigNum& operator/=(const CBigNum& b)
{
*this = *this / b;
return *this;
}
CBigNum& operator%=(const CBigNum& b)
{
*this = *this % b;
return *this;
}
CBigNum& operator<<=(unsigned int shift)
{
if (!BN_lshift(this, this, shift))
throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
return *this;
}
CBigNum& operator>>=(unsigned int shift)
{
// Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
CBigNum a = 1;
a <<= shift;
if (BN_cmp(&a, this) > 0)
{
*this = 0;
return *this;
}
if (!BN_rshift(this, this, shift))
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
return *this;
}
CBigNum& operator++()
{
// prefix operator
if (!BN_add(this, this, BN_value_one()))
throw bignum_error("CBigNum::operator++ : BN_add failed");
return *this;
}
const CBigNum operator++(int)
{
// postfix operator
const CBigNum ret = *this;
++(*this);
return ret;
}
CBigNum& operator--()
{
// prefix operator
CBigNum r;
if (!BN_sub(&r, this, BN_value_one()))
throw bignum_error("CBigNum::operator-- : BN_sub failed");
*this = r;
return *this;
}
const CBigNum operator--(int)
{
// postfix operator
const CBigNum ret = *this;
--(*this);
return ret;
}
friend inline const CBigNum operator-(const CBigNum& a, const CBigNum& b);
friend inline const CBigNum operator/(const CBigNum& a, const CBigNum& b);
friend inline const CBigNum operator%(const CBigNum& a, const CBigNum& b);
};
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_add(&r, &a, &b))
throw bignum_error("CBigNum::operator+ : BN_add failed");
return r;
}
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_sub(&r, &a, &b))
throw bignum_error("CBigNum::operator- : BN_sub failed");
return r;
}
inline const CBigNum operator-(const CBigNum& a)
{
CBigNum r(a);
BN_set_negative(&r, !BN_is_negative(&r));
return r;
}
inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mul(&r, &a, &b, pctx))
throw bignum_error("CBigNum::operator* : BN_mul failed");
return r;
}
inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_div(&r, NULL, &a, &b, pctx))
throw bignum_error("CBigNum::operator/ : BN_div failed");
return r;
}
inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mod(&r, &a, &b, pctx))
throw bignum_error("CBigNum::operator% : BN_div failed");
return r;
}
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
{
CBigNum r;
if (!BN_lshift(&r, &a, shift))
throw bignum_error("CBigNum:operator<< : BN_lshift failed");
return r;
}
inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
{
CBigNum r = a;
r >>= shift;
return r;
}
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
#endif
+188 -194
View File
@@ -1,194 +1,188 @@
/* cpuminer-config.h. Generated from cpuminer-config.h.in by configure. */
/* cpuminer-config.h.in. Generated from configure.ac by autoheader. */
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
/* #undef CRAY_STACKSEG_END */
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the declaration of `be32dec', and to 0 if you
don't. */
#define HAVE_DECL_BE32DEC 0
/* Define to 1 if you have the declaration of `be32enc', and to 0 if you
don't. */
#define HAVE_DECL_BE32ENC 0
/* Define to 1 if you have the declaration of `le32dec', and to 0 if you
don't. */
#define HAVE_DECL_LE32DEC 0
/* Define to 1 if you have the declaration of `le32enc', and to 0 if you
don't. */
#define HAVE_DECL_LE32ENC 0
/* Define to 1 if you have the `getopt_long' function. */
#define HAVE_GETOPT_LONG 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `crypto' library (-lcrypto). */
#define HAVE_LIBCRYPTO 1
/* Define to 1 if you have a functional curl library. */
#define HAVE_LIBCURL 1
/* Define to 1 if you have the `ssl' library (-lssl). */
#define HAVE_LIBSSL 1
/* Define to 1 if you have the `z' library (-lz). */
#define HAVE_LIBZ 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <syslog.h> header file. */
/* #undef HAVE_SYSLOG_H */
/* Define to 1 if you have the <sys/endian.h> header file. */
/* #undef HAVE_SYS_ENDIAN_H */
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#define HAVE_SYS_SYSCTL_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Defined if libcurl supports AsynchDNS */
/* #undef LIBCURL_FEATURE_ASYNCHDNS */
/* Defined if libcurl supports IDN */
#define LIBCURL_FEATURE_IDN 1
/* Defined if libcurl supports IPv6 */
#define LIBCURL_FEATURE_IPV6 1
/* Defined if libcurl supports KRB4 */
/* #undef LIBCURL_FEATURE_KRB4 */
/* Defined if libcurl supports libz */
#define LIBCURL_FEATURE_LIBZ 1
/* Defined if libcurl supports NTLM */
#define LIBCURL_FEATURE_NTLM 1
/* Defined if libcurl supports SSL */
#define LIBCURL_FEATURE_SSL 1
/* Defined if libcurl supports SSPI */
/* #undef LIBCURL_FEATURE_SSPI */
/* Defined if libcurl supports DICT */
/* #undef LIBCURL_PROTOCOL_DICT */
/* Defined if libcurl supports FILE */
#define LIBCURL_PROTOCOL_FILE 1
/* Defined if libcurl supports FTP */
#define LIBCURL_PROTOCOL_FTP 1
/* Defined if libcurl supports FTPS */
#define LIBCURL_PROTOCOL_FTPS 1
/* Defined if libcurl supports HTTP */
#define LIBCURL_PROTOCOL_HTTP 1
/* Defined if libcurl supports HTTPS */
/* #undef LIBCURL_PROTOCOL_HTTPS */
/* Defined if libcurl supports IMAP */
/* #undef LIBCURL_PROTOCOL_IMAP */
/* Defined if libcurl supports LDAP */
/* #undef LIBCURL_PROTOCOL_LDAP */
/* Defined if libcurl supports POP3 */
/* #undef LIBCURL_PROTOCOL_POP3 */
/* Defined if libcurl supports RTSP */
/* #undef LIBCURL_PROTOCOL_RTSP */
/* Defined if libcurl supports SMTP */
/* #undef LIBCURL_PROTOCOL_SMTP */
/* Defined if libcurl supports TELNET */
/* #undef LIBCURL_PROTOCOL_TELNET */
/* Defined if libcurl supports TFTP */
/* #undef LIBCURL_PROTOCOL_TFTP */
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Name of package */
#define PACKAGE "ccminer"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "ccminer"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "ccminer 1.6.5-C11"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "ccminer"
/* Define to the home page for this package. */
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.6.5-C11"
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "1.6.5-C11"
/* Define curl_free() as free() if our version of curl lacks curl_free. */
/* #undef curl_free */
/* Define to `unsigned int' if <sys/types.h> does not define. */
//#define size_t unsigned int
/* CONFIG ONLY FOR MS VC++ BUILD */
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
/* #undef CRAY_STACKSEG_END */
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the declaration of `be32dec', and to 0 if you
don't. */
#define HAVE_DECL_BE32DEC 0
/* Define to 1 if you have the declaration of `be32enc', and to 0 if you
don't. */
#define HAVE_DECL_BE32ENC 0
/* Define to 1 if you have the declaration of `le32dec', and to 0 if you
don't. */
#define HAVE_DECL_LE32DEC 0
/* Define to 1 if you have the declaration of `le32enc', and to 0 if you
don't. */
#define HAVE_DECL_LE32ENC 0
/* Define to 1 if you have the `getopt_long' function. */
#define HAVE_GETOPT_LONG 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `crypto' library (-lcrypto). */
#define HAVE_LIBCRYPTO 1
/* Define to 1 if you have a functional curl library. */
#define HAVE_LIBCURL 1
/* Define to 1 if you have the `ssl' library (-lssl). */
#define HAVE_LIBSSL 1
/* Define to 1 if you have the `z' library (-lz). */
#define HAVE_LIBZ 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <syslog.h> header file. */
/* #undef HAVE_SYSLOG_H */
/* Define to 1 if you have the <sys/endian.h> header file. */
/* #undef HAVE_SYS_ENDIAN_H */
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#define HAVE_SYS_SYSCTL_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Defined if libcurl supports AsynchDNS */
/* #undef LIBCURL_FEATURE_ASYNCHDNS */
/* Defined if libcurl supports IDN */
#define LIBCURL_FEATURE_IDN 1
/* Defined if libcurl supports IPv6 */
#define LIBCURL_FEATURE_IPV6 1
/* Defined if libcurl supports KRB4 */
/* #undef LIBCURL_FEATURE_KRB4 */
/* Defined if libcurl supports libz */
#define LIBCURL_FEATURE_LIBZ 1
/* Defined if libcurl supports NTLM */
#define LIBCURL_FEATURE_NTLM 1
/* Defined if libcurl supports SSL */
#define LIBCURL_FEATURE_SSL 1
/* Defined if libcurl supports SSPI */
/* #undef LIBCURL_FEATURE_SSPI */
/* Defined if libcurl supports DICT */
/* #undef LIBCURL_PROTOCOL_DICT */
/* Defined if libcurl supports FILE */
#define LIBCURL_PROTOCOL_FILE 1
/* Defined if libcurl supports FTP */
#define LIBCURL_PROTOCOL_FTP 1
/* Defined if libcurl supports FTPS */
#define LIBCURL_PROTOCOL_FTPS 1
/* Defined if libcurl supports HTTP */
#define LIBCURL_PROTOCOL_HTTP 1
/* Defined if libcurl supports HTTPS */
#define LIBCURL_PROTOCOL_HTTPS 1
/* Defined if libcurl supports IMAP */
/* #undef LIBCURL_PROTOCOL_IMAP */
/* Defined if libcurl supports LDAP */
/* #undef LIBCURL_PROTOCOL_LDAP */
/* Defined if libcurl supports POP3 */
/* #undef LIBCURL_PROTOCOL_POP3 */
/* Defined if libcurl supports RTSP */
/* #undef LIBCURL_PROTOCOL_RTSP */
/* Defined if libcurl supports SMTP */
/* #undef LIBCURL_PROTOCOL_SMTP */
/* Defined if libcurl supports TELNET */
/* #undef LIBCURL_PROTOCOL_TELNET */
/* Defined if libcurl supports TFTP */
/* #undef LIBCURL_PROTOCOL_TFTP */
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Name of package */
#define PACKAGE "ccminer"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "ccminer"
/* Define to the home page for this package. */
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
/* Define to the version of this package. */
#define PACKAGE_VERSION "2.3.1"
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define curl_free() as free() if our version of curl lacks curl_free. */
/* #undef curl_free */
/* Define to `unsigned int' if <sys/types.h> does not define. */
//#define size_t unsigned int
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
#define HAVE_STRUCT_TIMESPEC
#endif
+3
View File
@@ -23,6 +23,9 @@
#ifdef _MSC_VER
#define inline __inline
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
#define HAVE_STRUCT_TIMESPEC
#endif
#endif
#ifdef __cplusplus
Binary file not shown.
+1197 -193
View File
File diff suppressed because it is too large. Load diff
+371 -2
View File
@@ -1,2 +1,371 @@
/* todo: stripped version... or not */
#include "nvapi.h"
#pragma once
#define NVAPI_INTERNAL
#include "nvapi.h"
NvAPI_Status nvapi_dll_init();
typedef struct {
NvU32 version;
NvU8 valid;
NvU8 count;
struct
{
NvU32 pstate; // Assumption
NvU32 unknown1[2];
NvU32 min_power;
NvU32 unknown2[2];
NvU32 def_power;
NvU32 unknown3[2];
NvU32 max_power;
NvU32 unknown4; // 0
} entries[4];
} NVAPI_GPU_POWER_INFO;
#define NVAPI_GPU_POWER_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_INFO, 1)
typedef struct {
NvU32 version;
NvU32 flags;
struct {
NvU32 unknown1;
NvU32 unknown2;
NvU32 power; // percent * 1000
NvU32 unknown4;
} entries[4];
} NVAPI_GPU_POWER_STATUS;
#define NVAPI_GPU_POWER_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_STATUS, 1)
typedef struct {
NvU32 version;
NvU32 count;
struct {
NvU32 unknown1;
NvU32 unknown2;
NvU32 power; // unsure ?? 85536 to 95055 on 1080, 104825+ on 970
NvU32 unknown4;
} entries[4];
} NVAPI_GPU_POWER_TOPO;
#define NVAPI_GPU_POWER_TOPO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_POWER_TOPO, 1)
typedef struct {
NvU32 version;
NvU32 flags;
struct {
NvU32 controller;
NvU32 unknown;
NvS32 min_temp;
NvS32 def_temp;
NvS32 max_temp;
NvU32 defaultFlags;
} entries[4];
} NVAPI_GPU_THERMAL_INFO;
#define NVAPI_GPU_THERMAL_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_THERMAL_INFO, 2)
typedef struct {
NvU32 version;
NvU32 flags;
struct {
NvU32 controller;
NvU32 value;
NvU32 flags;
} entries[4];
} NVAPI_GPU_THERMAL_LIMIT;
#define NVAPI_GPU_THERMAL_LIMIT_VER MAKE_NVAPI_VERSION(NVAPI_GPU_THERMAL_LIMIT, 2)
// Maxwell gpu core voltage reading
typedef struct {
NvU32 version;
NvU32 flags;
NvU32 count; // unsure
NvU32 unknown;
NvU32 value_uV;
NvU32 buf1[30];
} NVAPI_VOLT_STATUS; // 140 bytes (1-008c)
#define NVAPI_VOLT_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_VOLT_STATUS, 1)
// Pascal gpu core voltage reading
typedef struct {
NvU32 version;
NvU32 flags;
NvU32 nul[8];
NvU32 value_uV;
NvU32 buf1[8];
} NVAPI_VOLTAGE_STATUS; // 76 bytes (1-004c)
#define NVAPI_VOLTAGE_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_VOLTAGE_STATUS, 1)
typedef struct {
NvU32 version;
NvU32 numClocks; // unsure
NvU32 nul[8];
struct {
NvU32 a;
NvU32 clockType;
NvU32 c;
NvU32 d;
NvU32 e;
NvU32 f;
NvU32 g;
NvU32 h;
NvU32 i;
NvU32 j;
NvS32 rangeMax;
NvS32 rangeMin;
NvS32 tempMax; // ? unsure
NvU32 n;
NvU32 o;
NvU32 p;
NvU32 q;
NvU32 r;
} entries[32]; // NVAPI_MAX_GPU_CLOCKS ?
} NVAPI_CLOCKS_RANGE; // 2344 bytes
#define NVAPI_CLOCKS_RANGE_VER MAKE_NVAPI_VERSION(NVAPI_CLOCKS_RANGE, 1)
// seems to return a clock table mask
typedef struct {
NvU32 version;
NvU32 mask[4]; // 80 bits mask
NvU32 buf0[8];
struct {
NvU32 a;
NvU32 b;
NvU32 c;
NvU32 d;
NvU32 memDelta; // 1 for mem
NvU32 gpuDelta; // 1 for gpu
} clocks[80 + 23];
NvU32 buf1[916];
} NVAPI_CLOCK_MASKS; // 6188 bytes
#define NVAPI_CLOCK_MASKS_VER MAKE_NVAPI_VERSION(NVAPI_CLOCK_MASKS, 1)
// contains the gpu/mem clocks deltas
typedef struct {
NvU32 version;
NvU32 mask[4]; // 80 bits mask (could be 8x 32bits)
NvU32 buf0[12];
struct {
NvU32 a;
NvU32 b;
NvU32 c;
NvU32 d;
NvU32 e;
NvS32 freqDelta; // 84000 = +84MHz
NvU32 g;
NvU32 h;
NvU32 i;
} gpuDeltas[80];
NvU32 memFilled[23]; // maybe only 4 max
NvS32 memDeltas[23];
NvU32 buf1[1529];
} NVAPI_CLOCK_TABLE; // 9248 bytes
#define NVAPI_CLOCK_TABLE_VER MAKE_NVAPI_VERSION(NVAPI_CLOCK_TABLE, 1)
typedef struct {
NvU32 version;
NvU32 mask[4]; // 80 bits mask
NvU32 buf0[12];
struct {
NvU32 a; // 0
NvU32 freq_kHz;
NvU32 volt_uV;
NvU32 d;
NvU32 e;
NvU32 f;
NvU32 g;
} gpuEntries[80];
struct {
NvU32 a; // 1 for idle values ?
NvU32 freq_kHz;
NvU32 volt_uV;
NvU32 d;
NvU32 e;
NvU32 f;
NvU32 g;
} memEntries[23];
NvU32 buf1[1064];
} NVAPI_VFP_CURVE; // 7208 bytes (1-1c28)
#define NVAPI_VFP_CURVE_VER MAKE_NVAPI_VERSION(NVAPI_VFP_CURVE, 1)
typedef struct {
NvU32 version;
NvS32 percent;
NvU32 pad[8];
} NVAPI_VOLTBOOST_PERCENT; // 40 bytes (1-0028)
#define NVAPI_VOLTBOOST_PERCENT_VER MAKE_NVAPI_VERSION(NVAPI_VOLTBOOST_PERCENT, 1)
typedef struct {
NvU32 version;
NvU32 flags;
NvU32 filled; // 1
struct {
NvU32 volt_uV;
NvU32 unknown;
} entries[128];
// some empty tables then...
NvU32 buf1[3888];
} NVAPI_VOLTAGES_TABLE; // 16588 bytes (1-40cc)
#define NVAPI_VOLTAGES_TABLE_VER MAKE_NVAPI_VERSION(NVAPI_VOLTAGES_TABLE, 1)
typedef struct {
NvU32 version;
NvU32 val1; // 7
NvU32 val2; // 0x3F (63.)
NvU32 pad[16];
} NVAPI_GPU_PERF_INFO; // 76 bytes (1-004c)
#define NVAPI_GPU_PERF_INFO_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_INFO, 1)
typedef struct {
NvU32 version;
NvU32 flags; // 0
NvU64 timeRef; // increment with time
NvU64 val1; // seen 1 4 5 while mining, 16 else
NvU64 val2; // seen 7 and 3
NvU64 values[3]; // increment with time
NvU32 pad[326]; // empty
} NVAPI_GPU_PERF_STATUS; // 1360 bytes (1-0550)
#define NVAPI_GPU_PERF_STATUS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_STATUS, 1)
typedef struct {
NvU32 version;
NvU32 val1; // 4
NvU32 val2; // 2 or 0
NvU32 val3; // 2
NvU32 val4; // 3
NV_GPU_PERF_PSTATE_ID pStateId;
NvU32 val6; // 0 or 2
NvU32 val7; // 4
NvU32 val8; // 0
NvU32 memFreq1; // 405000.
NvU32 memFreq2; // 405000.
NvU32 memFreqMin;// 101250.
NvU32 memFreqMax;// 486000.
NvU32 zeros[3];
NvU32 gpuFreq1; // 696000. Unsure about those
NvU32 gpuFreq2; // 696000.
NvU32 gpuFreqMin;// 174000.
NvU32 gpuFreqMax;// 658000.
NvU32 pad[2697];
} NVAPI_GPU_PERF_CLOCKS; // 10868 bytes (2-2a74)
#define NVAPI_GPU_PERF_CLOCKS_VER MAKE_NVAPI_VERSION(NVAPI_GPU_PERF_CLOCKS, 2)
typedef struct {
NvU32 version;
NvU32 level;
NvU32 count;
NvU32 pad[339]; // (4-0558)
} NVAPI_COOLER_SETTINGS;
#define NVAPI_COOLER_SETTINGS_VER MAKE_NVAPI_VERSION(NVAPI_COOLER_SETTINGS, 4)
typedef struct {
NvU32 version;
NvU32 level; // 0 = auto ?
NvU32 count; // 1
NvU32 pad[38]; // (1-00a4)
} NVAPI_COOLER_LEVEL;
#define NVAPI_COOLER_LEVEL_VER MAKE_NVAPI_VERSION(NVAPI_COOLER_LEVEL, 1)
NvAPI_Status NvAPI_DLL_GetInterfaceVersionString(NvAPI_ShortString string);
NvAPI_Status NvAPI_DLL_PerfPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_PERF_INFO*); // 409D9841 1-004c
NvAPI_Status NvAPI_DLL_PerfPoliciesGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_PERF_STATUS*); // 3D358A0C 1-0550
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_POWER_INFO*);
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*);
NvAPI_Status NvAPI_DLL_ClientPowerPoliciesSetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_STATUS*);
NvAPI_Status NvAPI_DLL_ClientPowerTopologyGetStatus(NvPhysicalGpuHandle, NVAPI_GPU_POWER_TOPO*); // EDCF624E 1-0048
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesGetInfo(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_INFO*);
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesGetLimit(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_LIMIT*);
NvAPI_Status NvAPI_DLL_ClientThermalPoliciesSetLimit(NvPhysicalGpuHandle, NVAPI_GPU_THERMAL_LIMIT*);
// Pascal GTX only
NvAPI_Status NvAPI_DLL_GetClockBoostRanges(NvPhysicalGpuHandle, NVAPI_CLOCKS_RANGE*);
NvAPI_Status NvAPI_DLL_GetClockBoostMask(NvPhysicalGpuHandle, NVAPI_CLOCK_MASKS*); // 0x507B4B59
NvAPI_Status NvAPI_DLL_GetClockBoostTable(NvPhysicalGpuHandle, NVAPI_CLOCK_TABLE*); // 0x23F1B133
NvAPI_Status NvAPI_DLL_SetClockBoostTable(NvPhysicalGpuHandle, NVAPI_CLOCK_TABLE*); // 0x0733E009
NvAPI_Status NvAPI_DLL_GetVFPCurve(NvPhysicalGpuHandle, NVAPI_VFP_CURVE*); // 0x21537AD4
NvAPI_Status NvAPI_DLL_GetCurrentVoltage(NvPhysicalGpuHandle, NVAPI_VOLTAGE_STATUS*); // 0x465F9BCF 1-004c
NvAPI_Status NvAPI_DLL_GetCoreVoltageBoostPercent(NvPhysicalGpuHandle, NVAPI_VOLTBOOST_PERCENT*);
NvAPI_Status NvAPI_DLL_SetCoreVoltageBoostPercent(NvPhysicalGpuHandle, NVAPI_VOLTBOOST_PERCENT*);
// Maxwell only
NvAPI_Status NvAPI_DLL_GetVoltageDomainsStatus(NvPhysicalGpuHandle, NVAPI_VOLT_STATUS*); // 0xC16C7E2C
NvAPI_Status NvAPI_DLL_GetVoltages(NvPhysicalGpuHandle, NVAPI_VOLTAGES_TABLE*); // 0x7D656244 1-40CC
NvAPI_Status NvAPI_DLL_GetVoltageStep(NvPhysicalGpuHandle, NVAPI_VOLT_STATUS*); // 0x28766157 1-008C unsure of the name
NvAPI_Status NvAPI_DLL_GetCoolerSettings(NvPhysicalGpuHandle, uint32_t, NVAPI_COOLER_SETTINGS*); // 0xDA141340 4-0558
NvAPI_Status NvAPI_DLL_SetCoolerLevels(NvPhysicalGpuHandle, uint32_t, NVAPI_COOLER_LEVEL*); // 0x891FA0AE 1-00A4
NvAPI_Status NvAPI_DLL_RestoreCoolerSettings(NvPhysicalGpuHandle, NVAPI_COOLER_SETTINGS*, uint32_t);
NvAPI_Status NvAPI_DLL_GetSerialNumber(NvPhysicalGpuHandle, NvAPI_ShortString serial);
NvAPI_Status NvAPI_DLL_GetPerfClocks(NvPhysicalGpuHandle, uint32_t num, NVAPI_GPU_PERF_CLOCKS* pClocks); // 2-2A74
//NvAPI_Status NvAPI_DLL_SetPerfClocks(NvPhysicalGpuHandle, uint32_t num, NVAPI_GPU_PERF_CLOCKS* pClocks); // error
//invalid..
//NvAPI_Status NvAPI_DLL_GetPstateClientLimits(NvPhysicalGpuHandle, NV_GPU_PERF_PSTATE_ID, uint32_t* pLimits);
//NvAPI_Status NvAPI_DLL_SetPstateClientLimits(NvPhysicalGpuHandle, NV_GPU_PERF_PSTATE_ID, uint32_t* pLimits);
NvAPI_Status NvAPI_DLL_SetPstates20v1(NvPhysicalGpuHandle handle, NV_GPU_PERF_PSTATES20_INFO_V1 *pSet);
NvAPI_Status NvAPI_DLL_SetPstates20v2(NvPhysicalGpuHandle handle, NV_GPU_PERF_PSTATES20_INFO_V2 *pSet);
NvAPI_Status NvAPI_DLL_Unload();
#define NV_ASSERT(x) { NvAPI_Status ret = x; if(ret != NVAPI_OK) return ret; }
// to reduce stack size, allow to reuse a mem buffer
#define NV_INIT_STRUCT_ON(TYPE, var, mem) { \
var = (TYPE*) mem; \
memset(var, 0, sizeof(TYPE)); \
var->version = TYPE##_VER; \
}
// alloc a struct, need free(var)
#define NV_INIT_STRUCT_ALLOC(TYPE, var) { \
var = (TYPE*) calloc(1, TYPE##_VER & 0xFFFF); \
if (var) var->version = TYPE##_VER; \
}
//! Used in NvAPI_I2CReadEx()
typedef struct
{
NvU32 version;
NvU32 displayMask; // Display Mask of the concerned display.
NvU8 bIsDDCPort; // indicates either the DDC port (TRUE) or the communication port (FALSE) of the concerned display.
NvU8 i2cDevAddress; // address of the I2C slave. The address should be shifted left by one. 0x50 -> 0xA0.
NvU8* pbI2cRegAddress; // I2C target register address. May be NULL, which indicates no register address should be sent.
NvU32 regAddrSize; // size in bytes of target register address. If pbI2cRegAddress is NULL, this field must be 0.
NvU8* pbData; // buffer of data which is to be read or written (depending on the command).
NvU32 cbRead; // bytes to read ??? seems required on write too
NvU32 cbSize; // full size of the data buffer, pbData, to be read or written.
NV_I2C_SPEED i2cSpeedKhz; // target speed of the transaction in (kHz) (Chosen from the enum NV_I2C_SPEED).
NvU8 portId; // portid on which device is connected (remember to set bIsPortIdSet if this value is set)
NvU32 bIsPortIdSet; // set this flag on if and only if portid value is set
} NV_I2C_INFO_EX;
#define NV_I2C_INFO_EX_VER MAKE_NVAPI_VERSION(NV_I2C_INFO_EX,3)
/*
sample evga x64 call (struct of 0x40 bytes)
ReadEx
$ ==> 40 00 03 00 00 00 00 00 00 40 00 00 00 00 00 00
$+10 58 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
$+20 C0 F9 2B 00 00 00 00 00 02 00 00 00 FF FF 00 00
$+30 00 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00
$ ==> 40 00 03 00 00 00 00 00 00 10 00 00 00 00 00 00
$+10 68 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
$+20 C0 F9 2B 00 00 00 00 00 01 00 00 00 FF FF 00 00
$+30 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00
00000000002BF968 > 75 83 CF 3F 01 00 00 00
00000000002BF9C0 > 0
WriteEx
$ ==> 40 00 03 00 00 00 00 00 00 8C 00 00 00 00 00 00
$+10 30 F9 2B 00 00 00 00 00 01 00 00 00 00 00 00 00
$+20 38 F9 2B 00 00 00 00 00 02 00 00 00 FF FF 00 00
$+30 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00
00000000002BF930 > D1 00 00 00 00 00 00 00
00000000002BF938 > 38 00 00 00 00 00 00 00
*/
NvAPI_Status NvAPI_DLL_I2CReadEx(NvPhysicalGpuHandle, NV_I2C_INFO_EX*, NvU32*);
NvAPI_Status NvAPI_DLL_I2CWriteEx(NvPhysicalGpuHandle, NV_I2C_INFO_EX*, NvU32*);
+78 -6
View File
@@ -1,3 +1,36 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#pragma once
#include"nvapi_lite_salstart.h"
#pragma pack(push,8)
@@ -20,6 +53,7 @@ extern "C" {
#endif
#endif
/* 64-bit types for compilers that support them, plus some obsolete variants */
#if defined(__GNUC__) || defined(__arm) || defined(__IAR_SYSTEMS_ICC__) || defined(__ghs__) || defined(_WIN64)
typedef unsigned long long NvU64; /* 0 to 18446744073709551615 */
@@ -36,6 +70,7 @@ typedef signed long NvS32; /* -2147483648 to 2147483647 */
typedef signed int NvS32; /* -2147483648 to 2147483647 */
#endif
#ifndef __unix
// mac os 32-bit still needs this
#if ( (defined(macintosh) && defined(__LP64__) && (__NVAPI_RESERVED0__)) || \
(!defined(macintosh) && defined(__NVAPI_RESERVED0__)) )
@@ -43,12 +78,22 @@ typedef unsigned int NvU32; /* 0 to 4294967295 */
#else
typedef unsigned long NvU32; /* 0 to 4294967295 */
#endif
#else
typedef unsigned int NvU32; /* 0 to 4294967295 */
#endif
typedef unsigned long temp_NvU32; /* 0 to 4294967295 */
typedef signed short NvS16;
typedef unsigned short NvU16;
typedef unsigned char NvU8;
typedef signed char NvS8;
/* Boolean type */
typedef NvU8 NvBool;
#define NV_TRUE ((NvBool)(0 == 0))
#define NV_FALSE ((NvBool)(0 != 0))
typedef struct _NV_RECT
{
NvU32 left;
@@ -299,11 +344,20 @@ typedef enum _NvAPI_Status
NVAPI_TIMEOUT = -191, //!< Requested operation timed out
NVAPI_GPU_WORKSTATION_FEATURE_INCOMPLETE = -192, //!< The requested workstation feature set has incomplete driver internal allocation resources
NVAPI_STEREO_INIT_ACTIVATION_NOT_DONE = -193, //!< Call failed because InitActivation was not called.
NVAPI_SYNC_NOT_ACTIVE = -194, //!< The requested action cannot be performed without Sync being enabled.
NVAPI_SYNC_MASTER_NOT_FOUND = -195, //!< The requested action cannot be performed without Sync Master being enabled.
NVAPI_INVALID_SYNC_TOPOLOGY = -196, //!< Invalid displays passed in the NV_GSYNC_DISPLAY pointer.
NVAPI_SYNC_NOT_ACTIVE = -194, //!< The requested action cannot be performed without Sync being enabled.
NVAPI_SYNC_MASTER_NOT_FOUND = -195, //!< The requested action cannot be performed without Sync Master being enabled.
NVAPI_INVALID_SYNC_TOPOLOGY = -196, //!< Invalid displays passed in the NV_GSYNC_DISPLAY pointer.
NVAPI_ECID_SIGN_ALGO_UNSUPPORTED = -197, //!< The specified signing algorithm is not supported. Either an incorrect value was entered or the current installed driver/hardware does not support the input value.
NVAPI_ECID_KEY_VERIFICATION_FAILED = -198, //!< The encrypted public key verification has failed.
NVAPI_ECID_KEY_VERIFICATION_FAILED = -198, //!< The encrypted public key verification has failed.
NVAPI_FIRMWARE_OUT_OF_DATE = -199, //!< The device's firmware is out of date.
NVAPI_FIRMWARE_REVISION_NOT_SUPPORTED = -200, //!< The device's firmware is not supported.
NVAPI_LICENSE_CALLER_AUTHENTICATION_FAILED = -201, //!< The caller is not authorized to modify the License.
NVAPI_D3D_DEVICE_NOT_REGISTERED = -202, //!< The user tried to use a deferred context without registering the device first
NVAPI_RESOURCE_NOT_ACQUIRED = -203, //!< Head or SourceId was not reserved for the VR Display before doing the Modeset.
NVAPI_TIMING_NOT_SUPPORTED = -204, //!< Provided timing is not supported.
NVAPI_HDCP_ENCRYPTION_FAILED = -205, //!< HDCP Encryption Failed for the device. Would be applicable when the device is HDCP Capable.
NVAPI_PCLK_LIMITATION_FAILED = -206, //!< Provided mode is over sink device pclk limitation.
NVAPI_NO_CONNECTOR_FOUND = -207, //!< No connector on GPU found.
} NvAPI_Status;
///////////////////////////////////////////////////////////////////////////////
@@ -352,9 +406,23 @@ typedef struct
} NV_DISPLAY_DRIVER_MEMORY_INFO_V2;
//! \ingroup driverapi
//! Used in NvAPI_GPU_GetMemoryInfo().
typedef struct
{
NvU32 version; //!< Version info
NvU32 dedicatedVideoMemory; //!< Size(in kb) of the physical framebuffer.
NvU32 availableDedicatedVideoMemory; //!< Size(in kb) of the available physical framebuffer for allocating video memory surfaces.
NvU32 systemVideoMemory; //!< Size(in kb) of system memory the driver allocates at load time.
NvU32 sharedSystemMemory; //!< Size(in kb) of shared system memory that driver is allowed to commit for surfaces across all allocations.
NvU32 curAvailableDedicatedVideoMemory; //!< Size(in kb) of the current available physical framebuffer for allocating video memory surfaces.
NvU32 dedicatedVideoMemoryEvictionsSize; //!< Size(in kb) of the total size of memory released as a result of the evictions.
NvU32 dedicatedVideoMemoryEvictionCount; //!< Indicates the number of eviction events that caused an allocation to be removed from dedicated video memory to free GPU
//!< video memory to make room for other allocations.
} NV_DISPLAY_DRIVER_MEMORY_INFO_V3;
//! \ingroup driverapi
typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V2 NV_DISPLAY_DRIVER_MEMORY_INFO;
typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V3 NV_DISPLAY_DRIVER_MEMORY_INFO;
//! \ingroup driverapi
//! Macro for constructing the version field of NV_DISPLAY_DRIVER_MEMORY_INFO_V1
@@ -365,7 +433,11 @@ typedef NV_DISPLAY_DRIVER_MEMORY_INFO_V2 NV_DISPLAY_DRIVER_MEMORY_INFO;
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER_2 MAKE_NVAPI_VERSION(NV_DISPLAY_DRIVER_MEMORY_INFO_V2,2)
//! \ingroup driverapi
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER NV_DISPLAY_DRIVER_MEMORY_INFO_VER_2
//! Macro for constructing the version field of NV_DISPLAY_DRIVER_MEMORY_INFO_V3
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER_3 MAKE_NVAPI_VERSION(NV_DISPLAY_DRIVER_MEMORY_INFO_V3,3)
//! \ingroup driverapi
#define NV_DISPLAY_DRIVER_MEMORY_INFO_VER NV_DISPLAY_DRIVER_MEMORY_INFO_VER_3
+37
View File
@@ -1,3 +1,36 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#pragma once
#include"nvapi_lite_salstart.h"
#include"nvapi_lite_common.h"
@@ -29,6 +62,10 @@ typedef enum
//! argument (D3D_FEATURE_LEVEL supported by the device) that the function fills in. This argument
//! can contain -1 (NVAPI_DEVICE_FEATURE_LEVEL_NULL), if the requested featureLevel is less than DirecX 10.0.
//!
//! NOTE: When NvAPI_D3D11_CreateDevice is called with 10+ feature level we have an issue on few set of
//! tesla hardware (G80/G84/G86/G92/G94/G96) which does not support all feature level 10+ functionality
//! e.g. calling driver with mismatch between RenderTarget and Depth Buffer. App developers should
//! take into consideration such limitation when using NVAPI on such tesla hardwares.
//! SUPPORTED OS: Windows Vista and higher
//!
//!
+33
View File
@@ -1,3 +1,36 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#ifndef __NVAPI_EMPTY_SAL
#ifdef __nvapi_undef__ecount
#undef __ecount
+34
View File
@@ -1,3 +1,37 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
// ====================================================
// SAL related support
// ====================================================
+42 -1
View File
@@ -1,3 +1,37 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#pragma once
#include"nvapi_lite_salstart.h"
#include"nvapi_lite_common.h"
@@ -93,6 +127,7 @@ typedef enum _NVAPI_D3D_SETRESOURCEHINT_CATEGORY
//
// NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC:
// NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USING:
//! \ingroup dx
@@ -101,9 +136,15 @@ typedef enum _NVAPI_D3D_SETRESOURCEHINT_CATEGORY
//! Default value: 0 \n
//! Explanation: If the value is 1, the driver will not track any rendering operations that would mark this resource as dirty,
//! avoiding any form of synchronization across frames rendered in parallel in multiple GPUs in AFR mode.
//!
//! NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USAGE: Valid values : 0 or 1 \n
//! Default value: 0 \n
//! Explanation: If the value is 1, the driver will try to perform operations which involved target resource in broadcast,
//! where its possible. Hint is static and must be set before resource starts using.
typedef enum _NVAPI_D3D_SETRESOURCEHINT_SLI
{
NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC = 1
NVAPI_D3D_SRH_SLI_APP_CONTROLLED_INTERFRAME_CONTENT_SYNC = 1,
NVAPI_D3D_SRH_SLI_ASK_FOR_BROADCAST_USAGE = 2
} NVAPI_D3D_SETRESOURCEHINT_SLI;
//! \ingroup dx
+34
View File
@@ -1,3 +1,37 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#pragma once
#include"nvapi_lite_salstart.h"
#include"nvapi_lite_common.h"
+34
View File
@@ -1,3 +1,37 @@
/************************************************************************************************************************************\
|* *|
|* Copyright © 2012 NVIDIA Corporation. All rights reserved. *|
|* *|
|* NOTICE TO USER: *|
|* *|
|* This software is subject to NVIDIA ownership rights under U.S. and international Copyright laws. *|
|* *|
|* This software and the information contained herein are PROPRIETARY and CONFIDENTIAL to NVIDIA *|
|* and are being provided solely under the terms and conditions of an NVIDIA software license agreement. *|
|* Otherwise, you have no rights to use or access this software in any manner. *|
|* *|
|* If not covered by the applicable NVIDIA software license agreement: *|
|* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. *|
|* IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. *|
|* NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *|
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. *|
|* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, *|
|* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, *|
|* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
|* *|
|* U.S. Government End Users. *|
|* This software is a "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
|* consisting of "commercial computer software" and "commercial computer software documentation" *|
|* as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government only as a commercial end item. *|
|* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
|* all U.S. Government End Users acquire the software with only those rights set forth herein. *|
|* *|
|* Any use of this software in individual and commercial software must include, *|
|* in the user documentation and internal comments to the code, *|
|* the above Disclaimer (as applicable) and U.S. Government End Users Notice. *|
|* *|
\************************************************************************************************************************************/
#pragma once
#include"nvapi_lite_salstart.h"
#include"nvapi_lite_common.h"
Binary file not shown.
+4
View File
@@ -37,6 +37,10 @@
#if !defined( PTHREAD_H )
#define PTHREAD_H
#if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900
#define HAVE_STRUCT_TIMESPEC
#endif
/*
* See the README file for an explanation of the pthreads-win32 version
* numbering scheme and how the DLL is named etc.
+69
View File
@@ -0,0 +1,69 @@
/**
* Meant to improve clang 4 / macos compatibility (untested)
*/
#ifndef PTHREAD_BARRIER_H_
#define PTHREAD_BARRIER_H_
#include <pthread.h>
#include <errno.h>
typedef int pthread_barrierattr_t;
typedef struct
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int tripCount;
} pthread_barrier_t;
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
{
if(count == 0)
{
errno = EINVAL;
return -1;
}
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
{
return -1;
}
if(pthread_cond_init(&barrier->cond, 0) < 0)
{
pthread_mutex_destroy(&barrier->mutex);
return -1;
}
barrier->tripCount = count;
barrier->count = 0;
return 0;
}
int pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_cond_destroy(&barrier->cond);
pthread_mutex_destroy(&barrier->mutex);
return 0;
}
int pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->tripCount)
{
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
pthread_mutex_unlock(&barrier->mutex);
return 0;
}
}
#endif // PTHREAD_BARRIER_H_
Regular → Executable
+347 -310
View File
@@ -1,310 +1,347 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-01-04.17; # UTC
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
# Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l*)
lib=${1#-l}
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
set x "$@" "$dir/$lib.dll.lib"
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
set x "$@" "$dir/$lib.lib"
break
fi
done
IFS=$save_IFS
test "$found" != yes && set x "$@" "$lib.lib"
shift
;;
-L*)
func_file_conv "${1#-L}"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-10-14.11; # UTC
# Copyright (C) 1999-2013 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
Vendored Regular → Executable
+332 -300
View File
@@ -1,14 +1,12 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
# Free Software Foundation, Inc.
# Copyright 1992-2013 Free Software Foundation, Inc.
timestamp='2008-01-23'
timestamp='2013-06-10'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
@@ -17,26 +15,22 @@ timestamp='2008-01-23'
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Originally written by Per Bothner <per@bothner.com>.
# Please send patches to <config-patches@gnu.org>. Submit a context
# diff and a properly formatted ChangeLog entry.
# the same distribution terms that you use for the rest of that
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
# Originally written by Per Bothner.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit build system type.
# You can get the latest version of this script from:
# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
#
# Please send patches with a ChangeLog entry to config-patches@gnu.org.
me=`echo "$0" | sed -e 's,.*/,,'`
@@ -56,8 +50,7 @@ version="\
GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright 1992-2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -139,12 +132,33 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
case "${UNAME_SYSTEM}" in
Linux|GNU|GNU/*)
# If the system lacks a compiler, then just pick glibc.
# We could probably try harder.
LIBC=gnu
eval $set_cc_for_build
cat <<-EOF > $dummy.c
#include <features.h>
#if defined(__UCLIBC__)
LIBC=uclibc
#elif defined(__dietlibc__)
LIBC=dietlibc
#else
LIBC=gnu
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
;;
esac
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:NetBSD:*:*)
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
@@ -170,7 +184,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
eval $set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep __ELF__ >/dev/null
| grep -q __ELF__
then
# Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
# Return netbsd for either. FIX?
@@ -180,7 +194,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
fi
;;
*)
os=netbsd
os=netbsd
;;
esac
# The OS release
@@ -201,6 +215,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
echo "${machine}-${os}${release}"
exit ;;
*:Bitrig:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
exit ;;
*:OpenBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
@@ -223,7 +241,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
@@ -269,7 +287,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
exit ;;
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
exitcode=$?
trap '' 0
exit $exitcode ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
@@ -295,12 +316,12 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
echo s390-ibm-zvmoe
exit ;;
*:OS400:*:*)
echo powerpc-ibm-os400
echo powerpc-ibm-os400
exit ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit ;;
arm:riscos:*:*|arm:RISCOS:*:*)
arm*:riscos:*:*|arm*:RISCOS:*:*)
echo arm-unknown-riscos
exit ;;
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
@@ -324,14 +345,33 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
case `/usr/bin/uname -p` in
sparc) echo sparc-icl-nx7; exit ;;
esac ;;
s390x:SunOS:*:*)
echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
echo i386-pc-auroraux${UNAME_RELEASE}
exit ;;
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
eval $set_cc_for_build
SUN_ARCH="i386"
# If there is a compiler, see if it is configured for 64-bit objects.
# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
# This test works for both compilers.
if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
SUN_ARCH="x86_64"
fi
fi
echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
@@ -375,23 +415,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# MiNT. But MiNT is downward compatible to TOS, so this should
# be no problem.
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
exit ;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
m68k:machten:*:*)
echo m68k-apple-machten${UNAME_RELEASE}
exit ;;
@@ -461,8 +501,8 @@ EOF
echo m88k-motorola-sysv3
exit ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
@@ -475,7 +515,7 @@ EOF
else
echo i586-dg-dgux${UNAME_RELEASE}
fi
exit ;;
exit ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit ;;
@@ -532,7 +572,7 @@ EOF
echo rs6000-ibm-aix3.2
fi
exit ;;
*:AIX:*:[456])
*:AIX:*:[4567])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
@@ -575,52 +615,52 @@ EOF
9000/[678][0-9][0-9])
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
esac ;;
esac
esac ;;
esac
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
sed 's/^ //' << EOF >$dummy.c
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
@@ -640,7 +680,7 @@ EOF
# => hppa64-hp-hpux11.23
if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
grep __LP64__ >/dev/null
grep -q __LP64__
then
HP_ARCH="hppa2.0w"
else
@@ -711,22 +751,22 @@ EOF
exit ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit ;;
exit ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit ;;
exit ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit ;;
exit ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit ;;
exit ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
@@ -750,14 +790,14 @@ EOF
exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
@@ -769,34 +809,39 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
case ${UNAME_MACHINE} in
pc98)
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
UNAME_PROCESSOR=`/usr/bin/uname -p`
case ${UNAME_PROCESSOR} in
amd64)
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
exit ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
exit ;;
*:MINGW64*:*)
echo ${UNAME_MACHINE}-pc-mingw64
exit ;;
*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:MSYS*:*)
echo ${UNAME_MACHINE}-pc-msys
exit ;;
i*:windows32*:*)
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
exit ;;
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
*:Interix*:[3456]*)
case ${UNAME_MACHINE} in
*:Interix*:*)
case ${UNAME_MACHINE} in
x86)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
EM64T | authenticamd)
authenticamd | genuineintel | EM64T)
echo x86_64-unknown-interix${UNAME_RELEASE}
exit ;;
IA64)
@@ -806,6 +851,9 @@ EOF
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
exit ;;
8664:Windows_NT:*)
echo x86_64-pc-mks
exit ;;
i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
@@ -826,100 +874,21 @@ EOF
exit ;;
*:GNU:*:*)
# the GNU system
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit ;;
*:GNU/*:*:*)
# other systems with GNU libc and userland
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
exit ;;
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
exit ;;
arm*:Linux:*:*)
eval $set_cc_for_build
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_EABI__
then
echo ${UNAME_MACHINE}-unknown-linux-gnu
else
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
fi
aarch64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
cris:Linux:*:*)
echo cris-axis-linux-gnu
exit ;;
crisv32:Linux:*:*)
echo crisv32-axis-linux-gnu
exit ;;
frv:Linux:*:*)
echo frv-unknown-linux-gnu
exit ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
m32r*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
m68*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
mips:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips
#undef mipsel
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mipsel
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips
#else
CPU=
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
mips64:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef mips64
#undef mips64el
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=mips64el
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=mips64
#else
CPU=
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
or32:Linux:*:*)
echo or32-unknown-linux-gnu
exit ;;
ppc:Linux:*:*)
echo powerpc-unknown-linux-gnu
exit ;;
ppc64:Linux:*:*)
echo powerpc64-unknown-linux-gnu
aarch64_be:Linux:*:*)
UNAME_MACHINE=aarch64_be
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
@@ -930,106 +899,132 @@ EOF
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
esac
objdump --private-headers /bin/sh | grep -q ld.so.1
if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
arc:Linux:*:* | arceb:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
arm*:Linux:*:*)
eval $set_cc_for_build
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_EABI__
then
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
else
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP
then
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
else
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
fi
fi
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
cris:Linux:*:*)
echo ${UNAME_MACHINE}-axis-linux-${LIBC}
exit ;;
crisv32:Linux:*:*)
echo ${UNAME_MACHINE}-axis-linux-${LIBC}
exit ;;
frv:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
hexagon:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
i*86:Linux:*:*)
echo ${UNAME_MACHINE}-pc-linux-${LIBC}
exit ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
m32r*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
m68*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
mips:Linux:*:* | mips64:Linux:*:*)
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#undef CPU
#undef ${UNAME_MACHINE}
#undef ${UNAME_MACHINE}el
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=${UNAME_MACHINE}el
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=${UNAME_MACHINE}
#else
CPU=
#endif
#endif
EOF
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
;;
or1k:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
or32:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
padre:Linux:*:*)
echo sparc-unknown-linux-${LIBC}
exit ;;
parisc64:Linux:*:* | hppa64:Linux:*:*)
echo hppa64-unknown-linux-${LIBC}
exit ;;
parisc:Linux:*:* | hppa:Linux:*:*)
# Look for CPU level
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
PA7*) echo hppa1.1-unknown-linux-gnu ;;
PA8*) echo hppa2.0-unknown-linux-gnu ;;
*) echo hppa-unknown-linux-gnu ;;
PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
*) echo hppa-unknown-linux-${LIBC} ;;
esac
exit ;;
parisc64:Linux:*:* | hppa64:Linux:*:*)
echo hppa64-unknown-linux-gnu
ppc64:Linux:*:*)
echo powerpc64-unknown-linux-${LIBC}
exit ;;
ppc:Linux:*:*)
echo powerpc-unknown-linux-${LIBC}
exit ;;
ppc64le:Linux:*:*)
echo powerpc64le-unknown-linux-${LIBC}
exit ;;
ppcle:Linux:*:*)
echo powerpcle-unknown-linux-${LIBC}
exit ;;
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux
echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
exit ;;
sh64*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
tile*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
echo ${UNAME_MACHINE}-dec-linux-${LIBC}
exit ;;
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
xtensa*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
i*86:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us. cd to the root directory to prevent
# problems with other programs or directories called `ld' in the path.
# Set LC_ALL=C to ensure ld outputs messages in English.
ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
| sed -ne '/supported targets:/!d
s/[ ][ ]*/ /g
s/.*supported targets: *//
s/ .*//
p'`
case "$ld_supported_targets" in
elf32-i386)
TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
;;
a.out-i386-linux)
echo "${UNAME_MACHINE}-pc-linux-gnuaout"
exit ;;
coff-i386)
echo "${UNAME_MACHINE}-pc-linux-gnucoff"
exit ;;
"")
# Either a pre-BFD a.out linker (linux-gnuoldld) or
# one that does not give us useful --help.
echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
exit ;;
esac
# Determine whether the default compiler is a.out or elf
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
#include <features.h>
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
LIBC=gnu
# else
LIBC=gnulibc1
# endif
# else
LIBC=gnulibc1
# endif
#else
#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
LIBC=gnu
#else
LIBC=gnuaout
#endif
#endif
#ifdef __dietlibc__
LIBC=dietlibc
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^LIBC/{
s: ::g
p
}'`"
test x"${LIBC}" != x && {
echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
exit
}
test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
# earlier versions are messed up and put the nodename in both
@@ -1037,11 +1032,11 @@ EOF
echo i386-sequent-sysv4
exit ;;
i*86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit ;;
i*86:OS/2:*:*)
@@ -1058,7 +1053,7 @@ EOF
i*86:syllable:*:*)
echo ${UNAME_MACHINE}-pc-syllable
exit ;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit ;;
i*86:*DOS:*:*)
@@ -1073,7 +1068,7 @@ EOF
fi
exit ;;
i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6.
# UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
@@ -1101,10 +1096,13 @@ EOF
exit ;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i386.
echo i386-pc-msdosdjgpp
exit ;;
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# Note: whatever this is, it MUST be the same as what config.sub
# prints for the "djgpp" host, or else GDB configury will decide that
# this is a cross-build.
echo i586-pc-msdosdjgpp
exit ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit ;;
@@ -1139,8 +1137,18 @@ EOF
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
NCR*:*:4.2:* | MPRAS*:*:4.2:*)
OS_REL='.3'
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3${OS_REL}; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; }
/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
echo m68k-unknown-lynxos${UNAME_RELEASE}
exit ;;
@@ -1153,7 +1161,7 @@ EOF
rs6000:LynxOS:2.*:*)
echo rs6000-unknown-lynxos${UNAME_RELEASE}
exit ;;
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
echo powerpc-unknown-lynxos${UNAME_RELEASE}
exit ;;
SM[BE]S:UNIX_SV:*:*)
@@ -1173,10 +1181,10 @@ EOF
echo ns32k-sni-sysv
fi
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
@@ -1202,11 +1210,11 @@ EOF
exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit ;;
exit ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit ;;
@@ -1216,6 +1224,12 @@ EOF
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
echo i586-pc-beos
exit ;;
BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
echo i586-pc-haiku
exit ;;
x86_64:Haiku:*:*)
echo x86_64-unknown-haiku
exit ;;
SX-4:SUPER-UX:*:*)
echo sx4-nec-superux${UNAME_RELEASE}
exit ;;
@@ -1242,9 +1256,21 @@ EOF
exit ;;
*:Darwin:*:*)
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
case $UNAME_PROCESSOR in
unknown) UNAME_PROCESSOR=powerpc ;;
esac
eval $set_cc_for_build
if test "$UNAME_PROCESSOR" = unknown ; then
UNAME_PROCESSOR=powerpc
fi
if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
case $UNAME_PROCESSOR in
i386) UNAME_PROCESSOR=x86_64 ;;
powerpc) UNAME_PROCESSOR=powerpc64 ;;
esac
fi
fi
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
exit ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
@@ -1258,7 +1284,10 @@ EOF
*:QNX:*:4*)
echo i386-pc-qnx
exit ;;
NSE-?:NONSTOP_KERNEL:*:*)
NEO-?:NONSTOP_KERNEL:*:*)
echo neo-tandem-nsk${UNAME_RELEASE}
exit ;;
NSE-*:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
NSR-?:NONSTOP_KERNEL:*:*)
@@ -1303,13 +1332,13 @@ EOF
echo pdp10-unknown-its
exit ;;
SEI:*:*:SEIUX)
echo mips-sei-seiux${UNAME_RELEASE}
echo mips-sei-seiux${UNAME_RELEASE}
exit ;;
*:DragonFly:*:*)
echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
*:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null`
UNAME_MACHINE=`(uname -p) 2>/dev/null`
case "${UNAME_MACHINE}" in
A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;;
@@ -1324,11 +1353,14 @@ EOF
i*86:rdos:*:*)
echo ${UNAME_MACHINE}-pc-rdos
exit ;;
i*86:AROS:*:*)
echo ${UNAME_MACHINE}-pc-aros
exit ;;
x86_64:VMkernel:*:*)
echo ${UNAME_MACHINE}-unknown-esx
exit ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
eval $set_cc_for_build
cat >$dummy.c <<EOF
#ifdef _SEQUENT_
@@ -1346,11 +1378,11 @@ main ()
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
"4"
#else
""
""
#endif
); exit (0);
); exit (0);
#endif
#endif
+13 -9
View File
@@ -1,10 +1,10 @@
AC_INIT([ccminer], [1.6.6-dev])
AC_INIT([ccminer], [2.3.1], [], [ccminer], [http://github.com/lbryio/ccminer])
AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([ccminer.cpp])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_HEADERS([cpuminer-config.h])
AC_CONFIG_HEADERS([ccminer-config.h])
dnl Make sure anyone changing configure.ac/Makefile.am has a clue
AM_MAINTAINER_MODE
@@ -63,6 +63,10 @@ case $target in
PTHREAD_FLAGS=""
WS2_LIBS="-lws2_32"
;;
*86*-apple-darwin*)
have_osx=true
PTHREAD_FLAGS=""
;;
esac
AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true)
@@ -73,17 +77,12 @@ AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread",
))))
AC_CHECK_LIB([z],[gzopen], [], [])
AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])])
AC_CHECK_LIB([ssl],[SSL_free], [], [AC_MSG_ERROR([OpenSSL library required])])
AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])])
# libpci-dev (to get vendor name)
PCILIB=""; PCIFLAGS=""
AC_CHECK_LIB([pci],[pci_alloc], PCILIB="-lpci"; PCIFLAGS="-DHAVE_PCIDEV", [])
AC_SUBST(PCILIB)
AC_SUBST(PCIFLAGS)
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
AM_CONDITIONAL([HAVE_OSX], [test x$have_osx = xtrue])
AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue])
AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue])
@@ -117,6 +116,11 @@ else
SUFFIX=""
fi
if test x$have_osx = xtrue
then
SUFFIX=""
fi
dnl Setup CUDA paths
AC_ARG_WITH([cuda],
[ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]])
+3 -7
View File
@@ -1,11 +1,7 @@
# possible additional CUDA_CFLAGS
#-gencode=arch=compute_50,code=\"sm_50,compute_50\"
#-gencode=arch=compute_35,code=\"sm_35,compute_35\"
#-gencode=arch=compute_30,code=\"sm_30,compute_30\"
#--ptxas-options=\"-v -dlcm=cg\""
# To change the cuda arch, edit Makefile.am and run ./build.sh
extracflags="-march=native -D_REENTRANT -falign-functions=16 -falign-jumps=16 -falign-labels=16"
CUDA_CFLAGS="-O3 -lineno -Xcompiler -Wall" ./configure CXXFLAGS="-O3 $extracflags" --with-cuda=/usr/local/cuda --with-nvml=libnvidia-ml.so
CUDA_CFLAGS="-O3 -lineno -Xcompiler -Wall -D_FORCE_INLINES" \
./configure CXXFLAGS="-O3 $extracflags" --with-cuda=/usr/local/cuda --with-nvml=libnvidia-ml.so
+170
View File
@@ -0,0 +1,170 @@
/*
---------------------------------------------------------------------------
Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
The redistribution and use of this software (with or without changes)
is allowed without the payment of fees or royalties provided that:
source code distributions include the above copyright notice, this
list of conditions and the following disclaimer;
binary distributions include the above copyright notice, this list
of conditions and the following disclaimer in their documentation.
This software is provided 'as is' with no explicit or implied warranties
in respect of its operation, including, but not limited to, correctness
and fitness for purpose.
---------------------------------------------------------------------------
Issue Date: 20/12/2007
*/
#include <stdint.h>
#if defined(__cplusplus)
extern "C"
{
#endif
#define TABLE_ALIGN 32
#define WPOLY 0x011b
#define N_COLS 4
#define AES_BLOCK_SIZE 16
#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2))
#if defined(_MSC_VER)
#define ALIGN __declspec(align(TABLE_ALIGN))
#elif defined(__GNUC__)
#define ALIGN __attribute__ ((aligned(16)))
#else
#define ALIGN
#endif
#define rf1(r,c) (r)
#define word_in(x,c) (*((uint32_t*)(x)+(c)))
#define word_out(x,c,v) (*((uint32_t*)(x)+(c)) = (v))
#define s(x,c) x[c]
#define si(y,x,c) (s(y,c) = word_in(x, c))
#define so(y,x,c) word_out(y, c, s(x,c))
#define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)
#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)
#define round(y,x,k) \
y[0] = (k)[0] ^ (t_fn[0][x[0] & 0xff] ^ t_fn[1][(x[1] >> 8) & 0xff] ^ t_fn[2][(x[2] >> 16) & 0xff] ^ t_fn[3][x[3] >> 24]); \
y[1] = (k)[1] ^ (t_fn[0][x[1] & 0xff] ^ t_fn[1][(x[2] >> 8) & 0xff] ^ t_fn[2][(x[3] >> 16) & 0xff] ^ t_fn[3][x[0] >> 24]); \
y[2] = (k)[2] ^ (t_fn[0][x[2] & 0xff] ^ t_fn[1][(x[3] >> 8) & 0xff] ^ t_fn[2][(x[0] >> 16) & 0xff] ^ t_fn[3][x[1] >> 24]); \
y[3] = (k)[3] ^ (t_fn[0][x[3] & 0xff] ^ t_fn[1][(x[0] >> 8) & 0xff] ^ t_fn[2][(x[1] >> 16) & 0xff] ^ t_fn[3][x[2] >> 24]);
#define to_byte(x) ((x) & 0xff)
#define bval(x,n) to_byte((x) >> (8 * (n)))
#define fwd_var(x,r,c)\
( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
: r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\
: r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
: ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))
#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c))
#define sb_data(w) {\
w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
#define rc_data(w) {\
w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\
w(0x1b), w(0x36) }
#define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \
((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0))
#define h0(x) (x)
#define w0(p) bytes2word(p, 0, 0, 0)
#define w1(p) bytes2word(0, p, 0, 0)
#define w2(p) bytes2word(0, 0, p, 0)
#define w3(p) bytes2word(0, 0, 0, p)
#define u0(p) bytes2word(f2(p), p, p, f3(p))
#define u1(p) bytes2word(f3(p), f2(p), p, p)
#define u2(p) bytes2word(p, f3(p), f2(p), p)
#define u3(p) bytes2word(p, p, f3(p), f2(p))
#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p))
#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p))
#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p))
#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p))
#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))
#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY))
#define f3(x) (f2(x) ^ x)
#define f9(x) (f8(x) ^ x)
#define fb(x) (f8(x) ^ f2(x) ^ x)
#define fd(x) (f8(x) ^ f4(x) ^ x)
#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
#define t_dec(m,n) t_##m##n
#define t_set(m,n) t_##m##n
#define t_use(m,n) t_##m##n
#define d_4(t,n,b,e,f,g,h) ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) }
#define four_tables(x,tab,vf,rf,c) \
(tab[0][bval(vf(x,0,c),rf(0,c))] \
^ tab[1][bval(vf(x,1,c),rf(1,c))] \
^ tab[2][bval(vf(x,2,c),rf(2,c))] \
^ tab[3][bval(vf(x,3,c),rf(3,c))])
d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3);
void aesb_single_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
{
round(((uint32_t*) out), ((uint32_t*) in), ((uint32_t*) expandedKey));
}
void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey)
{
uint32_t b1[4];
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey));
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 1 * N_COLS);
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 2 * N_COLS);
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 3 * N_COLS);
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 4 * N_COLS);
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 5 * N_COLS);
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 6 * N_COLS);
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 7 * N_COLS);
round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 8 * N_COLS);
round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS);
}
#if defined(__cplusplus)
}
#endif
+990
View File
@@ -0,0 +1,990 @@
#define N_COLS 4
#define WPOLY 0x011b
/*
static const __device__ __align__(16) uint32_t d_t_fn[1024] = {
0xa56363c6U, 0x847c7cf8U, 0x997777eeU, 0x8d7b7bf6U, 0x0df2f2ffU, 0xbd6b6bd6U, 0xb16f6fdeU, 0x54c5c591U,
0x50303060U, 0x03010102U, 0xa96767ceU, 0x7d2b2b56U, 0x19fefee7U, 0x62d7d7b5U, 0xe6abab4dU, 0x9a7676ecU,
0x45caca8fU, 0x9d82821fU, 0x40c9c989U, 0x877d7dfaU, 0x15fafaefU, 0xeb5959b2U, 0xc947478eU, 0x0bf0f0fbU,
0xecadad41U, 0x67d4d4b3U, 0xfda2a25fU, 0xeaafaf45U, 0xbf9c9c23U, 0xf7a4a453U, 0x967272e4U, 0x5bc0c09bU,
0xc2b7b775U, 0x1cfdfde1U, 0xae93933dU, 0x6a26264cU, 0x5a36366cU, 0x413f3f7eU, 0x02f7f7f5U, 0x4fcccc83U,
0x5c343468U, 0xf4a5a551U, 0x34e5e5d1U, 0x08f1f1f9U, 0x937171e2U, 0x73d8d8abU, 0x53313162U, 0x3f15152aU,
0x0c040408U, 0x52c7c795U, 0x65232346U, 0x5ec3c39dU, 0x28181830U, 0xa1969637U, 0x0f05050aU, 0xb59a9a2fU,
0x0907070eU, 0x36121224U, 0x9b80801bU, 0x3de2e2dfU, 0x26ebebcdU, 0x6927274eU, 0xcdb2b27fU, 0x9f7575eaU,
0x1b090912U, 0x9e83831dU, 0x742c2c58U, 0x2e1a1a34U, 0x2d1b1b36U, 0xb26e6edcU, 0xee5a5ab4U, 0xfba0a05bU,
0xf65252a4U, 0x4d3b3b76U, 0x61d6d6b7U, 0xceb3b37dU, 0x7b292952U, 0x3ee3e3ddU, 0x712f2f5eU, 0x97848413U,
0xf55353a6U, 0x68d1d1b9U, 0x00000000U, 0x2cededc1U, 0x60202040U, 0x1ffcfce3U, 0xc8b1b179U, 0xed5b5bb6U,
0xbe6a6ad4U, 0x46cbcb8dU, 0xd9bebe67U, 0x4b393972U, 0xde4a4a94U, 0xd44c4c98U, 0xe85858b0U, 0x4acfcf85U,
0x6bd0d0bbU, 0x2aefefc5U, 0xe5aaaa4fU, 0x16fbfbedU, 0xc5434386U, 0xd74d4d9aU, 0x55333366U, 0x94858511U,
0xcf45458aU, 0x10f9f9e9U, 0x06020204U, 0x817f7ffeU, 0xf05050a0U, 0x443c3c78U, 0xba9f9f25U, 0xe3a8a84bU,
0xf35151a2U, 0xfea3a35dU, 0xc0404080U, 0x8a8f8f05U, 0xad92923fU, 0xbc9d9d21U, 0x48383870U, 0x04f5f5f1U,
0xdfbcbc63U, 0xc1b6b677U, 0x75dadaafU, 0x63212142U, 0x30101020U, 0x1affffe5U, 0x0ef3f3fdU, 0x6dd2d2bfU,
0x4ccdcd81U, 0x140c0c18U, 0x35131326U, 0x2fececc3U, 0xe15f5fbeU, 0xa2979735U, 0xcc444488U, 0x3917172eU,
0x57c4c493U, 0xf2a7a755U, 0x827e7efcU, 0x473d3d7aU, 0xac6464c8U, 0xe75d5dbaU, 0x2b191932U, 0x957373e6U,
0xa06060c0U, 0x98818119U, 0xd14f4f9eU, 0x7fdcdca3U, 0x66222244U, 0x7e2a2a54U, 0xab90903bU, 0x8388880bU,
0xca46468cU, 0x29eeeec7U, 0xd3b8b86bU, 0x3c141428U, 0x79dedea7U, 0xe25e5ebcU, 0x1d0b0b16U, 0x76dbdbadU,
0x3be0e0dbU, 0x56323264U, 0x4e3a3a74U, 0x1e0a0a14U, 0xdb494992U, 0x0a06060cU, 0x6c242448U, 0xe45c5cb8U,
0x5dc2c29fU, 0x6ed3d3bdU, 0xefacac43U, 0xa66262c4U, 0xa8919139U, 0xa4959531U, 0x37e4e4d3U, 0x8b7979f2U,
0x32e7e7d5U, 0x43c8c88bU, 0x5937376eU, 0xb76d6ddaU, 0x8c8d8d01U, 0x64d5d5b1U, 0xd24e4e9cU, 0xe0a9a949U,
0xb46c6cd8U, 0xfa5656acU, 0x07f4f4f3U, 0x25eaeacfU, 0xaf6565caU, 0x8e7a7af4U, 0xe9aeae47U, 0x18080810U,
0xd5baba6fU, 0x887878f0U, 0x6f25254aU, 0x722e2e5cU, 0x241c1c38U, 0xf1a6a657U, 0xc7b4b473U, 0x51c6c697U,
0x23e8e8cbU, 0x7cdddda1U, 0x9c7474e8U, 0x211f1f3eU, 0xdd4b4b96U, 0xdcbdbd61U, 0x868b8b0dU, 0x858a8a0fU,
0x907070e0U, 0x423e3e7cU, 0xc4b5b571U, 0xaa6666ccU, 0xd8484890U, 0x05030306U, 0x01f6f6f7U, 0x120e0e1cU,
0xa36161c2U, 0x5f35356aU, 0xf95757aeU, 0xd0b9b969U, 0x91868617U, 0x58c1c199U, 0x271d1d3aU, 0xb99e9e27U,
0x38e1e1d9U, 0x13f8f8ebU, 0xb398982bU, 0x33111122U, 0xbb6969d2U, 0x70d9d9a9U, 0x898e8e07U, 0xa7949433U,
0xb69b9b2dU, 0x221e1e3cU, 0x92878715U, 0x20e9e9c9U, 0x49cece87U, 0xff5555aaU, 0x78282850U, 0x7adfdfa5U,
0x8f8c8c03U, 0xf8a1a159U, 0x80898909U, 0x170d0d1aU, 0xdabfbf65U, 0x31e6e6d7U, 0xc6424284U, 0xb86868d0U,
0xc3414182U, 0xb0999929U, 0x772d2d5aU, 0x110f0f1eU, 0xcbb0b07bU, 0xfc5454a8U, 0xd6bbbb6dU, 0x3a16162cU,
0x6363c6a5U, 0x7c7cf884U, 0x7777ee99U, 0x7b7bf68dU, 0xf2f2ff0dU, 0x6b6bd6bdU, 0x6f6fdeb1U, 0xc5c59154U,
0x30306050U, 0x01010203U, 0x6767cea9U, 0x2b2b567dU, 0xfefee719U, 0xd7d7b562U, 0xabab4de6U, 0x7676ec9aU,
0xcaca8f45U, 0x82821f9dU, 0xc9c98940U, 0x7d7dfa87U, 0xfafaef15U, 0x5959b2ebU, 0x47478ec9U, 0xf0f0fb0bU,
0xadad41ecU, 0xd4d4b367U, 0xa2a25ffdU, 0xafaf45eaU, 0x9c9c23bfU, 0xa4a453f7U, 0x7272e496U, 0xc0c09b5bU,
0xb7b775c2U, 0xfdfde11cU, 0x93933daeU, 0x26264c6aU, 0x36366c5aU, 0x3f3f7e41U, 0xf7f7f502U, 0xcccc834fU,
0x3434685cU, 0xa5a551f4U, 0xe5e5d134U, 0xf1f1f908U, 0x7171e293U, 0xd8d8ab73U, 0x31316253U, 0x15152a3fU,
0x0404080cU, 0xc7c79552U, 0x23234665U, 0xc3c39d5eU, 0x18183028U, 0x969637a1U, 0x05050a0fU, 0x9a9a2fb5U,
0x07070e09U, 0x12122436U, 0x80801b9bU, 0xe2e2df3dU, 0xebebcd26U, 0x27274e69U, 0xb2b27fcdU, 0x7575ea9fU,
0x0909121bU, 0x83831d9eU, 0x2c2c5874U, 0x1a1a342eU, 0x1b1b362dU, 0x6e6edcb2U, 0x5a5ab4eeU, 0xa0a05bfbU,
0x5252a4f6U, 0x3b3b764dU, 0xd6d6b761U, 0xb3b37dceU, 0x2929527bU, 0xe3e3dd3eU, 0x2f2f5e71U, 0x84841397U,
0x5353a6f5U, 0xd1d1b968U, 0x00000000U, 0xededc12cU, 0x20204060U, 0xfcfce31fU, 0xb1b179c8U, 0x5b5bb6edU,
0x6a6ad4beU, 0xcbcb8d46U, 0xbebe67d9U, 0x3939724bU, 0x4a4a94deU, 0x4c4c98d4U, 0x5858b0e8U, 0xcfcf854aU,
0xd0d0bb6bU, 0xefefc52aU, 0xaaaa4fe5U, 0xfbfbed16U, 0x434386c5U, 0x4d4d9ad7U, 0x33336655U, 0x85851194U,
0x45458acfU, 0xf9f9e910U, 0x02020406U, 0x7f7ffe81U, 0x5050a0f0U, 0x3c3c7844U, 0x9f9f25baU, 0xa8a84be3U,
0x5151a2f3U, 0xa3a35dfeU, 0x404080c0U, 0x8f8f058aU, 0x92923fadU, 0x9d9d21bcU, 0x38387048U, 0xf5f5f104U,
0xbcbc63dfU, 0xb6b677c1U, 0xdadaaf75U, 0x21214263U, 0x10102030U, 0xffffe51aU, 0xf3f3fd0eU, 0xd2d2bf6dU,
0xcdcd814cU, 0x0c0c1814U, 0x13132635U, 0xececc32fU, 0x5f5fbee1U, 0x979735a2U, 0x444488ccU, 0x17172e39U,
0xc4c49357U, 0xa7a755f2U, 0x7e7efc82U, 0x3d3d7a47U, 0x6464c8acU, 0x5d5dbae7U, 0x1919322bU, 0x7373e695U,
0x6060c0a0U, 0x81811998U, 0x4f4f9ed1U, 0xdcdca37fU, 0x22224466U, 0x2a2a547eU, 0x90903babU, 0x88880b83U,
0x46468ccaU, 0xeeeec729U, 0xb8b86bd3U, 0x1414283cU, 0xdedea779U, 0x5e5ebce2U, 0x0b0b161dU, 0xdbdbad76U,
0xe0e0db3bU, 0x32326456U, 0x3a3a744eU, 0x0a0a141eU, 0x494992dbU, 0x06060c0aU, 0x2424486cU, 0x5c5cb8e4U,
0xc2c29f5dU, 0xd3d3bd6eU, 0xacac43efU, 0x6262c4a6U, 0x919139a8U, 0x959531a4U, 0xe4e4d337U, 0x7979f28bU,
0xe7e7d532U, 0xc8c88b43U, 0x37376e59U, 0x6d6ddab7U, 0x8d8d018cU, 0xd5d5b164U, 0x4e4e9cd2U, 0xa9a949e0U,
0x6c6cd8b4U, 0x5656acfaU, 0xf4f4f307U, 0xeaeacf25U, 0x6565caafU, 0x7a7af48eU, 0xaeae47e9U, 0x08081018U,
0xbaba6fd5U, 0x7878f088U, 0x25254a6fU, 0x2e2e5c72U, 0x1c1c3824U, 0xa6a657f1U, 0xb4b473c7U, 0xc6c69751U,
0xe8e8cb23U, 0xdddda17cU, 0x7474e89cU, 0x1f1f3e21U, 0x4b4b96ddU, 0xbdbd61dcU, 0x8b8b0d86U, 0x8a8a0f85U,
0x7070e090U, 0x3e3e7c42U, 0xb5b571c4U, 0x6666ccaaU, 0x484890d8U, 0x03030605U, 0xf6f6f701U, 0x0e0e1c12U,
0x6161c2a3U, 0x35356a5fU, 0x5757aef9U, 0xb9b969d0U, 0x86861791U, 0xc1c19958U, 0x1d1d3a27U, 0x9e9e27b9U,
0xe1e1d938U, 0xf8f8eb13U, 0x98982bb3U, 0x11112233U, 0x6969d2bbU, 0xd9d9a970U, 0x8e8e0789U, 0x949433a7U,
0x9b9b2db6U, 0x1e1e3c22U, 0x87871592U, 0xe9e9c920U, 0xcece8749U, 0x5555aaffU, 0x28285078U, 0xdfdfa57aU,
0x8c8c038fU, 0xa1a159f8U, 0x89890980U, 0x0d0d1a17U, 0xbfbf65daU, 0xe6e6d731U, 0x424284c6U, 0x6868d0b8U,
0x414182c3U, 0x999929b0U, 0x2d2d5a77U, 0x0f0f1e11U, 0xb0b07bcbU, 0x5454a8fcU, 0xbbbb6dd6U, 0x16162c3aU,
0x63c6a563U, 0x7cf8847cU, 0x77ee9977U, 0x7bf68d7bU, 0xf2ff0df2U, 0x6bd6bd6bU, 0x6fdeb16fU, 0xc59154c5U,
0x30605030U, 0x01020301U, 0x67cea967U, 0x2b567d2bU, 0xfee719feU, 0xd7b562d7U, 0xab4de6abU, 0x76ec9a76U,
0xca8f45caU, 0x821f9d82U, 0xc98940c9U, 0x7dfa877dU, 0xfaef15faU, 0x59b2eb59U, 0x478ec947U, 0xf0fb0bf0U,
0xad41ecadU, 0xd4b367d4U, 0xa25ffda2U, 0xaf45eaafU, 0x9c23bf9cU, 0xa453f7a4U, 0x72e49672U, 0xc09b5bc0U,
0xb775c2b7U, 0xfde11cfdU, 0x933dae93U, 0x264c6a26U, 0x366c5a36U, 0x3f7e413fU, 0xf7f502f7U, 0xcc834fccU,
0x34685c34U, 0xa551f4a5U, 0xe5d134e5U, 0xf1f908f1U, 0x71e29371U, 0xd8ab73d8U, 0x31625331U, 0x152a3f15U,
0x04080c04U, 0xc79552c7U, 0x23466523U, 0xc39d5ec3U, 0x18302818U, 0x9637a196U, 0x050a0f05U, 0x9a2fb59aU,
0x070e0907U, 0x12243612U, 0x801b9b80U, 0xe2df3de2U, 0xebcd26ebU, 0x274e6927U, 0xb27fcdb2U, 0x75ea9f75U,
0x09121b09U, 0x831d9e83U, 0x2c58742cU, 0x1a342e1aU, 0x1b362d1bU, 0x6edcb26eU, 0x5ab4ee5aU, 0xa05bfba0U,
0x52a4f652U, 0x3b764d3bU, 0xd6b761d6U, 0xb37dceb3U, 0x29527b29U, 0xe3dd3ee3U, 0x2f5e712fU, 0x84139784U,
0x53a6f553U, 0xd1b968d1U, 0x00000000U, 0xedc12cedU, 0x20406020U, 0xfce31ffcU, 0xb179c8b1U, 0x5bb6ed5bU,
0x6ad4be6aU, 0xcb8d46cbU, 0xbe67d9beU, 0x39724b39U, 0x4a94de4aU, 0x4c98d44cU, 0x58b0e858U, 0xcf854acfU,
0xd0bb6bd0U, 0xefc52aefU, 0xaa4fe5aaU, 0xfbed16fbU, 0x4386c543U, 0x4d9ad74dU, 0x33665533U, 0x85119485U,
0x458acf45U, 0xf9e910f9U, 0x02040602U, 0x7ffe817fU, 0x50a0f050U, 0x3c78443cU, 0x9f25ba9fU, 0xa84be3a8U,
0x51a2f351U, 0xa35dfea3U, 0x4080c040U, 0x8f058a8fU, 0x923fad92U, 0x9d21bc9dU, 0x38704838U, 0xf5f104f5U,
0xbc63dfbcU, 0xb677c1b6U, 0xdaaf75daU, 0x21426321U, 0x10203010U, 0xffe51affU, 0xf3fd0ef3U, 0xd2bf6dd2U,
0xcd814ccdU, 0x0c18140cU, 0x13263513U, 0xecc32fecU, 0x5fbee15fU, 0x9735a297U, 0x4488cc44U, 0x172e3917U,
0xc49357c4U, 0xa755f2a7U, 0x7efc827eU, 0x3d7a473dU, 0x64c8ac64U, 0x5dbae75dU, 0x19322b19U, 0x73e69573U,
0x60c0a060U, 0x81199881U, 0x4f9ed14fU, 0xdca37fdcU, 0x22446622U, 0x2a547e2aU, 0x903bab90U, 0x880b8388U,
0x468cca46U, 0xeec729eeU, 0xb86bd3b8U, 0x14283c14U, 0xdea779deU, 0x5ebce25eU, 0x0b161d0bU, 0xdbad76dbU,
0xe0db3be0U, 0x32645632U, 0x3a744e3aU, 0x0a141e0aU, 0x4992db49U, 0x060c0a06U, 0x24486c24U, 0x5cb8e45cU,
0xc29f5dc2U, 0xd3bd6ed3U, 0xac43efacU, 0x62c4a662U, 0x9139a891U, 0x9531a495U, 0xe4d337e4U, 0x79f28b79U,
0xe7d532e7U, 0xc88b43c8U, 0x376e5937U, 0x6ddab76dU, 0x8d018c8dU, 0xd5b164d5U, 0x4e9cd24eU, 0xa949e0a9U,
0x6cd8b46cU, 0x56acfa56U, 0xf4f307f4U, 0xeacf25eaU, 0x65caaf65U, 0x7af48e7aU, 0xae47e9aeU, 0x08101808U,
0xba6fd5baU, 0x78f08878U, 0x254a6f25U, 0x2e5c722eU, 0x1c38241cU, 0xa657f1a6U, 0xb473c7b4U, 0xc69751c6U,
0xe8cb23e8U, 0xdda17cddU, 0x74e89c74U, 0x1f3e211fU, 0x4b96dd4bU, 0xbd61dcbdU, 0x8b0d868bU, 0x8a0f858aU,
0x70e09070U, 0x3e7c423eU, 0xb571c4b5U, 0x66ccaa66U, 0x4890d848U, 0x03060503U, 0xf6f701f6U, 0x0e1c120eU,
0x61c2a361U, 0x356a5f35U, 0x57aef957U, 0xb969d0b9U, 0x86179186U, 0xc19958c1U, 0x1d3a271dU, 0x9e27b99eU,
0xe1d938e1U, 0xf8eb13f8U, 0x982bb398U, 0x11223311U, 0x69d2bb69U, 0xd9a970d9U, 0x8e07898eU, 0x9433a794U,
0x9b2db69bU, 0x1e3c221eU, 0x87159287U, 0xe9c920e9U, 0xce8749ceU, 0x55aaff55U, 0x28507828U, 0xdfa57adfU,
0x8c038f8cU, 0xa159f8a1U, 0x89098089U, 0x0d1a170dU, 0xbf65dabfU, 0xe6d731e6U, 0x4284c642U, 0x68d0b868U,
0x4182c341U, 0x9929b099U, 0x2d5a772dU, 0x0f1e110fU, 0xb07bcbb0U, 0x54a8fc54U, 0xbb6dd6bbU, 0x162c3a16U,
0xc6a56363U, 0xf8847c7cU, 0xee997777U, 0xf68d7b7bU, 0xff0df2f2U, 0xd6bd6b6bU, 0xdeb16f6fU, 0x9154c5c5U,
0x60503030U, 0x02030101U, 0xcea96767U, 0x567d2b2bU, 0xe719fefeU, 0xb562d7d7U, 0x4de6ababU, 0xec9a7676U,
0x8f45cacaU, 0x1f9d8282U, 0x8940c9c9U, 0xfa877d7dU, 0xef15fafaU, 0xb2eb5959U, 0x8ec94747U, 0xfb0bf0f0U,
0x41ecadadU, 0xb367d4d4U, 0x5ffda2a2U, 0x45eaafafU, 0x23bf9c9cU, 0x53f7a4a4U, 0xe4967272U, 0x9b5bc0c0U,
0x75c2b7b7U, 0xe11cfdfdU, 0x3dae9393U, 0x4c6a2626U, 0x6c5a3636U, 0x7e413f3fU, 0xf502f7f7U, 0x834fccccU,
0x685c3434U, 0x51f4a5a5U, 0xd134e5e5U, 0xf908f1f1U, 0xe2937171U, 0xab73d8d8U, 0x62533131U, 0x2a3f1515U,
0x080c0404U, 0x9552c7c7U, 0x46652323U, 0x9d5ec3c3U, 0x30281818U, 0x37a19696U, 0x0a0f0505U, 0x2fb59a9aU,
0x0e090707U, 0x24361212U, 0x1b9b8080U, 0xdf3de2e2U, 0xcd26ebebU, 0x4e692727U, 0x7fcdb2b2U, 0xea9f7575U,
0x121b0909U, 0x1d9e8383U, 0x58742c2cU, 0x342e1a1aU, 0x362d1b1bU, 0xdcb26e6eU, 0xb4ee5a5aU, 0x5bfba0a0U,
0xa4f65252U, 0x764d3b3bU, 0xb761d6d6U, 0x7dceb3b3U, 0x527b2929U, 0xdd3ee3e3U, 0x5e712f2fU, 0x13978484U,
0xa6f55353U, 0xb968d1d1U, 0x00000000U, 0xc12cededU, 0x40602020U, 0xe31ffcfcU, 0x79c8b1b1U, 0xb6ed5b5bU,
0xd4be6a6aU, 0x8d46cbcbU, 0x67d9bebeU, 0x724b3939U, 0x94de4a4aU, 0x98d44c4cU, 0xb0e85858U, 0x854acfcfU,
0xbb6bd0d0U, 0xc52aefefU, 0x4fe5aaaaU, 0xed16fbfbU, 0x86c54343U, 0x9ad74d4dU, 0x66553333U, 0x11948585U,
0x8acf4545U, 0xe910f9f9U, 0x04060202U, 0xfe817f7fU, 0xa0f05050U, 0x78443c3cU, 0x25ba9f9fU, 0x4be3a8a8U,
0xa2f35151U, 0x5dfea3a3U, 0x80c04040U, 0x058a8f8fU, 0x3fad9292U, 0x21bc9d9dU, 0x70483838U, 0xf104f5f5U,
0x63dfbcbcU, 0x77c1b6b6U, 0xaf75dadaU, 0x42632121U, 0x20301010U, 0xe51affffU, 0xfd0ef3f3U, 0xbf6dd2d2U,
0x814ccdcdU, 0x18140c0cU, 0x26351313U, 0xc32fececU, 0xbee15f5fU, 0x35a29797U, 0x88cc4444U, 0x2e391717U,
0x9357c4c4U, 0x55f2a7a7U, 0xfc827e7eU, 0x7a473d3dU, 0xc8ac6464U, 0xbae75d5dU, 0x322b1919U, 0xe6957373U,
0xc0a06060U, 0x19988181U, 0x9ed14f4fU, 0xa37fdcdcU, 0x44662222U, 0x547e2a2aU, 0x3bab9090U, 0x0b838888U,
0x8cca4646U, 0xc729eeeeU, 0x6bd3b8b8U, 0x283c1414U, 0xa779dedeU, 0xbce25e5eU, 0x161d0b0bU, 0xad76dbdbU,
0xdb3be0e0U, 0x64563232U, 0x744e3a3aU, 0x141e0a0aU, 0x92db4949U, 0x0c0a0606U, 0x486c2424U, 0xb8e45c5cU,
0x9f5dc2c2U, 0xbd6ed3d3U, 0x43efacacU, 0xc4a66262U, 0x39a89191U, 0x31a49595U, 0xd337e4e4U, 0xf28b7979U,
0xd532e7e7U, 0x8b43c8c8U, 0x6e593737U, 0xdab76d6dU, 0x018c8d8dU, 0xb164d5d5U, 0x9cd24e4eU, 0x49e0a9a9U,
0xd8b46c6cU, 0xacfa5656U, 0xf307f4f4U, 0xcf25eaeaU, 0xcaaf6565U, 0xf48e7a7aU, 0x47e9aeaeU, 0x10180808U,
0x6fd5babaU, 0xf0887878U, 0x4a6f2525U, 0x5c722e2eU, 0x38241c1cU, 0x57f1a6a6U, 0x73c7b4b4U, 0x9751c6c6U,
0xcb23e8e8U, 0xa17cddddU, 0xe89c7474U, 0x3e211f1fU, 0x96dd4b4bU, 0x61dcbdbdU, 0x0d868b8bU, 0x0f858a8aU,
0xe0907070U, 0x7c423e3eU, 0x71c4b5b5U, 0xccaa6666U, 0x90d84848U, 0x06050303U, 0xf701f6f6U, 0x1c120e0eU,
0xc2a36161U, 0x6a5f3535U, 0xaef95757U, 0x69d0b9b9U, 0x17918686U, 0x9958c1c1U, 0x3a271d1dU, 0x27b99e9eU,
0xd938e1e1U, 0xeb13f8f8U, 0x2bb39898U, 0x22331111U, 0xd2bb6969U, 0xa970d9d9U, 0x07898e8eU, 0x33a79494U,
0x2db69b9bU, 0x3c221e1eU, 0x15928787U, 0xc920e9e9U, 0x8749ceceU, 0xaaff5555U, 0x50782828U, 0xa57adfdfU,
0x038f8c8cU, 0x59f8a1a1U, 0x09808989U, 0x1a170d0dU, 0x65dabfbfU, 0xd731e6e6U, 0x84c64242U, 0xd0b86868U,
0x82c34141U, 0x29b09999U, 0x5a772d2dU, 0x1e110f0fU, 0x7bcbb0b0U, 0xa8fc5454U, 0x6dd6bbbbU, 0x2c3a1616U
};
*/
#define AS_U32(addr) *((uint32_t*)(addr))
#define AS_U64(addr) *((uint64_t*)(addr))
#define AS_UINT2(addr) *((uint2*)(addr))
#define AS_UINT4(addr) *((uint4*)(addr))
#define AS_UL2(addr) *((ulonglong2*)(addr))
#define t_fn0(x) (sharedMemory[x])
#define t_fn1(x) (sharedMemory[0x100U | (x)])
#define t_fn2(x) (sharedMemory[0x200U | (x)])
#define t_fn3(x) (sharedMemory[0x300U | (x)])
#define round(shared, out, x, k) \
out[0] = (k)[0] ^ (t_fn0(x[0] & 0xff) ^ t_fn1((x[1] >> 8) & 0xff) ^ t_fn2((x[2] >> 16) & 0xff) ^ t_fn3((x[3] >> 24) & 0xff)); \
out[1] = (k)[1] ^ (t_fn0(x[1] & 0xff) ^ t_fn1((x[2] >> 8) & 0xff) ^ t_fn2((x[3] >> 16) & 0xff) ^ t_fn3((x[0] >> 24) & 0xff)); \
out[2] = (k)[2] ^ (t_fn0(x[2] & 0xff) ^ t_fn1((x[3] >> 8) & 0xff) ^ t_fn2((x[0] >> 16) & 0xff) ^ t_fn3((x[1] >> 24) & 0xff)); \
out[3] = (k)[3] ^ (t_fn0(x[3] & 0xff) ^ t_fn1((x[0] >> 8) & 0xff) ^ t_fn2((x[1] >> 16) & 0xff) ^ t_fn3((x[2] >> 24) & 0xff));
#define round_u4(shared, out, in, k) \
((uint32_t*)out)[0] = (k)[0] ^ t_fn0(in[0].x) ^ t_fn1(in[1].y) ^ t_fn2(in[2].z) ^ t_fn3(in[3].w); \
((uint32_t*)out)[1] = (k)[1] ^ t_fn0(in[1].x) ^ t_fn1(in[2].y) ^ t_fn2(in[3].z) ^ t_fn3(in[0].w); \
((uint32_t*)out)[2] = (k)[2] ^ t_fn0(in[2].x) ^ t_fn1(in[3].y) ^ t_fn2(in[0].z) ^ t_fn3(in[1].w); \
((uint32_t*)out)[3] = (k)[3] ^ t_fn0(in[3].x) ^ t_fn1(in[0].y) ^ t_fn2(in[1].z) ^ t_fn3(in[2].w);
#ifdef __INTELLISENSE__
#define __byte_perm(a,b,c) a
#endif
#define OFF32_0(x) (x & 0xFFu)
#define OFF32_1(x) __byte_perm(x, 0x01, 0x5541)
#define OFF32_2(x) __byte_perm(x, 0x02, 0x5542)
#define OFF32_3(x) __byte_perm(x, 0x03, 0x5543)
#define SHARED_0(x) sharedMemory[OFF32_0(x)]
#define SHARED_1(x) sharedMemory[OFF32_1(x)]
#define SHARED_2(x) sharedMemory[OFF32_2(x)]
#define SHARED_3(x) sharedMemory[OFF32_3(x)]
__device__ __forceinline__
void cn_aes_single_round(uint32_t * const sharedMemory, uint32_t * const in, uint32_t * out, uint32_t* expandedKey)
{
asm("// aes_single_round");
out[0] = expandedKey[0] ^ SHARED_0(in[0]) ^ SHARED_1(in[1]) ^ SHARED_2(in[2]) ^ SHARED_3(in[3]);
out[1] = expandedKey[1] ^ SHARED_0(in[1]) ^ SHARED_1(in[2]) ^ SHARED_2(in[3]) ^ SHARED_3(in[0]);
out[2] = expandedKey[2] ^ SHARED_0(in[2]) ^ SHARED_1(in[3]) ^ SHARED_2(in[0]) ^ SHARED_3(in[1]);
out[3] = expandedKey[3] ^ SHARED_0(in[3]) ^ SHARED_1(in[0]) ^ SHARED_2(in[1]) ^ SHARED_3(in[2]);
}
//
#ifdef _WIN64
/* do a mul.wide.u32 to prevent a shl + cvt 32 to 64 on ld.shared [ptr] */
#define OFF8_0(x) (x & 0xFFu) * sizeof(uint32_t)
#define OFF8_1(x) __byte_perm(x, 0x01, 0x5541) * sizeof(uint32_t)
#define OFF8_2(x) __byte_perm(x, 0x02, 0x5542) * sizeof(uint32_t)
#define OFF8_3(x) __byte_perm(x, 0x03, 0x5543) * sizeof(uint32_t)
#else
#define OFF8_0(x) (x & 0xFFu) << 2
#define OFF8_1(x) __byte_perm(x, 0x01, 0x5541) << 2
#define OFF8_2(x) __byte_perm(x, 0x02, 0x5542) << 2
#define OFF8_3(x) __byte_perm(x, 0x03, 0x5543) << 2
#endif
#define SHAR8_0(x) AS_U32(&sharedMemory[OFF8_0(x)])
#define SHAR8_1(x) AS_U32(&sharedMemory[OFF8_1(x)])
#define SHAR8_2(x) AS_U32(&sharedMemory[OFF8_2(x)])
#define SHAR8_3(x) AS_U32(&sharedMemory[OFF8_3(x)])
__device__ __forceinline__
void cn_aes_single_round_b(uint8_t * const sharedMemory, void * const long_state, const uint4 key, uint4 *res)
{
asm("// aes_single_round_b");
uint4 in = AS_UINT4(long_state);
*res = key;
res->x ^= SHAR8_0(in.x) ^ SHAR8_1(in.y) ^ SHAR8_2(in.z) ^ SHAR8_3(in.w);
res->y ^= SHAR8_0(in.y) ^ SHAR8_1(in.z) ^ SHAR8_2(in.w) ^ SHAR8_3(in.x);
res->z ^= SHAR8_0(in.z) ^ SHAR8_1(in.w) ^ SHAR8_2(in.x) ^ SHAR8_3(in.y);
res->w ^= SHAR8_0(in.w) ^ SHAR8_1(in.x) ^ SHAR8_2(in.y) ^ SHAR8_3(in.z);
}
#define round_perm(shared, out, in, k) \
out[0] = (k)[0] ^ SHARED_0(in[0]) ^ SHARED_1(in[1]) ^ SHARED_2(in[2]) ^ SHARED_3(in[3]); \
out[1] = (k)[1] ^ SHARED_0(in[1]) ^ SHARED_1(in[2]) ^ SHARED_2(in[3]) ^ SHARED_3(in[0]); \
out[2] = (k)[2] ^ SHARED_0(in[2]) ^ SHARED_1(in[3]) ^ SHARED_2(in[0]) ^ SHARED_3(in[1]); \
out[3] = (k)[3] ^ SHARED_0(in[3]) ^ SHARED_1(in[0]) ^ SHARED_2(in[1]) ^ SHARED_3(in[2]);
__device__ __forceinline__
void cn_aes_pseudo_round_mut(const uint32_t * sharedMemory, uint32_t * val, uint32_t const * expandedKey)
{
asm("// aes_pseudo_round_mut");
uint32_t b[4];
round_perm(sharedMemory, b, val, expandedKey);
round_perm(sharedMemory, val, b, expandedKey + (1 * N_COLS));
round_perm(sharedMemory, b, val, expandedKey + (2 * N_COLS));
round_perm(sharedMemory, val, b, expandedKey + (3 * N_COLS));
round_perm(sharedMemory, b, val, expandedKey + (4 * N_COLS));
round_perm(sharedMemory, val, b, expandedKey + (5 * N_COLS));
round_perm(sharedMemory, b, val, expandedKey + (6 * N_COLS));
round_perm(sharedMemory, val, b, expandedKey + (7 * N_COLS));
round_perm(sharedMemory, b, val, expandedKey + (8 * N_COLS));
round_perm(sharedMemory, val, b, expandedKey + (9 * N_COLS));
}
static __forceinline__ __device__ uint4 operator ^ (const uint4 &a, const uint4 &b) {
return make_uint4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
}
#define round_perm4(in, k) {\
uint4 tmp; \
tmp.x = SHARED_0(in.x) ^ SHARED_1(in.y) ^ SHARED_2(in.z) ^ SHARED_3(in.w); \
tmp.y = SHARED_0(in.y) ^ SHARED_1(in.z) ^ SHARED_2(in.w) ^ SHARED_3(in.x); \
tmp.z = SHARED_0(in.z) ^ SHARED_1(in.w) ^ SHARED_2(in.x) ^ SHARED_3(in.y); \
tmp.w = SHARED_0(in.w) ^ SHARED_1(in.x) ^ SHARED_2(in.y) ^ SHARED_3(in.z); \
val = tmp ^ key[k]; \
}
__device__ __forceinline__
void cn_aes_pseudo_round_mut_uint4(uint32_t * const sharedMemory, uint4 &val, uint4 const key[10])
{
asm("// aes_pseudo_round_mut_uint4");
round_perm4(val, 0);
round_perm4(val, 1);
round_perm4(val, 2);
round_perm4(val, 3);
round_perm4(val, 4);
round_perm4(val, 5);
round_perm4(val, 6);
round_perm4(val, 7);
round_perm4(val, 8);
round_perm4(val, 9);
}
/*
__device__ __forceinline__
void cn_aes_gpu_init2(uint32_t* sharedMemory)
{
#if 0
if(blockDim.x >= 64)
{
if(threadIdx.x < 64) {
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
#pragma unroll 4
for (uint32_t i = 0; i < 1024U; i += 256U) // 32x32 = 1024, 4 * 256 also
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
}
} else
#endif
if(blockDim.x >= 32) {
if(threadIdx.x < 32) {
#if 0
#pragma unroll 32
for(uint32_t i = 0; i < 1024; i += 32)
sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i];
#else
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
#pragma unroll 8
for (uint32_t i = 0; i < 1024; i += 128U) // 32x32 = 1024, 8 * 128 also
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
#endif
}
} else {
if(threadIdx.x < 4) {
#if 0
for (uint32_t i = 0; i < 1024; i += 4)
sharedMemory[threadIdx.x + i] = d_t_fn[threadIdx.x + i];
#else
#define thrX (threadIdx.x << 2U) // ensure offsets aligned (16) to vector
#pragma unroll 64
for (uint32_t i = 0; i < 1024; i += 16U)
AS_UINT4(&sharedMemory[i + thrX]) = AS_UINT4(&d_t_fn[i + thrX]);
#endif
}
}
}
*/
__device__ __forceinline__
void cn_aes_gpu_init(uint32_t* sharedMemory)
{
// AES 0
switch (threadIdx.x) {
case 0:
AS_UL2(&sharedMemory[0x000]) = make_ulonglong2(0x847c7cf8a56363c6, 0x8d7b7bf6997777ee);
AS_UL2(&sharedMemory[0x004]) = make_ulonglong2(0xbd6b6bd60df2f2ff, 0x54c5c591b16f6fde);
AS_UL2(&sharedMemory[0x008]) = make_ulonglong2(0x0301010250303060, 0x7d2b2b56a96767ce);
AS_UL2(&sharedMemory[0x00C]) = make_ulonglong2(0x62d7d7b519fefee7, 0x9a7676ece6abab4d);
AS_UL2(&sharedMemory[0x010]) = make_ulonglong2(0x9d82821f45caca8f, 0x877d7dfa40c9c989);
AS_UL2(&sharedMemory[0x014]) = make_ulonglong2(0xeb5959b215fafaef, 0x0bf0f0fbc947478e);
AS_UL2(&sharedMemory[0x018]) = make_ulonglong2(0x67d4d4b3ecadad41, 0xeaafaf45fda2a25f);
AS_UL2(&sharedMemory[0x01C]) = make_ulonglong2(0xf7a4a453bf9c9c23, 0x5bc0c09b967272e4);
break;
case 1:
AS_UL2(&sharedMemory[0x020]) = make_ulonglong2(0x1cfdfde1c2b7b775, 0x6a26264cae93933d);
AS_UL2(&sharedMemory[0x024]) = make_ulonglong2(0x413f3f7e5a36366c, 0x4fcccc8302f7f7f5);
AS_UL2(&sharedMemory[0x028]) = make_ulonglong2(0xf4a5a5515c343468, 0x08f1f1f934e5e5d1);
AS_UL2(&sharedMemory[0x02C]) = make_ulonglong2(0x73d8d8ab937171e2, 0x3f15152a53313162);
AS_UL2(&sharedMemory[0x030]) = make_ulonglong2(0x52c7c7950c040408, 0x5ec3c39d65232346);
AS_UL2(&sharedMemory[0x034]) = make_ulonglong2(0xa196963728181830, 0xb59a9a2f0f05050a);
AS_UL2(&sharedMemory[0x038]) = make_ulonglong2(0x361212240907070e, 0x3de2e2df9b80801b);
AS_UL2(&sharedMemory[0x03C]) = make_ulonglong2(0x6927274e26ebebcd, 0x9f7575eacdb2b27f);
break;
case 2:
AS_UL2(&sharedMemory[0x040]) = make_ulonglong2(0x9e83831d1b090912, 0x2e1a1a34742c2c58);
AS_UL2(&sharedMemory[0x044]) = make_ulonglong2(0xb26e6edc2d1b1b36, 0xfba0a05bee5a5ab4);
AS_UL2(&sharedMemory[0x048]) = make_ulonglong2(0x4d3b3b76f65252a4, 0xceb3b37d61d6d6b7);
AS_UL2(&sharedMemory[0x04C]) = make_ulonglong2(0x3ee3e3dd7b292952, 0x97848413712f2f5e);
AS_UL2(&sharedMemory[0x050]) = make_ulonglong2(0x68d1d1b9f55353a6, 0x2cededc100000000);
AS_UL2(&sharedMemory[0x054]) = make_ulonglong2(0x1ffcfce360202040, 0xed5b5bb6c8b1b179);
AS_UL2(&sharedMemory[0x058]) = make_ulonglong2(0x46cbcb8dbe6a6ad4, 0x4b393972d9bebe67);
AS_UL2(&sharedMemory[0x05C]) = make_ulonglong2(0xd44c4c98de4a4a94, 0x4acfcf85e85858b0);
break;
case 3:
AS_UL2(&sharedMemory[0x060]) = make_ulonglong2(0x2aefefc56bd0d0bb, 0x16fbfbede5aaaa4f);
AS_UL2(&sharedMemory[0x064]) = make_ulonglong2(0xd74d4d9ac5434386, 0x9485851155333366);
AS_UL2(&sharedMemory[0x068]) = make_ulonglong2(0x10f9f9e9cf45458a, 0x817f7ffe06020204);
AS_UL2(&sharedMemory[0x06C]) = make_ulonglong2(0x443c3c78f05050a0, 0xe3a8a84bba9f9f25);
AS_UL2(&sharedMemory[0x070]) = make_ulonglong2(0xfea3a35df35151a2, 0x8a8f8f05c0404080);
AS_UL2(&sharedMemory[0x074]) = make_ulonglong2(0xbc9d9d21ad92923f, 0x04f5f5f148383870);
AS_UL2(&sharedMemory[0x078]) = make_ulonglong2(0xc1b6b677dfbcbc63, 0x6321214275dadaaf);
AS_UL2(&sharedMemory[0x07C]) = make_ulonglong2(0x1affffe530101020, 0x6dd2d2bf0ef3f3fd);
break;
case 4:
AS_UL2(&sharedMemory[0x080]) = make_ulonglong2(0x140c0c184ccdcd81, 0x2fececc335131326);
AS_UL2(&sharedMemory[0x084]) = make_ulonglong2(0xa2979735e15f5fbe, 0x3917172ecc444488);
AS_UL2(&sharedMemory[0x088]) = make_ulonglong2(0xf2a7a75557c4c493, 0x473d3d7a827e7efc);
AS_UL2(&sharedMemory[0x08C]) = make_ulonglong2(0xe75d5dbaac6464c8, 0x957373e62b191932);
AS_UL2(&sharedMemory[0x090]) = make_ulonglong2(0x98818119a06060c0, 0x7fdcdca3d14f4f9e);
AS_UL2(&sharedMemory[0x094]) = make_ulonglong2(0x7e2a2a5466222244, 0x8388880bab90903b);
AS_UL2(&sharedMemory[0x098]) = make_ulonglong2(0x29eeeec7ca46468c, 0x3c141428d3b8b86b);
AS_UL2(&sharedMemory[0x09C]) = make_ulonglong2(0xe25e5ebc79dedea7, 0x76dbdbad1d0b0b16);
break;
case 5:
AS_UL2(&sharedMemory[0x0A0]) = make_ulonglong2(0x563232643be0e0db, 0x1e0a0a144e3a3a74);
AS_UL2(&sharedMemory[0x0A4]) = make_ulonglong2(0x0a06060cdb494992, 0xe45c5cb86c242448);
AS_UL2(&sharedMemory[0x0A8]) = make_ulonglong2(0x6ed3d3bd5dc2c29f, 0xa66262c4efacac43);
AS_UL2(&sharedMemory[0x0AC]) = make_ulonglong2(0xa4959531a8919139, 0x8b7979f237e4e4d3);
AS_UL2(&sharedMemory[0x0B0]) = make_ulonglong2(0x43c8c88b32e7e7d5, 0xb76d6dda5937376e);
AS_UL2(&sharedMemory[0x0B4]) = make_ulonglong2(0x64d5d5b18c8d8d01, 0xe0a9a949d24e4e9c);
AS_UL2(&sharedMemory[0x0B8]) = make_ulonglong2(0xfa5656acb46c6cd8, 0x25eaeacf07f4f4f3);
AS_UL2(&sharedMemory[0x0BC]) = make_ulonglong2(0x8e7a7af4af6565ca, 0x18080810e9aeae47);
break;
case 6:
AS_UL2(&sharedMemory[0x0C0]) = make_ulonglong2(0x887878f0d5baba6f, 0x722e2e5c6f25254a);
AS_UL2(&sharedMemory[0x0C4]) = make_ulonglong2(0xf1a6a657241c1c38, 0x51c6c697c7b4b473);
AS_UL2(&sharedMemory[0x0C8]) = make_ulonglong2(0x7cdddda123e8e8cb, 0x211f1f3e9c7474e8);
AS_UL2(&sharedMemory[0x0CC]) = make_ulonglong2(0xdcbdbd61dd4b4b96, 0x858a8a0f868b8b0d);
AS_UL2(&sharedMemory[0x0D0]) = make_ulonglong2(0x423e3e7c907070e0, 0xaa6666ccc4b5b571);
AS_UL2(&sharedMemory[0x0D4]) = make_ulonglong2(0x05030306d8484890, 0x120e0e1c01f6f6f7);
AS_UL2(&sharedMemory[0x0D8]) = make_ulonglong2(0x5f35356aa36161c2, 0xd0b9b969f95757ae);
AS_UL2(&sharedMemory[0x0DC]) = make_ulonglong2(0x58c1c19991868617, 0xb99e9e27271d1d3a);
break;
case 7:
AS_UL2(&sharedMemory[0x0E0]) = make_ulonglong2(0x13f8f8eb38e1e1d9, 0x33111122b398982b);
AS_UL2(&sharedMemory[0x0E4]) = make_ulonglong2(0x70d9d9a9bb6969d2, 0xa7949433898e8e07);
AS_UL2(&sharedMemory[0x0E8]) = make_ulonglong2(0x221e1e3cb69b9b2d, 0x20e9e9c992878715);
AS_UL2(&sharedMemory[0x0EC]) = make_ulonglong2(0xff5555aa49cece87, 0x7adfdfa578282850);
AS_UL2(&sharedMemory[0x0F0]) = make_ulonglong2(0xf8a1a1598f8c8c03, 0x170d0d1a80898909);
AS_UL2(&sharedMemory[0x0F4]) = make_ulonglong2(0x31e6e6d7dabfbf65, 0xb86868d0c6424284);
AS_UL2(&sharedMemory[0x0F8]) = make_ulonglong2(0xb0999929c3414182, 0x110f0f1e772d2d5a);
AS_UL2(&sharedMemory[0x0FC]) = make_ulonglong2(0xfc5454a8cbb0b07b, 0x3a16162cd6bbbb6d);
break;
}
// AES 1
switch (threadIdx.x) {
case 0:
AS_UL2(&sharedMemory[0x100]) = make_ulonglong2(0x7c7cf8846363c6a5, 0x7b7bf68d7777ee99);
AS_UL2(&sharedMemory[0x104]) = make_ulonglong2(0x6b6bd6bdf2f2ff0d, 0xc5c591546f6fdeb1);
AS_UL2(&sharedMemory[0x108]) = make_ulonglong2(0x0101020330306050, 0x2b2b567d6767cea9);
AS_UL2(&sharedMemory[0x10C]) = make_ulonglong2(0xd7d7b562fefee719, 0x7676ec9aabab4de6);
AS_UL2(&sharedMemory[0x110]) = make_ulonglong2(0x82821f9dcaca8f45, 0x7d7dfa87c9c98940);
AS_UL2(&sharedMemory[0x114]) = make_ulonglong2(0x5959b2ebfafaef15, 0xf0f0fb0b47478ec9);
AS_UL2(&sharedMemory[0x118]) = make_ulonglong2(0xd4d4b367adad41ec, 0xafaf45eaa2a25ffd);
AS_UL2(&sharedMemory[0x11C]) = make_ulonglong2(0xa4a453f79c9c23bf, 0xc0c09b5b7272e496);
break;
case 1:
AS_UL2(&sharedMemory[0x120]) = make_ulonglong2(0xfdfde11cb7b775c2, 0x26264c6a93933dae);
AS_UL2(&sharedMemory[0x124]) = make_ulonglong2(0x3f3f7e4136366c5a, 0xcccc834ff7f7f502);
AS_UL2(&sharedMemory[0x128]) = make_ulonglong2(0xa5a551f43434685c, 0xf1f1f908e5e5d134);
AS_UL2(&sharedMemory[0x12C]) = make_ulonglong2(0xd8d8ab737171e293, 0x15152a3f31316253);
AS_UL2(&sharedMemory[0x130]) = make_ulonglong2(0xc7c795520404080c, 0xc3c39d5e23234665);
AS_UL2(&sharedMemory[0x134]) = make_ulonglong2(0x969637a118183028, 0x9a9a2fb505050a0f);
AS_UL2(&sharedMemory[0x138]) = make_ulonglong2(0x1212243607070e09, 0xe2e2df3d80801b9b);
AS_UL2(&sharedMemory[0x13C]) = make_ulonglong2(0x27274e69ebebcd26, 0x7575ea9fb2b27fcd);
break;
case 2:
AS_UL2(&sharedMemory[0x140]) = make_ulonglong2(0x83831d9e0909121b, 0x1a1a342e2c2c5874);
AS_UL2(&sharedMemory[0x144]) = make_ulonglong2(0x6e6edcb21b1b362d, 0xa0a05bfb5a5ab4ee);
AS_UL2(&sharedMemory[0x148]) = make_ulonglong2(0x3b3b764d5252a4f6, 0xb3b37dced6d6b761);
AS_UL2(&sharedMemory[0x14C]) = make_ulonglong2(0xe3e3dd3e2929527b, 0x848413972f2f5e71);
AS_UL2(&sharedMemory[0x150]) = make_ulonglong2(0xd1d1b9685353a6f5, 0xededc12c00000000);
AS_UL2(&sharedMemory[0x154]) = make_ulonglong2(0xfcfce31f20204060, 0x5b5bb6edb1b179c8);
AS_UL2(&sharedMemory[0x158]) = make_ulonglong2(0xcbcb8d466a6ad4be, 0x3939724bbebe67d9);
AS_UL2(&sharedMemory[0x15C]) = make_ulonglong2(0x4c4c98d44a4a94de, 0xcfcf854a5858b0e8);
break;
case 3:
AS_UL2(&sharedMemory[0x160]) = make_ulonglong2(0xefefc52ad0d0bb6b, 0xfbfbed16aaaa4fe5);
AS_UL2(&sharedMemory[0x164]) = make_ulonglong2(0x4d4d9ad7434386c5, 0x8585119433336655);
AS_UL2(&sharedMemory[0x168]) = make_ulonglong2(0xf9f9e91045458acf, 0x7f7ffe8102020406);
AS_UL2(&sharedMemory[0x16C]) = make_ulonglong2(0x3c3c78445050a0f0, 0xa8a84be39f9f25ba);
AS_UL2(&sharedMemory[0x170]) = make_ulonglong2(0xa3a35dfe5151a2f3, 0x8f8f058a404080c0);
AS_UL2(&sharedMemory[0x174]) = make_ulonglong2(0x9d9d21bc92923fad, 0xf5f5f10438387048);
AS_UL2(&sharedMemory[0x178]) = make_ulonglong2(0xb6b677c1bcbc63df, 0x21214263dadaaf75);
AS_UL2(&sharedMemory[0x17C]) = make_ulonglong2(0xffffe51a10102030, 0xd2d2bf6df3f3fd0e);
break;
case 4:
AS_UL2(&sharedMemory[0x180]) = make_ulonglong2(0x0c0c1814cdcd814c, 0xececc32f13132635);
AS_UL2(&sharedMemory[0x184]) = make_ulonglong2(0x979735a25f5fbee1, 0x17172e39444488cc);
AS_UL2(&sharedMemory[0x188]) = make_ulonglong2(0xa7a755f2c4c49357, 0x3d3d7a477e7efc82);
AS_UL2(&sharedMemory[0x18C]) = make_ulonglong2(0x5d5dbae76464c8ac, 0x7373e6951919322b);
AS_UL2(&sharedMemory[0x190]) = make_ulonglong2(0x818119986060c0a0, 0xdcdca37f4f4f9ed1);
AS_UL2(&sharedMemory[0x194]) = make_ulonglong2(0x2a2a547e22224466, 0x88880b8390903bab);
AS_UL2(&sharedMemory[0x198]) = make_ulonglong2(0xeeeec72946468cca, 0x1414283cb8b86bd3);
AS_UL2(&sharedMemory[0x19C]) = make_ulonglong2(0x5e5ebce2dedea779, 0xdbdbad760b0b161d);
break;
case 5:
AS_UL2(&sharedMemory[0x1A0]) = make_ulonglong2(0x32326456e0e0db3b, 0x0a0a141e3a3a744e);
AS_UL2(&sharedMemory[0x1A4]) = make_ulonglong2(0x06060c0a494992db, 0x5c5cb8e42424486c);
AS_UL2(&sharedMemory[0x1A8]) = make_ulonglong2(0xd3d3bd6ec2c29f5d, 0x6262c4a6acac43ef);
AS_UL2(&sharedMemory[0x1AC]) = make_ulonglong2(0x959531a4919139a8, 0x7979f28be4e4d337);
AS_UL2(&sharedMemory[0x1B0]) = make_ulonglong2(0xc8c88b43e7e7d532, 0x6d6ddab737376e59);
AS_UL2(&sharedMemory[0x1B4]) = make_ulonglong2(0xd5d5b1648d8d018c, 0xa9a949e04e4e9cd2);
AS_UL2(&sharedMemory[0x1B8]) = make_ulonglong2(0x5656acfa6c6cd8b4, 0xeaeacf25f4f4f307);
AS_UL2(&sharedMemory[0x1BC]) = make_ulonglong2(0x7a7af48e6565caaf, 0x08081018aeae47e9);
break;
case 6:
AS_UL2(&sharedMemory[0x1C0]) = make_ulonglong2(0x7878f088baba6fd5, 0x2e2e5c7225254a6f);
AS_UL2(&sharedMemory[0x1C4]) = make_ulonglong2(0xa6a657f11c1c3824, 0xc6c69751b4b473c7);
AS_UL2(&sharedMemory[0x1C8]) = make_ulonglong2(0xdddda17ce8e8cb23, 0x1f1f3e217474e89c);
AS_UL2(&sharedMemory[0x1CC]) = make_ulonglong2(0xbdbd61dc4b4b96dd, 0x8a8a0f858b8b0d86);
AS_UL2(&sharedMemory[0x1D0]) = make_ulonglong2(0x3e3e7c427070e090, 0x6666ccaab5b571c4);
AS_UL2(&sharedMemory[0x1D4]) = make_ulonglong2(0x03030605484890d8, 0x0e0e1c12f6f6f701);
AS_UL2(&sharedMemory[0x1D8]) = make_ulonglong2(0x35356a5f6161c2a3, 0xb9b969d05757aef9);
AS_UL2(&sharedMemory[0x1DC]) = make_ulonglong2(0xc1c1995886861791, 0x9e9e27b91d1d3a27);
break;
case 7:
AS_UL2(&sharedMemory[0x1E0]) = make_ulonglong2(0xf8f8eb13e1e1d938, 0x1111223398982bb3);
AS_UL2(&sharedMemory[0x1E4]) = make_ulonglong2(0xd9d9a9706969d2bb, 0x949433a78e8e0789);
AS_UL2(&sharedMemory[0x1E8]) = make_ulonglong2(0x1e1e3c229b9b2db6, 0xe9e9c92087871592);
AS_UL2(&sharedMemory[0x1EC]) = make_ulonglong2(0x5555aaffcece8749, 0xdfdfa57a28285078);
AS_UL2(&sharedMemory[0x1F0]) = make_ulonglong2(0xa1a159f88c8c038f, 0x0d0d1a1789890980);
AS_UL2(&sharedMemory[0x1F4]) = make_ulonglong2(0xe6e6d731bfbf65da, 0x6868d0b8424284c6);
AS_UL2(&sharedMemory[0x1F8]) = make_ulonglong2(0x999929b0414182c3, 0x0f0f1e112d2d5a77);
AS_UL2(&sharedMemory[0x1FC]) = make_ulonglong2(0x5454a8fcb0b07bcb, 0x16162c3abbbb6dd6);
break;
}
// AES 2
switch (threadIdx.x) {
case 0:
AS_UL2(&sharedMemory[0x200]) = make_ulonglong2(0x7cf8847c63c6a563, 0x7bf68d7b77ee9977);
AS_UL2(&sharedMemory[0x204]) = make_ulonglong2(0x6bd6bd6bf2ff0df2, 0xc59154c56fdeb16f);
AS_UL2(&sharedMemory[0x208]) = make_ulonglong2(0x0102030130605030, 0x2b567d2b67cea967);
AS_UL2(&sharedMemory[0x20C]) = make_ulonglong2(0xd7b562d7fee719fe, 0x76ec9a76ab4de6ab);
AS_UL2(&sharedMemory[0x210]) = make_ulonglong2(0x821f9d82ca8f45ca, 0x7dfa877dc98940c9);
AS_UL2(&sharedMemory[0x214]) = make_ulonglong2(0x59b2eb59faef15fa, 0xf0fb0bf0478ec947);
AS_UL2(&sharedMemory[0x218]) = make_ulonglong2(0xd4b367d4ad41ecad, 0xaf45eaafa25ffda2);
AS_UL2(&sharedMemory[0x21C]) = make_ulonglong2(0xa453f7a49c23bf9c, 0xc09b5bc072e49672);
break;
case 1:
AS_UL2(&sharedMemory[0x220]) = make_ulonglong2(0xfde11cfdb775c2b7, 0x264c6a26933dae93);
AS_UL2(&sharedMemory[0x224]) = make_ulonglong2(0x3f7e413f366c5a36, 0xcc834fccf7f502f7);
AS_UL2(&sharedMemory[0x228]) = make_ulonglong2(0xa551f4a534685c34, 0xf1f908f1e5d134e5);
AS_UL2(&sharedMemory[0x22C]) = make_ulonglong2(0xd8ab73d871e29371, 0x152a3f1531625331);
AS_UL2(&sharedMemory[0x230]) = make_ulonglong2(0xc79552c704080c04, 0xc39d5ec323466523);
AS_UL2(&sharedMemory[0x234]) = make_ulonglong2(0x9637a19618302818, 0x9a2fb59a050a0f05);
AS_UL2(&sharedMemory[0x238]) = make_ulonglong2(0x12243612070e0907, 0xe2df3de2801b9b80);
AS_UL2(&sharedMemory[0x23C]) = make_ulonglong2(0x274e6927ebcd26eb, 0x75ea9f75b27fcdb2);
break;
case 2:
AS_UL2(&sharedMemory[0x240]) = make_ulonglong2(0x831d9e8309121b09, 0x1a342e1a2c58742c);
AS_UL2(&sharedMemory[0x244]) = make_ulonglong2(0x6edcb26e1b362d1b, 0xa05bfba05ab4ee5a);
AS_UL2(&sharedMemory[0x248]) = make_ulonglong2(0x3b764d3b52a4f652, 0xb37dceb3d6b761d6);
AS_UL2(&sharedMemory[0x24C]) = make_ulonglong2(0xe3dd3ee329527b29, 0x841397842f5e712f);
AS_UL2(&sharedMemory[0x250]) = make_ulonglong2(0xd1b968d153a6f553, 0xedc12ced00000000);
AS_UL2(&sharedMemory[0x254]) = make_ulonglong2(0xfce31ffc20406020, 0x5bb6ed5bb179c8b1);
AS_UL2(&sharedMemory[0x258]) = make_ulonglong2(0xcb8d46cb6ad4be6a, 0x39724b39be67d9be);
AS_UL2(&sharedMemory[0x25C]) = make_ulonglong2(0x4c98d44c4a94de4a, 0xcf854acf58b0e858);
break;
case 3:
AS_UL2(&sharedMemory[0x260]) = make_ulonglong2(0xefc52aefd0bb6bd0, 0xfbed16fbaa4fe5aa);
AS_UL2(&sharedMemory[0x264]) = make_ulonglong2(0x4d9ad74d4386c543, 0x8511948533665533);
AS_UL2(&sharedMemory[0x268]) = make_ulonglong2(0xf9e910f9458acf45, 0x7ffe817f02040602);
AS_UL2(&sharedMemory[0x26C]) = make_ulonglong2(0x3c78443c50a0f050, 0xa84be3a89f25ba9f);
AS_UL2(&sharedMemory[0x270]) = make_ulonglong2(0xa35dfea351a2f351, 0x8f058a8f4080c040);
AS_UL2(&sharedMemory[0x274]) = make_ulonglong2(0x9d21bc9d923fad92, 0xf5f104f538704838);
AS_UL2(&sharedMemory[0x278]) = make_ulonglong2(0xb677c1b6bc63dfbc, 0x21426321daaf75da);
AS_UL2(&sharedMemory[0x27C]) = make_ulonglong2(0xffe51aff10203010, 0xd2bf6dd2f3fd0ef3);
break;
case 4:
AS_UL2(&sharedMemory[0x280]) = make_ulonglong2(0x0c18140ccd814ccd, 0xecc32fec13263513);
AS_UL2(&sharedMemory[0x284]) = make_ulonglong2(0x9735a2975fbee15f, 0x172e39174488cc44);
AS_UL2(&sharedMemory[0x288]) = make_ulonglong2(0xa755f2a7c49357c4, 0x3d7a473d7efc827e);
AS_UL2(&sharedMemory[0x28C]) = make_ulonglong2(0x5dbae75d64c8ac64, 0x73e6957319322b19);
AS_UL2(&sharedMemory[0x290]) = make_ulonglong2(0x8119988160c0a060, 0xdca37fdc4f9ed14f);
AS_UL2(&sharedMemory[0x294]) = make_ulonglong2(0x2a547e2a22446622, 0x880b8388903bab90);
AS_UL2(&sharedMemory[0x298]) = make_ulonglong2(0xeec729ee468cca46, 0x14283c14b86bd3b8);
AS_UL2(&sharedMemory[0x29C]) = make_ulonglong2(0x5ebce25edea779de, 0xdbad76db0b161d0b);
break;
case 5:
AS_UL2(&sharedMemory[0x2A0]) = make_ulonglong2(0x32645632e0db3be0, 0x0a141e0a3a744e3a);
AS_UL2(&sharedMemory[0x2A4]) = make_ulonglong2(0x060c0a064992db49, 0x5cb8e45c24486c24);
AS_UL2(&sharedMemory[0x2A8]) = make_ulonglong2(0xd3bd6ed3c29f5dc2, 0x62c4a662ac43efac);
AS_UL2(&sharedMemory[0x2AC]) = make_ulonglong2(0x9531a4959139a891, 0x79f28b79e4d337e4);
AS_UL2(&sharedMemory[0x2B0]) = make_ulonglong2(0xc88b43c8e7d532e7, 0x6ddab76d376e5937);
AS_UL2(&sharedMemory[0x2B4]) = make_ulonglong2(0xd5b164d58d018c8d, 0xa949e0a94e9cd24e);
AS_UL2(&sharedMemory[0x2B8]) = make_ulonglong2(0x56acfa566cd8b46c, 0xeacf25eaf4f307f4);
AS_UL2(&sharedMemory[0x2BC]) = make_ulonglong2(0x7af48e7a65caaf65, 0x08101808ae47e9ae);
break;
case 6:
AS_UL2(&sharedMemory[0x2C0]) = make_ulonglong2(0x78f08878ba6fd5ba, 0x2e5c722e254a6f25);
AS_UL2(&sharedMemory[0x2C4]) = make_ulonglong2(0xa657f1a61c38241c, 0xc69751c6b473c7b4);
AS_UL2(&sharedMemory[0x2C8]) = make_ulonglong2(0xdda17cdde8cb23e8, 0x1f3e211f74e89c74);
AS_UL2(&sharedMemory[0x2CC]) = make_ulonglong2(0xbd61dcbd4b96dd4b, 0x8a0f858a8b0d868b);
AS_UL2(&sharedMemory[0x2D0]) = make_ulonglong2(0x3e7c423e70e09070, 0x66ccaa66b571c4b5);
AS_UL2(&sharedMemory[0x2D4]) = make_ulonglong2(0x030605034890d848, 0x0e1c120ef6f701f6);
AS_UL2(&sharedMemory[0x2D8]) = make_ulonglong2(0x356a5f3561c2a361, 0xb969d0b957aef957);
AS_UL2(&sharedMemory[0x2DC]) = make_ulonglong2(0xc19958c186179186, 0x9e27b99e1d3a271d);
break;
case 7:
AS_UL2(&sharedMemory[0x2E0]) = make_ulonglong2(0xf8eb13f8e1d938e1, 0x11223311982bb398);
AS_UL2(&sharedMemory[0x2E4]) = make_ulonglong2(0xd9a970d969d2bb69, 0x9433a7948e07898e);
AS_UL2(&sharedMemory[0x2E8]) = make_ulonglong2(0x1e3c221e9b2db69b, 0xe9c920e987159287);
AS_UL2(&sharedMemory[0x2EC]) = make_ulonglong2(0x55aaff55ce8749ce, 0xdfa57adf28507828);
AS_UL2(&sharedMemory[0x2F0]) = make_ulonglong2(0xa159f8a18c038f8c, 0x0d1a170d89098089);
AS_UL2(&sharedMemory[0x2F4]) = make_ulonglong2(0xe6d731e6bf65dabf, 0x68d0b8684284c642);
AS_UL2(&sharedMemory[0x2F8]) = make_ulonglong2(0x9929b0994182c341, 0x0f1e110f2d5a772d);
AS_UL2(&sharedMemory[0x2FC]) = make_ulonglong2(0x54a8fc54b07bcbb0, 0x162c3a16bb6dd6bb);
break;
}
// AES 3
switch (threadIdx.x) {
case 0:
AS_UL2(&sharedMemory[0x300]) = make_ulonglong2(0xf8847c7cc6a56363, 0xf68d7b7bee997777);
AS_UL2(&sharedMemory[0x304]) = make_ulonglong2(0xd6bd6b6bff0df2f2, 0x9154c5c5deb16f6f);
AS_UL2(&sharedMemory[0x308]) = make_ulonglong2(0x0203010160503030, 0x567d2b2bcea96767);
AS_UL2(&sharedMemory[0x30C]) = make_ulonglong2(0xb562d7d7e719fefe, 0xec9a76764de6abab);
AS_UL2(&sharedMemory[0x310]) = make_ulonglong2(0x1f9d82828f45caca, 0xfa877d7d8940c9c9);
AS_UL2(&sharedMemory[0x314]) = make_ulonglong2(0xb2eb5959ef15fafa, 0xfb0bf0f08ec94747);
AS_UL2(&sharedMemory[0x318]) = make_ulonglong2(0xb367d4d441ecadad, 0x45eaafaf5ffda2a2);
AS_UL2(&sharedMemory[0x31C]) = make_ulonglong2(0x53f7a4a423bf9c9c, 0x9b5bc0c0e4967272);
break;
case 1:
AS_UL2(&sharedMemory[0x320]) = make_ulonglong2(0xe11cfdfd75c2b7b7, 0x4c6a26263dae9393);
AS_UL2(&sharedMemory[0x324]) = make_ulonglong2(0x7e413f3f6c5a3636, 0x834fccccf502f7f7);
AS_UL2(&sharedMemory[0x328]) = make_ulonglong2(0x51f4a5a5685c3434, 0xf908f1f1d134e5e5);
AS_UL2(&sharedMemory[0x32C]) = make_ulonglong2(0xab73d8d8e2937171, 0x2a3f151562533131);
AS_UL2(&sharedMemory[0x330]) = make_ulonglong2(0x9552c7c7080c0404, 0x9d5ec3c346652323);
AS_UL2(&sharedMemory[0x334]) = make_ulonglong2(0x37a1969630281818, 0x2fb59a9a0a0f0505);
AS_UL2(&sharedMemory[0x338]) = make_ulonglong2(0x243612120e090707, 0xdf3de2e21b9b8080);
AS_UL2(&sharedMemory[0x33C]) = make_ulonglong2(0x4e692727cd26ebeb, 0xea9f75757fcdb2b2);
break;
case 2:
AS_UL2(&sharedMemory[0x340]) = make_ulonglong2(0x1d9e8383121b0909, 0x342e1a1a58742c2c);
AS_UL2(&sharedMemory[0x344]) = make_ulonglong2(0xdcb26e6e362d1b1b, 0x5bfba0a0b4ee5a5a);
AS_UL2(&sharedMemory[0x348]) = make_ulonglong2(0x764d3b3ba4f65252, 0x7dceb3b3b761d6d6);
AS_UL2(&sharedMemory[0x34C]) = make_ulonglong2(0xdd3ee3e3527b2929, 0x139784845e712f2f);
AS_UL2(&sharedMemory[0x350]) = make_ulonglong2(0xb968d1d1a6f55353, 0xc12ceded00000000);
AS_UL2(&sharedMemory[0x354]) = make_ulonglong2(0xe31ffcfc40602020, 0xb6ed5b5b79c8b1b1);
AS_UL2(&sharedMemory[0x358]) = make_ulonglong2(0x8d46cbcbd4be6a6a, 0x724b393967d9bebe);
AS_UL2(&sharedMemory[0x35C]) = make_ulonglong2(0x98d44c4c94de4a4a, 0x854acfcfb0e85858);
break;
case 3:
AS_UL2(&sharedMemory[0x360]) = make_ulonglong2(0xc52aefefbb6bd0d0, 0xed16fbfb4fe5aaaa);
AS_UL2(&sharedMemory[0x364]) = make_ulonglong2(0x9ad74d4d86c54343, 0x1194858566553333);
AS_UL2(&sharedMemory[0x368]) = make_ulonglong2(0xe910f9f98acf4545, 0xfe817f7f04060202);
AS_UL2(&sharedMemory[0x36C]) = make_ulonglong2(0x78443c3ca0f05050, 0x4be3a8a825ba9f9f);
AS_UL2(&sharedMemory[0x370]) = make_ulonglong2(0x5dfea3a3a2f35151, 0x058a8f8f80c04040);
AS_UL2(&sharedMemory[0x374]) = make_ulonglong2(0x21bc9d9d3fad9292, 0xf104f5f570483838);
AS_UL2(&sharedMemory[0x378]) = make_ulonglong2(0x77c1b6b663dfbcbc, 0x42632121af75dada);
AS_UL2(&sharedMemory[0x37C]) = make_ulonglong2(0xe51affff20301010, 0xbf6dd2d2fd0ef3f3);
break;
case 4:
AS_UL2(&sharedMemory[0x380]) = make_ulonglong2(0x18140c0c814ccdcd, 0xc32fecec26351313);
AS_UL2(&sharedMemory[0x384]) = make_ulonglong2(0x35a29797bee15f5f, 0x2e39171788cc4444);
AS_UL2(&sharedMemory[0x388]) = make_ulonglong2(0x55f2a7a79357c4c4, 0x7a473d3dfc827e7e);
AS_UL2(&sharedMemory[0x38C]) = make_ulonglong2(0xbae75d5dc8ac6464, 0xe6957373322b1919);
AS_UL2(&sharedMemory[0x390]) = make_ulonglong2(0x19988181c0a06060, 0xa37fdcdc9ed14f4f);
AS_UL2(&sharedMemory[0x394]) = make_ulonglong2(0x547e2a2a44662222, 0x0b8388883bab9090);
AS_UL2(&sharedMemory[0x398]) = make_ulonglong2(0xc729eeee8cca4646, 0x283c14146bd3b8b8);
AS_UL2(&sharedMemory[0x39C]) = make_ulonglong2(0xbce25e5ea779dede, 0xad76dbdb161d0b0b);
break;
case 5:
AS_UL2(&sharedMemory[0x3A0]) = make_ulonglong2(0x64563232db3be0e0, 0x141e0a0a744e3a3a);
AS_UL2(&sharedMemory[0x3A4]) = make_ulonglong2(0x0c0a060692db4949, 0xb8e45c5c486c2424);
AS_UL2(&sharedMemory[0x3A8]) = make_ulonglong2(0xbd6ed3d39f5dc2c2, 0xc4a6626243efacac);
AS_UL2(&sharedMemory[0x3AC]) = make_ulonglong2(0x31a4959539a89191, 0xf28b7979d337e4e4);
AS_UL2(&sharedMemory[0x3B0]) = make_ulonglong2(0x8b43c8c8d532e7e7, 0xdab76d6d6e593737);
AS_UL2(&sharedMemory[0x3B4]) = make_ulonglong2(0xb164d5d5018c8d8d, 0x49e0a9a99cd24e4e);
AS_UL2(&sharedMemory[0x3B8]) = make_ulonglong2(0xacfa5656d8b46c6c, 0xcf25eaeaf307f4f4);
AS_UL2(&sharedMemory[0x3BC]) = make_ulonglong2(0xf48e7a7acaaf6565, 0x1018080847e9aeae);
break;
case 6:
AS_UL2(&sharedMemory[0x3C0]) = make_ulonglong2(0xf08878786fd5baba, 0x5c722e2e4a6f2525);
AS_UL2(&sharedMemory[0x3C4]) = make_ulonglong2(0x57f1a6a638241c1c, 0x9751c6c673c7b4b4);
AS_UL2(&sharedMemory[0x3C8]) = make_ulonglong2(0xa17cddddcb23e8e8, 0x3e211f1fe89c7474);
AS_UL2(&sharedMemory[0x3CC]) = make_ulonglong2(0x61dcbdbd96dd4b4b, 0x0f858a8a0d868b8b);
AS_UL2(&sharedMemory[0x3D0]) = make_ulonglong2(0x7c423e3ee0907070, 0xccaa666671c4b5b5);
AS_UL2(&sharedMemory[0x3D4]) = make_ulonglong2(0x0605030390d84848, 0x1c120e0ef701f6f6);
AS_UL2(&sharedMemory[0x3D8]) = make_ulonglong2(0x6a5f3535c2a36161, 0x69d0b9b9aef95757);
AS_UL2(&sharedMemory[0x3DC]) = make_ulonglong2(0x9958c1c117918686, 0x27b99e9e3a271d1d);
break;
case 7:
AS_UL2(&sharedMemory[0x3E0]) = make_ulonglong2(0xeb13f8f8d938e1e1, 0x223311112bb39898);
AS_UL2(&sharedMemory[0x3E4]) = make_ulonglong2(0xa970d9d9d2bb6969, 0x33a7949407898e8e);
AS_UL2(&sharedMemory[0x3E8]) = make_ulonglong2(0x3c221e1e2db69b9b, 0xc920e9e915928787);
AS_UL2(&sharedMemory[0x3EC]) = make_ulonglong2(0xaaff55558749cece, 0xa57adfdf50782828);
AS_UL2(&sharedMemory[0x3F0]) = make_ulonglong2(0x59f8a1a1038f8c8c, 0x1a170d0d09808989);
AS_UL2(&sharedMemory[0x3F4]) = make_ulonglong2(0xd731e6e665dabfbf, 0xd0b8686884c64242);
AS_UL2(&sharedMemory[0x3F8]) = make_ulonglong2(0x29b0999982c34141, 0x1e110f0f5a772d2d);
AS_UL2(&sharedMemory[0x3FC]) = make_ulonglong2(0xa8fc54547bcbb0b0, 0x2c3a16166dd6bbbb);
break;
}
}
__device__ __forceinline__
void cn_aes_gpu_init_u4(uint32_t* sharedMemory)
{
// AES 0
switch (threadIdx.x) {
case 0:
AS_UINT4(&sharedMemory[0x000]) = make_uint4(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
AS_UINT4(&sharedMemory[0x004]) = make_uint4(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
AS_UINT4(&sharedMemory[0x008]) = make_uint4(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
AS_UINT4(&sharedMemory[0x00C]) = make_uint4(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
AS_UINT4(&sharedMemory[0x010]) = make_uint4(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
AS_UINT4(&sharedMemory[0x014]) = make_uint4(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
AS_UINT4(&sharedMemory[0x018]) = make_uint4(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
AS_UINT4(&sharedMemory[0x01C]) = make_uint4(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
break;
case 1:
AS_UINT4(&sharedMemory[0x020]) = make_uint4(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
AS_UINT4(&sharedMemory[0x024]) = make_uint4(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
AS_UINT4(&sharedMemory[0x028]) = make_uint4(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
AS_UINT4(&sharedMemory[0x02C]) = make_uint4(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
AS_UINT4(&sharedMemory[0x030]) = make_uint4(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
AS_UINT4(&sharedMemory[0x034]) = make_uint4(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
AS_UINT4(&sharedMemory[0x038]) = make_uint4(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
AS_UINT4(&sharedMemory[0x03C]) = make_uint4(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
break;
case 2:
AS_UINT4(&sharedMemory[0x040]) = make_uint4(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
AS_UINT4(&sharedMemory[0x044]) = make_uint4(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
AS_UINT4(&sharedMemory[0x048]) = make_uint4(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
AS_UINT4(&sharedMemory[0x04C]) = make_uint4(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
AS_UINT4(&sharedMemory[0x050]) = make_uint4(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
AS_UINT4(&sharedMemory[0x054]) = make_uint4(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
AS_UINT4(&sharedMemory[0x058]) = make_uint4(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
AS_UINT4(&sharedMemory[0x05C]) = make_uint4(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
break;
case 3:
AS_UINT4(&sharedMemory[0x060]) = make_uint4(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
AS_UINT4(&sharedMemory[0x064]) = make_uint4(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
AS_UINT4(&sharedMemory[0x068]) = make_uint4(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
AS_UINT4(&sharedMemory[0x06C]) = make_uint4(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
AS_UINT4(&sharedMemory[0x070]) = make_uint4(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
AS_UINT4(&sharedMemory[0x074]) = make_uint4(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
AS_UINT4(&sharedMemory[0x078]) = make_uint4(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
AS_UINT4(&sharedMemory[0x07C]) = make_uint4(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
break;
case 4:
AS_UINT4(&sharedMemory[0x080]) = make_uint4(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
AS_UINT4(&sharedMemory[0x084]) = make_uint4(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
AS_UINT4(&sharedMemory[0x088]) = make_uint4(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
AS_UINT4(&sharedMemory[0x08C]) = make_uint4(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
AS_UINT4(&sharedMemory[0x090]) = make_uint4(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
AS_UINT4(&sharedMemory[0x094]) = make_uint4(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
AS_UINT4(&sharedMemory[0x098]) = make_uint4(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
AS_UINT4(&sharedMemory[0x09C]) = make_uint4(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
break;
case 5:
AS_UINT4(&sharedMemory[0x0A0]) = make_uint4(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
AS_UINT4(&sharedMemory[0x0A4]) = make_uint4(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
AS_UINT4(&sharedMemory[0x0A8]) = make_uint4(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
AS_UINT4(&sharedMemory[0x0AC]) = make_uint4(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
AS_UINT4(&sharedMemory[0x0B0]) = make_uint4(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
AS_UINT4(&sharedMemory[0x0B4]) = make_uint4(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
AS_UINT4(&sharedMemory[0x0B8]) = make_uint4(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
AS_UINT4(&sharedMemory[0x0BC]) = make_uint4(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
break;
case 6:
AS_UINT4(&sharedMemory[0x0C0]) = make_uint4(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
AS_UINT4(&sharedMemory[0x0C4]) = make_uint4(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
AS_UINT4(&sharedMemory[0x0C8]) = make_uint4(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
AS_UINT4(&sharedMemory[0x0CC]) = make_uint4(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
AS_UINT4(&sharedMemory[0x0D0]) = make_uint4(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
AS_UINT4(&sharedMemory[0x0D4]) = make_uint4(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
AS_UINT4(&sharedMemory[0x0D8]) = make_uint4(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
AS_UINT4(&sharedMemory[0x0DC]) = make_uint4(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
break;
case 7:
AS_UINT4(&sharedMemory[0x0E0]) = make_uint4(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
AS_UINT4(&sharedMemory[0x0E4]) = make_uint4(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
AS_UINT4(&sharedMemory[0x0E8]) = make_uint4(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
AS_UINT4(&sharedMemory[0x0EC]) = make_uint4(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
AS_UINT4(&sharedMemory[0x0F0]) = make_uint4(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
AS_UINT4(&sharedMemory[0x0F4]) = make_uint4(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
AS_UINT4(&sharedMemory[0x0F8]) = make_uint4(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
AS_UINT4(&sharedMemory[0x0FC]) = make_uint4(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
break;
}
// AES 1
switch (threadIdx.x) {
case 0:
AS_UINT4(&sharedMemory[0x100]) = make_uint4(0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d);
AS_UINT4(&sharedMemory[0x104]) = make_uint4(0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154);
AS_UINT4(&sharedMemory[0x108]) = make_uint4(0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d);
AS_UINT4(&sharedMemory[0x10C]) = make_uint4(0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a);
AS_UINT4(&sharedMemory[0x110]) = make_uint4(0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87);
AS_UINT4(&sharedMemory[0x114]) = make_uint4(0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b);
AS_UINT4(&sharedMemory[0x118]) = make_uint4(0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea);
AS_UINT4(&sharedMemory[0x11C]) = make_uint4(0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b);
break;
case 1:
AS_UINT4(&sharedMemory[0x120]) = make_uint4(0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a);
AS_UINT4(&sharedMemory[0x124]) = make_uint4(0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f);
AS_UINT4(&sharedMemory[0x128]) = make_uint4(0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908);
AS_UINT4(&sharedMemory[0x12C]) = make_uint4(0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f);
AS_UINT4(&sharedMemory[0x130]) = make_uint4(0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e);
AS_UINT4(&sharedMemory[0x134]) = make_uint4(0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5);
AS_UINT4(&sharedMemory[0x138]) = make_uint4(0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d);
AS_UINT4(&sharedMemory[0x13C]) = make_uint4(0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f);
break;
case 2:
AS_UINT4(&sharedMemory[0x140]) = make_uint4(0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e);
AS_UINT4(&sharedMemory[0x144]) = make_uint4(0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb);
AS_UINT4(&sharedMemory[0x148]) = make_uint4(0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce);
AS_UINT4(&sharedMemory[0x14C]) = make_uint4(0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397);
AS_UINT4(&sharedMemory[0x150]) = make_uint4(0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c);
AS_UINT4(&sharedMemory[0x154]) = make_uint4(0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed);
AS_UINT4(&sharedMemory[0x158]) = make_uint4(0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b);
AS_UINT4(&sharedMemory[0x15C]) = make_uint4(0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a);
break;
case 3:
AS_UINT4(&sharedMemory[0x160]) = make_uint4(0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16);
AS_UINT4(&sharedMemory[0x164]) = make_uint4(0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194);
AS_UINT4(&sharedMemory[0x168]) = make_uint4(0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81);
AS_UINT4(&sharedMemory[0x16C]) = make_uint4(0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3);
AS_UINT4(&sharedMemory[0x170]) = make_uint4(0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a);
AS_UINT4(&sharedMemory[0x174]) = make_uint4(0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104);
AS_UINT4(&sharedMemory[0x178]) = make_uint4(0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263);
AS_UINT4(&sharedMemory[0x17C]) = make_uint4(0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d);
break;
case 4:
AS_UINT4(&sharedMemory[0x180]) = make_uint4(0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f);
AS_UINT4(&sharedMemory[0x184]) = make_uint4(0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39);
AS_UINT4(&sharedMemory[0x188]) = make_uint4(0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47);
AS_UINT4(&sharedMemory[0x18C]) = make_uint4(0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695);
AS_UINT4(&sharedMemory[0x190]) = make_uint4(0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f);
AS_UINT4(&sharedMemory[0x194]) = make_uint4(0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83);
AS_UINT4(&sharedMemory[0x198]) = make_uint4(0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c);
AS_UINT4(&sharedMemory[0x19C]) = make_uint4(0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76);
break;
case 5:
AS_UINT4(&sharedMemory[0x1A0]) = make_uint4(0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e);
AS_UINT4(&sharedMemory[0x1A4]) = make_uint4(0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4);
AS_UINT4(&sharedMemory[0x1A8]) = make_uint4(0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6);
AS_UINT4(&sharedMemory[0x1AC]) = make_uint4(0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b);
AS_UINT4(&sharedMemory[0x1B0]) = make_uint4(0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7);
AS_UINT4(&sharedMemory[0x1B4]) = make_uint4(0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0);
AS_UINT4(&sharedMemory[0x1B8]) = make_uint4(0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25);
AS_UINT4(&sharedMemory[0x1BC]) = make_uint4(0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018);
break;
case 6:
AS_UINT4(&sharedMemory[0x1C0]) = make_uint4(0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72);
AS_UINT4(&sharedMemory[0x1C4]) = make_uint4(0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751);
AS_UINT4(&sharedMemory[0x1C8]) = make_uint4(0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21);
AS_UINT4(&sharedMemory[0x1CC]) = make_uint4(0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85);
AS_UINT4(&sharedMemory[0x1D0]) = make_uint4(0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa);
AS_UINT4(&sharedMemory[0x1D4]) = make_uint4(0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12);
AS_UINT4(&sharedMemory[0x1D8]) = make_uint4(0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0);
AS_UINT4(&sharedMemory[0x1DC]) = make_uint4(0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9);
break;
case 7:
AS_UINT4(&sharedMemory[0x1E0]) = make_uint4(0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233);
AS_UINT4(&sharedMemory[0x1E4]) = make_uint4(0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7);
AS_UINT4(&sharedMemory[0x1E8]) = make_uint4(0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920);
AS_UINT4(&sharedMemory[0x1EC]) = make_uint4(0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a);
AS_UINT4(&sharedMemory[0x1F0]) = make_uint4(0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17);
AS_UINT4(&sharedMemory[0x1F4]) = make_uint4(0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8);
AS_UINT4(&sharedMemory[0x1F8]) = make_uint4(0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11);
AS_UINT4(&sharedMemory[0x1FC]) = make_uint4(0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a);
break;
}
// AES 2
switch (threadIdx.x) {
case 0:
AS_UINT4(&sharedMemory[0x200]) = make_uint4(0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b);
AS_UINT4(&sharedMemory[0x204]) = make_uint4(0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5);
AS_UINT4(&sharedMemory[0x208]) = make_uint4(0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b);
AS_UINT4(&sharedMemory[0x20C]) = make_uint4(0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76);
AS_UINT4(&sharedMemory[0x210]) = make_uint4(0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d);
AS_UINT4(&sharedMemory[0x214]) = make_uint4(0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0);
AS_UINT4(&sharedMemory[0x218]) = make_uint4(0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf);
AS_UINT4(&sharedMemory[0x21C]) = make_uint4(0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0);
break;
case 1:
AS_UINT4(&sharedMemory[0x220]) = make_uint4(0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26);
AS_UINT4(&sharedMemory[0x224]) = make_uint4(0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc);
AS_UINT4(&sharedMemory[0x228]) = make_uint4(0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1);
AS_UINT4(&sharedMemory[0x22C]) = make_uint4(0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15);
AS_UINT4(&sharedMemory[0x230]) = make_uint4(0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3);
AS_UINT4(&sharedMemory[0x234]) = make_uint4(0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a);
AS_UINT4(&sharedMemory[0x238]) = make_uint4(0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2);
AS_UINT4(&sharedMemory[0x23C]) = make_uint4(0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75);
break;
case 2:
AS_UINT4(&sharedMemory[0x240]) = make_uint4(0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a);
AS_UINT4(&sharedMemory[0x244]) = make_uint4(0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0);
AS_UINT4(&sharedMemory[0x248]) = make_uint4(0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3);
AS_UINT4(&sharedMemory[0x24C]) = make_uint4(0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784);
AS_UINT4(&sharedMemory[0x250]) = make_uint4(0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced);
AS_UINT4(&sharedMemory[0x254]) = make_uint4(0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b);
AS_UINT4(&sharedMemory[0x258]) = make_uint4(0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39);
AS_UINT4(&sharedMemory[0x25C]) = make_uint4(0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf);
break;
case 3:
AS_UINT4(&sharedMemory[0x260]) = make_uint4(0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb);
AS_UINT4(&sharedMemory[0x264]) = make_uint4(0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485);
AS_UINT4(&sharedMemory[0x268]) = make_uint4(0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f);
AS_UINT4(&sharedMemory[0x26C]) = make_uint4(0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8);
AS_UINT4(&sharedMemory[0x270]) = make_uint4(0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f);
AS_UINT4(&sharedMemory[0x274]) = make_uint4(0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5);
AS_UINT4(&sharedMemory[0x278]) = make_uint4(0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321);
AS_UINT4(&sharedMemory[0x27C]) = make_uint4(0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2);
break;
case 4:
AS_UINT4(&sharedMemory[0x280]) = make_uint4(0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec);
AS_UINT4(&sharedMemory[0x284]) = make_uint4(0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917);
AS_UINT4(&sharedMemory[0x288]) = make_uint4(0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d);
AS_UINT4(&sharedMemory[0x28C]) = make_uint4(0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573);
AS_UINT4(&sharedMemory[0x290]) = make_uint4(0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc);
AS_UINT4(&sharedMemory[0x294]) = make_uint4(0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388);
AS_UINT4(&sharedMemory[0x298]) = make_uint4(0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14);
AS_UINT4(&sharedMemory[0x29C]) = make_uint4(0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db);
break;
case 5:
AS_UINT4(&sharedMemory[0x2A0]) = make_uint4(0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a);
AS_UINT4(&sharedMemory[0x2A4]) = make_uint4(0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c);
AS_UINT4(&sharedMemory[0x2A8]) = make_uint4(0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662);
AS_UINT4(&sharedMemory[0x2AC]) = make_uint4(0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79);
AS_UINT4(&sharedMemory[0x2B0]) = make_uint4(0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d);
AS_UINT4(&sharedMemory[0x2B4]) = make_uint4(0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9);
AS_UINT4(&sharedMemory[0x2B8]) = make_uint4(0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea);
AS_UINT4(&sharedMemory[0x2BC]) = make_uint4(0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808);
break;
case 6:
AS_UINT4(&sharedMemory[0x2C0]) = make_uint4(0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e);
AS_UINT4(&sharedMemory[0x2C4]) = make_uint4(0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6);
AS_UINT4(&sharedMemory[0x2C8]) = make_uint4(0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f);
AS_UINT4(&sharedMemory[0x2CC]) = make_uint4(0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a);
AS_UINT4(&sharedMemory[0x2D0]) = make_uint4(0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66);
AS_UINT4(&sharedMemory[0x2D4]) = make_uint4(0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e);
AS_UINT4(&sharedMemory[0x2D8]) = make_uint4(0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9);
AS_UINT4(&sharedMemory[0x2DC]) = make_uint4(0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e);
break;
case 7:
AS_UINT4(&sharedMemory[0x2E0]) = make_uint4(0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311);
AS_UINT4(&sharedMemory[0x2E4]) = make_uint4(0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794);
AS_UINT4(&sharedMemory[0x2E8]) = make_uint4(0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9);
AS_UINT4(&sharedMemory[0x2EC]) = make_uint4(0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf);
AS_UINT4(&sharedMemory[0x2F0]) = make_uint4(0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d);
AS_UINT4(&sharedMemory[0x2F4]) = make_uint4(0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868);
AS_UINT4(&sharedMemory[0x2F8]) = make_uint4(0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f);
AS_UINT4(&sharedMemory[0x2FC]) = make_uint4(0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16);
break;
}
// AES 3
switch (threadIdx.x) {
case 0:
AS_UINT4(&sharedMemory[0x300]) = make_uint4(0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b);
AS_UINT4(&sharedMemory[0x304]) = make_uint4(0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5);
AS_UINT4(&sharedMemory[0x308]) = make_uint4(0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b);
AS_UINT4(&sharedMemory[0x30C]) = make_uint4(0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676);
AS_UINT4(&sharedMemory[0x310]) = make_uint4(0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d);
AS_UINT4(&sharedMemory[0x314]) = make_uint4(0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0);
AS_UINT4(&sharedMemory[0x318]) = make_uint4(0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf);
AS_UINT4(&sharedMemory[0x31C]) = make_uint4(0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0);
break;
case 1:
AS_UINT4(&sharedMemory[0x320]) = make_uint4(0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626);
AS_UINT4(&sharedMemory[0x324]) = make_uint4(0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc);
AS_UINT4(&sharedMemory[0x328]) = make_uint4(0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1);
AS_UINT4(&sharedMemory[0x32C]) = make_uint4(0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515);
AS_UINT4(&sharedMemory[0x330]) = make_uint4(0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3);
AS_UINT4(&sharedMemory[0x334]) = make_uint4(0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a);
AS_UINT4(&sharedMemory[0x338]) = make_uint4(0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2);
AS_UINT4(&sharedMemory[0x33C]) = make_uint4(0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575);
break;
case 2:
AS_UINT4(&sharedMemory[0x340]) = make_uint4(0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a);
AS_UINT4(&sharedMemory[0x344]) = make_uint4(0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0);
AS_UINT4(&sharedMemory[0x348]) = make_uint4(0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3);
AS_UINT4(&sharedMemory[0x34C]) = make_uint4(0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484);
AS_UINT4(&sharedMemory[0x350]) = make_uint4(0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded);
AS_UINT4(&sharedMemory[0x354]) = make_uint4(0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b);
AS_UINT4(&sharedMemory[0x358]) = make_uint4(0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939);
AS_UINT4(&sharedMemory[0x35C]) = make_uint4(0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf);
break;
case 3:
AS_UINT4(&sharedMemory[0x360]) = make_uint4(0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb);
AS_UINT4(&sharedMemory[0x364]) = make_uint4(0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585);
AS_UINT4(&sharedMemory[0x368]) = make_uint4(0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f);
AS_UINT4(&sharedMemory[0x36C]) = make_uint4(0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8);
AS_UINT4(&sharedMemory[0x370]) = make_uint4(0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f);
AS_UINT4(&sharedMemory[0x374]) = make_uint4(0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5);
AS_UINT4(&sharedMemory[0x378]) = make_uint4(0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121);
AS_UINT4(&sharedMemory[0x37C]) = make_uint4(0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2);
break;
case 4:
AS_UINT4(&sharedMemory[0x380]) = make_uint4(0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec);
AS_UINT4(&sharedMemory[0x384]) = make_uint4(0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717);
AS_UINT4(&sharedMemory[0x388]) = make_uint4(0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d);
AS_UINT4(&sharedMemory[0x38C]) = make_uint4(0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373);
AS_UINT4(&sharedMemory[0x390]) = make_uint4(0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc);
AS_UINT4(&sharedMemory[0x394]) = make_uint4(0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888);
AS_UINT4(&sharedMemory[0x398]) = make_uint4(0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414);
AS_UINT4(&sharedMemory[0x39C]) = make_uint4(0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb);
break;
case 5:
AS_UINT4(&sharedMemory[0x3A0]) = make_uint4(0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a);
AS_UINT4(&sharedMemory[0x3A4]) = make_uint4(0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c);
AS_UINT4(&sharedMemory[0x3A8]) = make_uint4(0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262);
AS_UINT4(&sharedMemory[0x3AC]) = make_uint4(0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979);
AS_UINT4(&sharedMemory[0x3B0]) = make_uint4(0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d);
AS_UINT4(&sharedMemory[0x3B4]) = make_uint4(0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9);
AS_UINT4(&sharedMemory[0x3B8]) = make_uint4(0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea);
AS_UINT4(&sharedMemory[0x3BC]) = make_uint4(0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808);
break;
case 6:
AS_UINT4(&sharedMemory[0x3C0]) = make_uint4(0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e);
AS_UINT4(&sharedMemory[0x3C4]) = make_uint4(0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6);
AS_UINT4(&sharedMemory[0x3C8]) = make_uint4(0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f);
AS_UINT4(&sharedMemory[0x3CC]) = make_uint4(0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a);
AS_UINT4(&sharedMemory[0x3D0]) = make_uint4(0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666);
AS_UINT4(&sharedMemory[0x3D4]) = make_uint4(0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e);
AS_UINT4(&sharedMemory[0x3D8]) = make_uint4(0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9);
AS_UINT4(&sharedMemory[0x3DC]) = make_uint4(0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e);
break;
case 7:
AS_UINT4(&sharedMemory[0x3E0]) = make_uint4(0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111);
AS_UINT4(&sharedMemory[0x3E4]) = make_uint4(0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494);
AS_UINT4(&sharedMemory[0x3E8]) = make_uint4(0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9);
AS_UINT4(&sharedMemory[0x3EC]) = make_uint4(0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf);
AS_UINT4(&sharedMemory[0x3F0]) = make_uint4(0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d);
AS_UINT4(&sharedMemory[0x3F4]) = make_uint4(0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868);
AS_UINT4(&sharedMemory[0x3F8]) = make_uint4(0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f);
AS_UINT4(&sharedMemory[0x3FC]) = make_uint4(0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616);
break;
}
}
+180
View File
@@ -0,0 +1,180 @@
//#include <cuda_helper.h>
typedef struct {
uint32_t h[8], s[4], t[2];
int buflen, nullt;
uint8_t buf[64];
} blake_state;
#define U8TO32(p) \
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
#define U32TO8(p, v) \
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
#define BLAKE_ROT(x,n) ROTR32(x, n)
#define BLAKE_G(a,b,c,d,e) \
v[a] += (m[d_blake_sigma[i][e]] ^ d_blake_cst[d_blake_sigma[i][e+1]]) + v[b]; \
v[d] = BLAKE_ROT(v[d] ^ v[a],16); \
v[c] += v[d]; \
v[b] = BLAKE_ROT(v[b] ^ v[c],12); \
v[a] += (m[d_blake_sigma[i][e+1]] ^ d_blake_cst[d_blake_sigma[i][e]]) + v[b]; \
v[d] = BLAKE_ROT(v[d] ^ v[a], 8); \
v[c] += v[d]; \
v[b] = BLAKE_ROT(v[b] ^ v[c], 7);
__constant__ uint8_t d_blake_sigma[14][16] = {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}
};
__constant__ uint32_t d_blake_cst[16] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
};
__device__
void cn_blake_compress(blake_state * __restrict__ S, const uint8_t * __restrict__ block)
{
uint32_t v[16], m[16], i;
for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4);
for (i = 0; i < 8; ++i) v[i] = S->h[i];
v[ 8] = S->s[0] ^ 0x243F6A88;
v[ 9] = S->s[1] ^ 0x85A308D3;
v[10] = S->s[2] ^ 0x13198A2E;
v[11] = S->s[3] ^ 0x03707344;
v[12] = 0xA4093822;
v[13] = 0x299F31D0;
v[14] = 0x082EFA98;
v[15] = 0xEC4E6C89;
if (S->nullt == 0) {
v[12] ^= S->t[0];
v[13] ^= S->t[0];
v[14] ^= S->t[1];
v[15] ^= S->t[1];
}
for (i = 0; i < 14; ++i) {
BLAKE_G(0, 4, 8, 12, 0);
BLAKE_G(1, 5, 9, 13, 2);
BLAKE_G(2, 6, 10, 14, 4);
BLAKE_G(3, 7, 11, 15, 6);
BLAKE_G(3, 4, 9, 14, 14);
BLAKE_G(2, 7, 8, 13, 12);
BLAKE_G(0, 5, 10, 15, 8);
BLAKE_G(1, 6, 11, 12, 10);
}
for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i];
for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4];
}
__device__ void cn_blake_update(blake_state * __restrict__ S, const uint8_t * __restrict__ data, uint64_t datalen)
{
int left = S->buflen >> 3;
int fill = 64 - left;
if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) {
memcpy((void *) (S->buf + left), (void *) data, fill);
S->t[0] += 512;
if (S->t[0] == 0) S->t[1]++;
cn_blake_compress(S, S->buf);
data += fill;
datalen -= (fill << 3);
left = 0;
}
while (datalen >= 512) {
S->t[0] += 512;
if (S->t[0] == 0) S->t[1]++;
cn_blake_compress(S, data);
data += 64;
datalen -= 512;
}
if (datalen > 0) {
memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
S->buflen = (left << 3) + datalen;
} else {
S->buflen = 0;
}
}
__device__
void cn_blake_final(blake_state * __restrict__ S, uint8_t * __restrict__ digest)
{
const uint8_t padding[] = {
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
uint8_t pa = 0x81, pb = 0x01;
uint8_t msglen[8];
uint32_t lo = S->t[0] + S->buflen, hi = S->t[1];
if (lo < (unsigned) S->buflen) hi++;
U32TO8(msglen + 0, hi);
U32TO8(msglen + 4, lo);
if (S->buflen == 440) {
S->t[0] -= 8;
cn_blake_update(S, &pa, 8);
} else {
if (S->buflen < 440) {
if (S->buflen == 0) S->nullt = 1;
S->t[0] -= 440 - S->buflen;
cn_blake_update(S, padding, 440 - S->buflen);
} else {
S->t[0] -= 512 - S->buflen;
cn_blake_update(S, padding, 512 - S->buflen);
S->t[0] -= 440;
cn_blake_update(S, padding + 1, 440);
S->nullt = 1;
}
cn_blake_update(S, &pb, 8);
S->t[0] -= 8;
}
S->t[0] -= 64;
cn_blake_update(S, msglen, 64);
U32TO8(digest + 0, S->h[0]);
U32TO8(digest + 4, S->h[1]);
U32TO8(digest + 8, S->h[2]);
U32TO8(digest + 12, S->h[3]);
U32TO8(digest + 16, S->h[4]);
U32TO8(digest + 20, S->h[5]);
U32TO8(digest + 24, S->h[6]);
U32TO8(digest + 28, S->h[7]);
}
__device__
void cn_blake(const uint8_t * __restrict__ in, uint64_t inlen, uint32_t * out)
{
blake_state bs;
blake_state *S = (blake_state *)&bs;
S->h[0] = 0x6A09E667; S->h[1] = 0xBB67AE85; S->h[2] = 0x3C6EF372;
S->h[3] = 0xA54FF53A; S->h[4] = 0x510E527F; S->h[5] = 0x9B05688C;
S->h[6] = 0x1F83D9AB; S->h[7] = 0x5BE0CD19;
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
cn_blake_update(S, (uint8_t *)in, inlen * 8);
cn_blake_final(S, (uint8_t *)out);
}
+348
View File
@@ -0,0 +1,348 @@
#define GROESTL_ROWS 8
#define GROESTL_LENGTHFIELDLEN GROESTL_ROWS
#define GROESTL_COLS512 8
#define GROESTL_SIZE512 (GROESTL_ROWS*GROESTL_COLS512)
#define GROESTL_ROUNDS512 10
#define GROESTL_HASH_BIT_LEN 256
#define GROESTL_ROTL32(v, n) ROTL32(v, n)
#define li_32(h) 0x##h##u
#define GROESTL_EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n)))
#define u32BIG(a) \
((GROESTL_ROTL32(a,8) & li_32(00FF00FF)) | \
(GROESTL_ROTL32(a,24) & li_32(FF00FF00)))
typedef struct {
uint32_t chaining[GROESTL_SIZE512/sizeof(uint32_t)];
uint32_t block_counter1, block_counter2;
BitSequence buffer[GROESTL_SIZE512];
int buf_ptr;
int bits_in_last_byte;
} groestlHashState;
__constant__ uint32_t d_groestl_T[512] = {
0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0x0d17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc,
0x50f09060, 0x6050c0f0, 0x03050702, 0x02030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5,
0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0x0b1de6fb, 0xfb0bed1d,
0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded,
0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x0206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1,
0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x0818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441,
0x0c141c08, 0x080c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0x0f111b0a, 0x0a0f1411, 0xb5c4eb2f, 0x2fb55ec4,
0x091b150e, 0x0e091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba,
0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616,
0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2,
0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0, 0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c,
0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de,
0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7,
0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x060a0e04, 0x0406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e,
0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x058a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x040cfdf1, 0xf104f90c,
0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0x0e12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7,
0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b,
0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4,
0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e,
0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a,
0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0x0a1e120c, 0x0c0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37,
0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86,
0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x018c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b,
0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x0709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028,
0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3,
0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0x0d861a91, 0x85949b0f, 0xf851e94,
0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x050f0906, 0x06050c0f, 0x0103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836,
0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0,
0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x07890e80, 0xa7f2c133, 0x33a766f2,
0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e,
0x8f8a8903, 0x038f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x0980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3,
0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e
};
#define GROESTL_ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) { \
temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \
v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \
v1 = temp_var; \
}
#define GROESTL_COLUMN(x,y,i, c0,c1,c2,c3,c4,c5,c6,c7, tv1,tv2,tu,tl,t) \
tu = d_groestl_T[2*(uint32_t)x[4*c0+0]]; \
tl = d_groestl_T[2*(uint32_t)x[4*c0+0]+1]; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c1+1]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c1+1]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \
tu ^= tv1; \
tl ^= tv2; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c2+2]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c2+2]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \
tu ^= tv1; \
tl ^= tv2; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c3+3]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c3+3]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \
tu ^= tv1; \
tl ^= tv2; \
tl ^= d_groestl_T[2*(uint32_t)x[4*c4+0]]; \
tu ^= d_groestl_T[2*(uint32_t)x[4*c4+0]+1]; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c5+1]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c5+1]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \
tl ^= tv1; \
tu ^= tv2; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c6+2]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c6+2]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \
tl ^= tv1; \
tu ^= tv2; \
tv1 = d_groestl_T[2*(uint32_t)x[4*c7+3]]; \
tv2 = d_groestl_T[2*(uint32_t)x[4*c7+3]+1]; \
GROESTL_ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \
tl ^= tv1; \
tu ^= tv2; \
y[i] = tu; \
y[i+1] = tl;
__device__
void cn_groestl_RND512P(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r)
{
uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
uint32_t* x32 = (uint32_t*)x;
x32[ 0] ^= 0x00000000^r;
x32[ 2] ^= 0x00000010^r;
x32[ 4] ^= 0x00000020^r;
x32[ 6] ^= 0x00000030^r;
x32[ 8] ^= 0x00000040^r;
x32[10] ^= 0x00000050^r;
x32[12] ^= 0x00000060^r;
x32[14] ^= 0x00000070^r;
GROESTL_COLUMN(x,y, 0, 0, 2, 4, 6, 9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 2, 2, 4, 6, 8, 11, 13, 15, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 4, 4, 6, 8, 10, 13, 15, 1, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 6, 6, 8, 10, 12, 15, 1, 3, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 8, 8, 10, 12, 14, 1, 3, 5, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,10, 10, 12, 14, 0, 3, 5, 7, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,12, 12, 14, 0, 2, 5, 7, 9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,14, 14, 0, 2, 4, 7, 9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
}
__device__
void cn_groestl_RND512Q(uint8_t * __restrict__ x, uint32_t * __restrict__ y, uint32_t r)
{
uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
uint32_t* x32 = (uint32_t*)x;
x32[ 0] = ~x32[ 0];
x32[ 1] ^= 0xffffffff^r;
x32[ 2] = ~x32[ 2];
x32[ 3] ^= 0xefffffff^r;
x32[ 4] = ~x32[ 4];
x32[ 5] ^= 0xdfffffff^r;
x32[ 6] = ~x32[ 6];
x32[ 7] ^= 0xcfffffff^r;
x32[ 8] = ~x32[ 8];
x32[ 9] ^= 0xbfffffff^r;
x32[10] = ~x32[10];
x32[11] ^= 0xafffffff^r;
x32[12] = ~x32[12];
x32[13] ^= 0x9fffffff^r;
x32[14] = ~x32[14];
x32[15] ^= 0x8fffffff^r;
GROESTL_COLUMN(x,y, 0, 2, 6, 10, 14, 1, 5, 9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 2, 4, 8, 12, 0, 3, 7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 4, 6, 10, 14, 2, 5, 9, 13, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 6, 8, 12, 0, 4, 7, 11, 15, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y, 8, 10, 14, 2, 6, 9, 13, 1, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,10, 12, 0, 4, 8, 11, 15, 3, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,12, 14, 2, 6, 10, 13, 1, 5, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
GROESTL_COLUMN(x,y,14, 0, 4, 8, 12, 15, 3, 7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
}
__device__
void cn_groestl_F512(uint32_t * __restrict__ h, const uint32_t * __restrict__ m)
{
int i;
uint32_t Ptmp[2*GROESTL_COLS512];
uint32_t Qtmp[2*GROESTL_COLS512];
uint32_t y[2*GROESTL_COLS512];
uint32_t z[2*GROESTL_COLS512];
for (i = 0; i < 2*GROESTL_COLS512; i++) {
z[i] = m[i];
Ptmp[i] = h[i]^m[i];
}
cn_groestl_RND512Q((uint8_t*)z, y, 0x00000000);
cn_groestl_RND512Q((uint8_t*)y, z, 0x01000000);
cn_groestl_RND512Q((uint8_t*)z, y, 0x02000000);
cn_groestl_RND512Q((uint8_t*)y, z, 0x03000000);
cn_groestl_RND512Q((uint8_t*)z, y, 0x04000000);
cn_groestl_RND512Q((uint8_t*)y, z, 0x05000000);
cn_groestl_RND512Q((uint8_t*)z, y, 0x06000000);
cn_groestl_RND512Q((uint8_t*)y, z, 0x07000000);
cn_groestl_RND512Q((uint8_t*)z, y, 0x08000000);
cn_groestl_RND512Q((uint8_t*)y, Qtmp, 0x09000000);
cn_groestl_RND512P((uint8_t*)Ptmp, y, 0x00000000);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000001);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000002);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000003);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000004);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000005);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000006);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000007);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000008);
cn_groestl_RND512P((uint8_t*)y, Ptmp, 0x00000009);
for (i = 0; i < 2*GROESTL_COLS512; i++)
h[i] ^= Ptmp[i]^Qtmp[i];
}
__device__
void cn_groestl_outputtransformation(groestlHashState *ctx)
{
int j;
uint32_t temp[2*GROESTL_COLS512];
uint32_t y[2*GROESTL_COLS512];
uint32_t z[2*GROESTL_COLS512];
for (j = 0; j < 2*GROESTL_COLS512; j++)
temp[j] = ctx->chaining[j];
cn_groestl_RND512P((uint8_t*)temp, y, 0x00000000);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000001);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000002);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000003);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000004);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000005);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000006);
cn_groestl_RND512P((uint8_t*)y, z, 0x00000007);
cn_groestl_RND512P((uint8_t*)z, y, 0x00000008);
cn_groestl_RND512P((uint8_t*)y, temp, 0x00000009);
for (j = 0; j < 2*GROESTL_COLS512; j++)
ctx->chaining[j] ^= temp[j];
}
__device__
void cn_groestl_transform(groestlHashState * __restrict__ ctx,
const uint8_t * __restrict__ input, int msglen)
{
for (; msglen >= GROESTL_SIZE512; msglen -= GROESTL_SIZE512, input += GROESTL_SIZE512) {
cn_groestl_F512(ctx->chaining,(uint32_t*)input);
ctx->block_counter1++;
if (ctx->block_counter1 == 0) ctx->block_counter2++;
}
}
__device__
void cn_groestl_final(groestlHashState* __restrict__ ctx, BitSequence* __restrict__ output)
{
int i, j = 0, hashbytelen = GROESTL_HASH_BIT_LEN/8;
uint8_t *s = (BitSequence*)ctx->chaining;
if (ctx->bits_in_last_byte) {
ctx->buffer[(int)ctx->buf_ptr-1] &= ((1<<ctx->bits_in_last_byte)-1)<<(8-ctx->bits_in_last_byte);
ctx->buffer[(int)ctx->buf_ptr-1] ^= 0x1<<(7-ctx->bits_in_last_byte);
ctx->bits_in_last_byte = 0;
}
else ctx->buffer[(int)ctx->buf_ptr++] = 0x80;
if (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
while (ctx->buf_ptr < GROESTL_SIZE512) {
ctx->buffer[(int)ctx->buf_ptr++] = 0;
}
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
ctx->buf_ptr = 0;
}
while (ctx->buf_ptr < GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
ctx->buffer[(int)ctx->buf_ptr++] = 0;
}
ctx->block_counter1++;
if (ctx->block_counter1 == 0) ctx->block_counter2++;
ctx->buf_ptr = GROESTL_SIZE512;
while (ctx->buf_ptr > GROESTL_SIZE512-(int)sizeof(uint32_t)) {
ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter1;
ctx->block_counter1 >>= 8;
}
while (ctx->buf_ptr > GROESTL_SIZE512-GROESTL_LENGTHFIELDLEN) {
ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter2;
ctx->block_counter2 >>= 8;
}
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
cn_groestl_outputtransformation(ctx);
for (i = GROESTL_SIZE512-hashbytelen; i < GROESTL_SIZE512; i++,j++) {
output[j] = s[i];
}
#if 0
for (i = 0; i < GROESTL_COLS512; i++) {
ctx->chaining[i] = 0;
}
for (i = 0; i < GROESTL_SIZE512; i++) {
ctx->buffer[i] = 0;
}
#endif
}
__device__
void cn_groestl_update(groestlHashState* __restrict__ ctx,
const BitSequence* __restrict__ input, DataLength databitlen)
{
int index = 0;
int msglen = (int)(databitlen/8);
int rem = (int)(databitlen%8);
if (ctx->buf_ptr) {
while (ctx->buf_ptr < GROESTL_SIZE512 && index < msglen) {
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
}
if (ctx->buf_ptr < GROESTL_SIZE512) {
if (rem) {
ctx->bits_in_last_byte = rem;
ctx->buffer[(int)ctx->buf_ptr++] = input[index];
}
return;
}
ctx->buf_ptr = 0;
cn_groestl_transform(ctx, ctx->buffer, GROESTL_SIZE512);
}
cn_groestl_transform(ctx, input+index, msglen-index);
index += ((msglen-index)/GROESTL_SIZE512)*GROESTL_SIZE512;
while (index < msglen) {
ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
}
if (rem) {
ctx->bits_in_last_byte = rem;
ctx->buffer[(int)ctx->buf_ptr++] = input[index];
}
}
__device__
void cn_groestl_init(groestlHashState* ctx)
{
int i = 0;
for(;i<(GROESTL_SIZE512/sizeof(uint32_t));i++)
ctx->chaining[i] = 0;
ctx->chaining[2*GROESTL_COLS512-1] = u32BIG((uint32_t)GROESTL_HASH_BIT_LEN);
ctx->buf_ptr = 0;
ctx->block_counter1 = 0;
ctx->block_counter2 = 0;
ctx->bits_in_last_byte = 0;
}
__device__
void cn_groestl(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
{
DataLength databitlen = len << 3;
groestlHashState context;
cn_groestl_init(&context);
cn_groestl_update(&context, (BitSequence*) data, databitlen);
cn_groestl_final(&context, (BitSequence*) hashval);
}
+296
View File
@@ -0,0 +1,296 @@
typedef struct {
int hashbitlen;
unsigned long long databitlen;
unsigned long long datasize_in_buffer;
uint64_t x[8][2];
unsigned char buffer[64];
} jhHashState;
__constant__ unsigned char d_JH256_H0[512] = {
0xeb, 0x98, 0xa3, 0x41, 0x2c, 0x20, 0xd3, 0xeb, 0x92, 0xcd, 0xbe, 0x7b, 0x9c, 0xb2, 0x45, 0xc1,
0x1c, 0x93, 0x51, 0x91, 0x60, 0xd4, 0xc7, 0xfa, 0x26, 0x0, 0x82, 0xd6, 0x7e, 0x50, 0x8a, 0x3,
0xa4, 0x23, 0x9e, 0x26, 0x77, 0x26, 0xb9, 0x45, 0xe0, 0xfb, 0x1a, 0x48, 0xd4, 0x1a, 0x94, 0x77,
0xcd, 0xb5, 0xab, 0x26, 0x2, 0x6b, 0x17, 0x7a, 0x56, 0xf0, 0x24, 0x42, 0xf, 0xff, 0x2f, 0xa8,
0x71, 0xa3, 0x96, 0x89, 0x7f, 0x2e, 0x4d, 0x75, 0x1d, 0x14, 0x49, 0x8, 0xf7, 0x7d, 0xe2, 0x62,
0x27, 0x76, 0x95, 0xf7, 0x76, 0x24, 0x8f, 0x94, 0x87, 0xd5, 0xb6, 0x57, 0x47, 0x80, 0x29, 0x6c,
0x5c, 0x5e, 0x27, 0x2d, 0xac, 0x8e, 0xd, 0x6c, 0x51, 0x84, 0x50, 0xc6, 0x57, 0x5, 0x7a, 0xf,
0x7b, 0xe4, 0xd3, 0x67, 0x70, 0x24, 0x12, 0xea, 0x89, 0xe3, 0xab, 0x13, 0xd3, 0x1c, 0xd7, 0x69
};
__constant__ unsigned char d_E8_rc[42][32] = {
{0x72, 0xd5, 0xde, 0xa2, 0xdf, 0x15, 0xf8, 0x67, 0x7b, 0x84, 0x15, 0xa, 0xb7, 0x23, 0x15, 0x57, 0x81, 0xab, 0xd6, 0x90, 0x4d, 0x5a, 0x87, 0xf6, 0x4e, 0x9f, 0x4f, 0xc5, 0xc3, 0xd1, 0x2b, 0x40},
{0xea, 0x98, 0x3a, 0xe0, 0x5c, 0x45, 0xfa, 0x9c, 0x3, 0xc5, 0xd2, 0x99, 0x66, 0xb2, 0x99, 0x9a, 0x66, 0x2, 0x96, 0xb4, 0xf2, 0xbb, 0x53, 0x8a, 0xb5, 0x56, 0x14, 0x1a, 0x88, 0xdb, 0xa2, 0x31},
{0x3, 0xa3, 0x5a, 0x5c, 0x9a, 0x19, 0xe, 0xdb, 0x40, 0x3f, 0xb2, 0xa, 0x87, 0xc1, 0x44, 0x10, 0x1c, 0x5, 0x19, 0x80, 0x84, 0x9e, 0x95, 0x1d, 0x6f, 0x33, 0xeb, 0xad, 0x5e, 0xe7, 0xcd, 0xdc},
{0x10, 0xba, 0x13, 0x92, 0x2, 0xbf, 0x6b, 0x41, 0xdc, 0x78, 0x65, 0x15, 0xf7, 0xbb, 0x27, 0xd0, 0xa, 0x2c, 0x81, 0x39, 0x37, 0xaa, 0x78, 0x50, 0x3f, 0x1a, 0xbf, 0xd2, 0x41, 0x0, 0x91, 0xd3},
{0x42, 0x2d, 0x5a, 0xd, 0xf6, 0xcc, 0x7e, 0x90, 0xdd, 0x62, 0x9f, 0x9c, 0x92, 0xc0, 0x97, 0xce, 0x18, 0x5c, 0xa7, 0xb, 0xc7, 0x2b, 0x44, 0xac, 0xd1, 0xdf, 0x65, 0xd6, 0x63, 0xc6, 0xfc, 0x23},
{0x97, 0x6e, 0x6c, 0x3, 0x9e, 0xe0, 0xb8, 0x1a, 0x21, 0x5, 0x45, 0x7e, 0x44, 0x6c, 0xec, 0xa8, 0xee, 0xf1, 0x3, 0xbb, 0x5d, 0x8e, 0x61, 0xfa, 0xfd, 0x96, 0x97, 0xb2, 0x94, 0x83, 0x81, 0x97},
{0x4a, 0x8e, 0x85, 0x37, 0xdb, 0x3, 0x30, 0x2f, 0x2a, 0x67, 0x8d, 0x2d, 0xfb, 0x9f, 0x6a, 0x95, 0x8a, 0xfe, 0x73, 0x81, 0xf8, 0xb8, 0x69, 0x6c, 0x8a, 0xc7, 0x72, 0x46, 0xc0, 0x7f, 0x42, 0x14},
{0xc5, 0xf4, 0x15, 0x8f, 0xbd, 0xc7, 0x5e, 0xc4, 0x75, 0x44, 0x6f, 0xa7, 0x8f, 0x11, 0xbb, 0x80, 0x52, 0xde, 0x75, 0xb7, 0xae, 0xe4, 0x88, 0xbc, 0x82, 0xb8, 0x0, 0x1e, 0x98, 0xa6, 0xa3, 0xf4},
{0x8e, 0xf4, 0x8f, 0x33, 0xa9, 0xa3, 0x63, 0x15, 0xaa, 0x5f, 0x56, 0x24, 0xd5, 0xb7, 0xf9, 0x89, 0xb6, 0xf1, 0xed, 0x20, 0x7c, 0x5a, 0xe0, 0xfd, 0x36, 0xca, 0xe9, 0x5a, 0x6, 0x42, 0x2c, 0x36},
{0xce, 0x29, 0x35, 0x43, 0x4e, 0xfe, 0x98, 0x3d, 0x53, 0x3a, 0xf9, 0x74, 0x73, 0x9a, 0x4b, 0xa7, 0xd0, 0xf5, 0x1f, 0x59, 0x6f, 0x4e, 0x81, 0x86, 0xe, 0x9d, 0xad, 0x81, 0xaf, 0xd8, 0x5a, 0x9f},
{0xa7, 0x5, 0x6, 0x67, 0xee, 0x34, 0x62, 0x6a, 0x8b, 0xb, 0x28, 0xbe, 0x6e, 0xb9, 0x17, 0x27, 0x47, 0x74, 0x7, 0x26, 0xc6, 0x80, 0x10, 0x3f, 0xe0, 0xa0, 0x7e, 0x6f, 0xc6, 0x7e, 0x48, 0x7b},
{0xd, 0x55, 0xa, 0xa5, 0x4a, 0xf8, 0xa4, 0xc0, 0x91, 0xe3, 0xe7, 0x9f, 0x97, 0x8e, 0xf1, 0x9e, 0x86, 0x76, 0x72, 0x81, 0x50, 0x60, 0x8d, 0xd4, 0x7e, 0x9e, 0x5a, 0x41, 0xf3, 0xe5, 0xb0, 0x62},
{0xfc, 0x9f, 0x1f, 0xec, 0x40, 0x54, 0x20, 0x7a, 0xe3, 0xe4, 0x1a, 0x0, 0xce, 0xf4, 0xc9, 0x84, 0x4f, 0xd7, 0x94, 0xf5, 0x9d, 0xfa, 0x95, 0xd8, 0x55, 0x2e, 0x7e, 0x11, 0x24, 0xc3, 0x54, 0xa5},
{0x5b, 0xdf, 0x72, 0x28, 0xbd, 0xfe, 0x6e, 0x28, 0x78, 0xf5, 0x7f, 0xe2, 0xf, 0xa5, 0xc4, 0xb2, 0x5, 0x89, 0x7c, 0xef, 0xee, 0x49, 0xd3, 0x2e, 0x44, 0x7e, 0x93, 0x85, 0xeb, 0x28, 0x59, 0x7f},
{0x70, 0x5f, 0x69, 0x37, 0xb3, 0x24, 0x31, 0x4a, 0x5e, 0x86, 0x28, 0xf1, 0x1d, 0xd6, 0xe4, 0x65, 0xc7, 0x1b, 0x77, 0x4, 0x51, 0xb9, 0x20, 0xe7, 0x74, 0xfe, 0x43, 0xe8, 0x23, 0xd4, 0x87, 0x8a},
{0x7d, 0x29, 0xe8, 0xa3, 0x92, 0x76, 0x94, 0xf2, 0xdd, 0xcb, 0x7a, 0x9, 0x9b, 0x30, 0xd9, 0xc1, 0x1d, 0x1b, 0x30, 0xfb, 0x5b, 0xdc, 0x1b, 0xe0, 0xda, 0x24, 0x49, 0x4f, 0xf2, 0x9c, 0x82, 0xbf},
{0xa4, 0xe7, 0xba, 0x31, 0xb4, 0x70, 0xbf, 0xff, 0xd, 0x32, 0x44, 0x5, 0xde, 0xf8, 0xbc, 0x48, 0x3b, 0xae, 0xfc, 0x32, 0x53, 0xbb, 0xd3, 0x39, 0x45, 0x9f, 0xc3, 0xc1, 0xe0, 0x29, 0x8b, 0xa0},
{0xe5, 0xc9, 0x5, 0xfd, 0xf7, 0xae, 0x9, 0xf, 0x94, 0x70, 0x34, 0x12, 0x42, 0x90, 0xf1, 0x34, 0xa2, 0x71, 0xb7, 0x1, 0xe3, 0x44, 0xed, 0x95, 0xe9, 0x3b, 0x8e, 0x36, 0x4f, 0x2f, 0x98, 0x4a},
{0x88, 0x40, 0x1d, 0x63, 0xa0, 0x6c, 0xf6, 0x15, 0x47, 0xc1, 0x44, 0x4b, 0x87, 0x52, 0xaf, 0xff, 0x7e, 0xbb, 0x4a, 0xf1, 0xe2, 0xa, 0xc6, 0x30, 0x46, 0x70, 0xb6, 0xc5, 0xcc, 0x6e, 0x8c, 0xe6},
{0xa4, 0xd5, 0xa4, 0x56, 0xbd, 0x4f, 0xca, 0x0, 0xda, 0x9d, 0x84, 0x4b, 0xc8, 0x3e, 0x18, 0xae, 0x73, 0x57, 0xce, 0x45, 0x30, 0x64, 0xd1, 0xad, 0xe8, 0xa6, 0xce, 0x68, 0x14, 0x5c, 0x25, 0x67},
{0xa3, 0xda, 0x8c, 0xf2, 0xcb, 0xe, 0xe1, 0x16, 0x33, 0xe9, 0x6, 0x58, 0x9a, 0x94, 0x99, 0x9a, 0x1f, 0x60, 0xb2, 0x20, 0xc2, 0x6f, 0x84, 0x7b, 0xd1, 0xce, 0xac, 0x7f, 0xa0, 0xd1, 0x85, 0x18},
{0x32, 0x59, 0x5b, 0xa1, 0x8d, 0xdd, 0x19, 0xd3, 0x50, 0x9a, 0x1c, 0xc0, 0xaa, 0xa5, 0xb4, 0x46, 0x9f, 0x3d, 0x63, 0x67, 0xe4, 0x4, 0x6b, 0xba, 0xf6, 0xca, 0x19, 0xab, 0xb, 0x56, 0xee, 0x7e},
{0x1f, 0xb1, 0x79, 0xea, 0xa9, 0x28, 0x21, 0x74, 0xe9, 0xbd, 0xf7, 0x35, 0x3b, 0x36, 0x51, 0xee, 0x1d, 0x57, 0xac, 0x5a, 0x75, 0x50, 0xd3, 0x76, 0x3a, 0x46, 0xc2, 0xfe, 0xa3, 0x7d, 0x70, 0x1},
{0xf7, 0x35, 0xc1, 0xaf, 0x98, 0xa4, 0xd8, 0x42, 0x78, 0xed, 0xec, 0x20, 0x9e, 0x6b, 0x67, 0x79, 0x41, 0x83, 0x63, 0x15, 0xea, 0x3a, 0xdb, 0xa8, 0xfa, 0xc3, 0x3b, 0x4d, 0x32, 0x83, 0x2c, 0x83},
{0xa7, 0x40, 0x3b, 0x1f, 0x1c, 0x27, 0x47, 0xf3, 0x59, 0x40, 0xf0, 0x34, 0xb7, 0x2d, 0x76, 0x9a, 0xe7, 0x3e, 0x4e, 0x6c, 0xd2, 0x21, 0x4f, 0xfd, 0xb8, 0xfd, 0x8d, 0x39, 0xdc, 0x57, 0x59, 0xef},
{0x8d, 0x9b, 0xc, 0x49, 0x2b, 0x49, 0xeb, 0xda, 0x5b, 0xa2, 0xd7, 0x49, 0x68, 0xf3, 0x70, 0xd, 0x7d, 0x3b, 0xae, 0xd0, 0x7a, 0x8d, 0x55, 0x84, 0xf5, 0xa5, 0xe9, 0xf0, 0xe4, 0xf8, 0x8e, 0x65},
{0xa0, 0xb8, 0xa2, 0xf4, 0x36, 0x10, 0x3b, 0x53, 0xc, 0xa8, 0x7, 0x9e, 0x75, 0x3e, 0xec, 0x5a, 0x91, 0x68, 0x94, 0x92, 0x56, 0xe8, 0x88, 0x4f, 0x5b, 0xb0, 0x5c, 0x55, 0xf8, 0xba, 0xbc, 0x4c},
{0xe3, 0xbb, 0x3b, 0x99, 0xf3, 0x87, 0x94, 0x7b, 0x75, 0xda, 0xf4, 0xd6, 0x72, 0x6b, 0x1c, 0x5d, 0x64, 0xae, 0xac, 0x28, 0xdc, 0x34, 0xb3, 0x6d, 0x6c, 0x34, 0xa5, 0x50, 0xb8, 0x28, 0xdb, 0x71},
{0xf8, 0x61, 0xe2, 0xf2, 0x10, 0x8d, 0x51, 0x2a, 0xe3, 0xdb, 0x64, 0x33, 0x59, 0xdd, 0x75, 0xfc, 0x1c, 0xac, 0xbc, 0xf1, 0x43, 0xce, 0x3f, 0xa2, 0x67, 0xbb, 0xd1, 0x3c, 0x2, 0xe8, 0x43, 0xb0},
{0x33, 0xa, 0x5b, 0xca, 0x88, 0x29, 0xa1, 0x75, 0x7f, 0x34, 0x19, 0x4d, 0xb4, 0x16, 0x53, 0x5c, 0x92, 0x3b, 0x94, 0xc3, 0xe, 0x79, 0x4d, 0x1e, 0x79, 0x74, 0x75, 0xd7, 0xb6, 0xee, 0xaf, 0x3f},
{0xea, 0xa8, 0xd4, 0xf7, 0xbe, 0x1a, 0x39, 0x21, 0x5c, 0xf4, 0x7e, 0x9, 0x4c, 0x23, 0x27, 0x51, 0x26, 0xa3, 0x24, 0x53, 0xba, 0x32, 0x3c, 0xd2, 0x44, 0xa3, 0x17, 0x4a, 0x6d, 0xa6, 0xd5, 0xad},
{0xb5, 0x1d, 0x3e, 0xa6, 0xaf, 0xf2, 0xc9, 0x8, 0x83, 0x59, 0x3d, 0x98, 0x91, 0x6b, 0x3c, 0x56, 0x4c, 0xf8, 0x7c, 0xa1, 0x72, 0x86, 0x60, 0x4d, 0x46, 0xe2, 0x3e, 0xcc, 0x8, 0x6e, 0xc7, 0xf6},
{0x2f, 0x98, 0x33, 0xb3, 0xb1, 0xbc, 0x76, 0x5e, 0x2b, 0xd6, 0x66, 0xa5, 0xef, 0xc4, 0xe6, 0x2a, 0x6, 0xf4, 0xb6, 0xe8, 0xbe, 0xc1, 0xd4, 0x36, 0x74, 0xee, 0x82, 0x15, 0xbc, 0xef, 0x21, 0x63},
{0xfd, 0xc1, 0x4e, 0xd, 0xf4, 0x53, 0xc9, 0x69, 0xa7, 0x7d, 0x5a, 0xc4, 0x6, 0x58, 0x58, 0x26, 0x7e, 0xc1, 0x14, 0x16, 0x6, 0xe0, 0xfa, 0x16, 0x7e, 0x90, 0xaf, 0x3d, 0x28, 0x63, 0x9d, 0x3f},
{0xd2, 0xc9, 0xf2, 0xe3, 0x0, 0x9b, 0xd2, 0xc, 0x5f, 0xaa, 0xce, 0x30, 0xb7, 0xd4, 0xc, 0x30, 0x74, 0x2a, 0x51, 0x16, 0xf2, 0xe0, 0x32, 0x98, 0xd, 0xeb, 0x30, 0xd8, 0xe3, 0xce, 0xf8, 0x9a},
{0x4b, 0xc5, 0x9e, 0x7b, 0xb5, 0xf1, 0x79, 0x92, 0xff, 0x51, 0xe6, 0x6e, 0x4, 0x86, 0x68, 0xd3, 0x9b, 0x23, 0x4d, 0x57, 0xe6, 0x96, 0x67, 0x31, 0xcc, 0xe6, 0xa6, 0xf3, 0x17, 0xa, 0x75, 0x5},
{0xb1, 0x76, 0x81, 0xd9, 0x13, 0x32, 0x6c, 0xce, 0x3c, 0x17, 0x52, 0x84, 0xf8, 0x5, 0xa2, 0x62, 0xf4, 0x2b, 0xcb, 0xb3, 0x78, 0x47, 0x15, 0x47, 0xff, 0x46, 0x54, 0x82, 0x23, 0x93, 0x6a, 0x48},
{0x38, 0xdf, 0x58, 0x7, 0x4e, 0x5e, 0x65, 0x65, 0xf2, 0xfc, 0x7c, 0x89, 0xfc, 0x86, 0x50, 0x8e, 0x31, 0x70, 0x2e, 0x44, 0xd0, 0xb, 0xca, 0x86, 0xf0, 0x40, 0x9, 0xa2, 0x30, 0x78, 0x47, 0x4e},
{0x65, 0xa0, 0xee, 0x39, 0xd1, 0xf7, 0x38, 0x83, 0xf7, 0x5e, 0xe9, 0x37, 0xe4, 0x2c, 0x3a, 0xbd, 0x21, 0x97, 0xb2, 0x26, 0x1, 0x13, 0xf8, 0x6f, 0xa3, 0x44, 0xed, 0xd1, 0xef, 0x9f, 0xde, 0xe7},
{0x8b, 0xa0, 0xdf, 0x15, 0x76, 0x25, 0x92, 0xd9, 0x3c, 0x85, 0xf7, 0xf6, 0x12, 0xdc, 0x42, 0xbe, 0xd8, 0xa7, 0xec, 0x7c, 0xab, 0x27, 0xb0, 0x7e, 0x53, 0x8d, 0x7d, 0xda, 0xaa, 0x3e, 0xa8, 0xde},
{0xaa, 0x25, 0xce, 0x93, 0xbd, 0x2, 0x69, 0xd8, 0x5a, 0xf6, 0x43, 0xfd, 0x1a, 0x73, 0x8, 0xf9, 0xc0, 0x5f, 0xef, 0xda, 0x17, 0x4a, 0x19, 0xa5, 0x97, 0x4d, 0x66, 0x33, 0x4c, 0xfd, 0x21, 0x6a},
{0x35, 0xb4, 0x98, 0x31, 0xdb, 0x41, 0x15, 0x70, 0xea, 0x1e, 0xf, 0xbb, 0xed, 0xcd, 0x54, 0x9b, 0x9a, 0xd0, 0x63, 0xa1, 0x51, 0x97, 0x40, 0x72, 0xf6, 0x75, 0x9d, 0xbf, 0x91, 0x47, 0x6f, 0xe2}
};
#define JH_SWAP1(x) (x) = ((((x) & 0x5555555555555555ULL) << 1) | (((x) & 0xaaaaaaaaaaaaaaaaULL) >> 1));
#define JH_SWAP2(x) (x) = ((((x) & 0x3333333333333333ULL) << 2) | (((x) & 0xccccccccccccccccULL) >> 2));
#define JH_SWAP4(x) (x) = ((((x) & 0x0f0f0f0f0f0f0f0fULL) << 4) | (((x) & 0xf0f0f0f0f0f0f0f0ULL) >> 4));
#define JH_SWAP8(x) (x) = ((((x) & 0x00ff00ff00ff00ffULL) << 8) | (((x) & 0xff00ff00ff00ff00ULL) >> 8));
#define JH_SWAP16(x) (x) = ((((x) & 0x0000ffff0000ffffULL) << 16) | (((x) & 0xffff0000ffff0000ULL) >> 16));
#define JH_SWAP32(x) (x) = (((x) << 32) | ((x) >> 32));
#define JH_L(m0,m1,m2,m3,m4,m5,m6,m7) \
(m4) ^= (m1); \
(m5) ^= (m2); \
(m6) ^= (m0) ^ (m3); \
(m7) ^= (m0); \
(m0) ^= (m5); \
(m1) ^= (m6); \
(m2) ^= (m4) ^ (m7); \
(m3) ^= (m4);
#define JH_SS(m0,m1,m2,m3,m4,m5,m6,m7,cc0,cc1) \
m3 = ~(m3); \
m7 = ~(m7); \
m0 ^= ((~(m2)) & (cc0)); \
m4 ^= ((~(m6)) & (cc1)); \
temp0 = (cc0) ^ ((m0) & (m1));\
temp1 = (cc1) ^ ((m4) & (m5));\
m0 ^= ((m2) & (m3)); \
m4 ^= ((m6) & (m7)); \
m3 ^= ((~(m1)) & (m2)); \
m7 ^= ((~(m5)) & (m6)); \
m1 ^= ((m0) & (m2)); \
m5 ^= ((m4) & (m6)); \
m2 ^= ((m0) & (~(m3))); \
m6 ^= ((m4) & (~(m7))); \
m0 ^= ((m1) | (m3)); \
m4 ^= ((m5) | (m7)); \
m3 ^= ((m1) & (m2)); \
m7 ^= ((m5) & (m6)); \
m1 ^= (temp0 & (m0)); \
m5 ^= (temp1 & (m4)); \
m2 ^= temp0; \
m6 ^= temp1;
__device__
void cn_jh_E8(jhHashState *state)
{
uint64_t i,roundnumber,temp0,temp1;
for (roundnumber = 0; roundnumber < 42; roundnumber = roundnumber+7)
{
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+0])[i],((uint64_t *)d_E8_rc[roundnumber+0])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP1(state->x[1][i]); JH_SWAP1(state->x[3][i]); JH_SWAP1(state->x[5][i]); JH_SWAP1(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+1])[i],((uint64_t *)d_E8_rc[roundnumber+1])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP2(state->x[1][i]); JH_SWAP2(state->x[3][i]); JH_SWAP2(state->x[5][i]); JH_SWAP2(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+2])[i],((uint64_t *)d_E8_rc[roundnumber+2])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP4(state->x[1][i]); JH_SWAP4(state->x[3][i]); JH_SWAP4(state->x[5][i]); JH_SWAP4(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+3])[i],((uint64_t *)d_E8_rc[roundnumber+3])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP8(state->x[1][i]); JH_SWAP8(state->x[3][i]); JH_SWAP8(state->x[5][i]); JH_SWAP8(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+4])[i],((uint64_t *)d_E8_rc[roundnumber+4])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP16(state->x[1][i]); JH_SWAP16(state->x[3][i]); JH_SWAP16(state->x[5][i]); JH_SWAP16(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+5])[i],((uint64_t *)d_E8_rc[roundnumber+5])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
JH_SWAP32(state->x[1][i]); JH_SWAP32(state->x[3][i]); JH_SWAP32(state->x[5][i]); JH_SWAP32(state->x[7][i]);
}
for (i = 0; i < 2; i++) {
JH_SS(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i],
((uint64_t *)d_E8_rc[roundnumber+6])[i],((uint64_t *)d_E8_rc[roundnumber+6])[i+2] );
JH_L(state->x[0][i],state->x[2][i],state->x[4][i],state->x[6][i],state->x[1][i],state->x[3][i],state->x[5][i],state->x[7][i]);
}
for (i = 1; i < 8; i = i+2) {
temp0 = state->x[i][0]; state->x[i][0] = state->x[i][1]; state->x[i][1] = temp0;
}
}
}
__device__
void cn_jh_F8(jhHashState *state)
{
uint64_t i;
for (i = 0; i < 8; i++) {
state->x[i >> 1][i & 1] ^= ((uint64_t *)state->buffer)[i];
}
cn_jh_E8(state);
for (i = 0; i < 8; i++) {
state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64_t *)state->buffer)[i];
}
}
__device__
void cn_jh_update(jhHashState * __restrict__ state, const uint8_t * __restrict__ data, DataLength databitlen)
{
DataLength index;
state->databitlen += databitlen;
index = 0;
if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) < 512) )
{
if ( (databitlen & 7) == 0 ) {
memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3));
}
else memcpy(state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3)+1);
state->datasize_in_buffer += databitlen;
databitlen = 0;
}
if ( (state->datasize_in_buffer > 0 ) && (( state->datasize_in_buffer + databitlen) >= 512) )
{
memcpy( state->buffer + (state->datasize_in_buffer >> 3), data, 64-(state->datasize_in_buffer >> 3) );
index = 64-(state->datasize_in_buffer >> 3);
databitlen = databitlen - (512 - state->datasize_in_buffer);
cn_jh_F8(state);
state->datasize_in_buffer = 0;
}
for ( ; databitlen >= 512; index = index+64, databitlen = databitlen - 512) {
memcpy(state->buffer, data+index, 64);
cn_jh_F8(state);
}
if ( databitlen > 0) {
if ((databitlen & 7) == 0)
memcpy(state->buffer, data+index, (databitlen & 0x1ff) >> 3);
else
memcpy(state->buffer, data+index, ((databitlen & 0x1ff) >> 3)+1);
state->datasize_in_buffer = databitlen;
}
}
/* pad the message, process the padded block(s), truncate the hash value H to obtain the message digest */
__device__
void cn_jh_final(jhHashState * __restrict__ state, uint8_t * __restrict__ hashval)
{
unsigned int i;
//uint32_t *bufptr = (uint32_t *)state->buffer;
if ( (state->databitlen & 0x1ff) == 0 ) {
/* pad the message when databitlen is multiple of 512 bits, then process the padded block */
memset(state->buffer, 0, 64);
//for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000;
state->buffer[0] = 0x80;
state->buffer[63] = state->databitlen & 0xff;
state->buffer[62] = (state->databitlen >> 8) & 0xff;
state->buffer[61] = (state->databitlen >> 16) & 0xff;
state->buffer[60] = (state->databitlen >> 24) & 0xff;
state->buffer[59] = (state->databitlen >> 32) & 0xff;
state->buffer[58] = (state->databitlen >> 40) & 0xff;
state->buffer[57] = (state->databitlen >> 48) & 0xff;
state->buffer[56] = (state->databitlen >> 56) & 0xff;
cn_jh_F8(state);
} else {
/* set the rest of the bytes in the buffer to 0 */
if ( (state->datasize_in_buffer & 7) == 0) {
for (i = (state->databitlen & 0x1ff) >> 3; i < 64; i++) state->buffer[i] = 0;
} else {
for (i = ((state->databitlen & 0x1ff) >> 3)+1; i < 64; i++) state->buffer[i] = 0;
}
/*pad and process the partial block when databitlen is not multiple of 512 bits, then hash the padded blocks*/
state->buffer[((state->databitlen & 0x1ff) >> 3)] |= 1 << (7- (state->databitlen & 7));
cn_jh_F8(state);
memset(state->buffer, 0, 64);
//for( i = 0; i < 16; i++ ) *(bufptr+i) = 0x00000000;
state->buffer[63] = state->databitlen & 0xff;
state->buffer[62] = (state->databitlen >> 8) & 0xff;
state->buffer[61] = (state->databitlen >> 16) & 0xff;
state->buffer[60] = (state->databitlen >> 24) & 0xff;
state->buffer[59] = (state->databitlen >> 32) & 0xff;
state->buffer[58] = (state->databitlen >> 40) & 0xff;
state->buffer[57] = (state->databitlen >> 48) & 0xff;
state->buffer[56] = (state->databitlen >> 56) & 0xff;
cn_jh_F8(state);
}
memcpy(hashval, ((unsigned char*)state->x) + 64 + 32, 32);
//MEMCPY4(hashval, ((unsigned char*)state->x) + 64 + 32, 8);
}
__device__
void cn_jh_init(jhHashState *state, int hashbitlen)
{
state->databitlen = 0;
state->datasize_in_buffer = 0;
state->hashbitlen = hashbitlen;
memcpy(state->x, d_JH256_H0, 128);
//MEMCPY8(state->x, d_JH256_H0, 128 / 8);
}
__device__
void cn_jh(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
{
const int hashbitlen = 256;
DataLength databitlen = len << 3;
jhHashState state;
cn_jh_init(&state, hashbitlen);
cn_jh_update(&state, data, databitlen);
cn_jh_final(&state, (uint8_t*) hashval);
}
+211
View File
@@ -0,0 +1,211 @@
__constant__ uint64_t keccakf_rndc[24] = {
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
};
#if __CUDA_ARCH__ >= 350
__forceinline__ __device__ uint64_t cuda_rotl64(const uint64_t value, const int offset)
{
uint2 result;
if(offset >= 32)
{
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
}
else
{
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
}
return __double_as_longlong(__hiloint2double(result.y, result.x));
}
#define rotl64_1(x, y) (cuda_rotl64((x), (y)))
#else
#define rotl64_1(x, y) ((x) << (y) | ((x) >> (64 - (y))))
#endif
#define rotl64_2(x, y) rotl64_1(((x) >> 32) | ((x) << 32), (y))
#define bitselect(a, b, c) ((a) ^ ((c) & ((b) ^ (a))))
__device__ __forceinline__
void cn_keccakf2(uint64_t *s)
{
uint8_t i;
for(i = 0; i < 24; ++i)
{
uint64_t bc[5], tmpxor[5], tmp1, tmp2;
tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
tmp1 = s[1] ^ bc[0];
s[0] ^= bc[4];
s[1] = rotl64_2(s[6] ^ bc[0], 12);
s[6] = rotl64_1(s[9] ^ bc[3], 20);
s[9] = rotl64_2(s[22] ^ bc[1], 29);
s[22] = rotl64_2(s[14] ^ bc[3], 7);
s[14] = rotl64_1(s[20] ^ bc[4], 18);
s[20] = rotl64_2(s[2] ^ bc[1], 30);
s[2] = rotl64_2(s[12] ^ bc[1], 11);
s[12] = rotl64_1(s[13] ^ bc[2], 25);
s[13] = rotl64_1(s[19] ^ bc[3], 8);
s[19] = rotl64_2(s[23] ^ bc[2], 24);
s[23] = rotl64_2(s[15] ^ bc[4], 9);
s[15] = rotl64_1(s[4] ^ bc[3], 27);
s[4] = rotl64_1(s[24] ^ bc[3], 14);
s[24] = rotl64_1(s[21] ^ bc[0], 2);
s[21] = rotl64_2(s[8] ^ bc[2], 23);
s[8] = rotl64_2(s[16] ^ bc[0], 13);
s[16] = rotl64_2(s[5] ^ bc[4], 4);
s[5] = rotl64_1(s[3] ^ bc[2], 28);
s[3] = rotl64_1(s[18] ^ bc[2], 21);
s[18] = rotl64_1(s[17] ^ bc[1], 15);
s[17] = rotl64_1(s[11] ^ bc[0], 10);
s[11] = rotl64_1(s[7] ^ bc[1], 6);
s[7] = rotl64_1(s[10] ^ bc[4], 3);
s[10] = rotl64_1(tmp1, 1);
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
s[0] ^= keccakf_rndc[i];
}
}
__device__ __forceinline__
void cn_keccakf(uint64_t *s)
{
uint64_t bc[5], tmpxor[5], tmp1, tmp2;
tmpxor[0] = s[0] ^ s[5];
tmpxor[1] = s[1] ^ s[6] ^ 0x8000000000000000ULL;
tmpxor[2] = s[2] ^ s[7];
tmpxor[3] = s[3] ^ s[8];
tmpxor[4] = s[4] ^ s[9];
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
tmp1 = s[1] ^ bc[0];
s[0] ^= bc[4];
s[1] = rotl64_2(s[6] ^ bc[0], 12);
s[6] = rotl64_1(s[9] ^ bc[3], 20);
s[9] = rotl64_2(bc[1], 29);
s[22] = rotl64_2(bc[3], 7);
s[14] = rotl64_1(bc[4], 18);
s[20] = rotl64_2(s[2] ^ bc[1], 30);
s[2] = rotl64_2(bc[1], 11);
s[12] = rotl64_1(bc[2], 25);
s[13] = rotl64_1(bc[3], 8);
s[19] = rotl64_2(bc[2], 24);
s[23] = rotl64_2(bc[4], 9);
s[15] = rotl64_1(s[4] ^ bc[3], 27);
s[4] = rotl64_1(bc[3], 14);
s[24] = rotl64_1(bc[0], 2);
s[21] = rotl64_2(s[8] ^ bc[2], 23);
s[8] = rotl64_2(0x8000000000000000ULL ^ bc[0], 13);
s[16] = rotl64_2(s[5] ^ bc[4], 4);
s[5] = rotl64_1(s[3] ^ bc[2], 28);
s[3] = rotl64_1(bc[2], 21);
s[18] = rotl64_1(bc[1], 15);
s[17] = rotl64_1(bc[0], 10);
s[11] = rotl64_1(s[7] ^ bc[1], 6);
s[7] = rotl64_1(bc[4], 3);
s[10] = rotl64_1(tmp1, 1);
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
s[0] ^= 0x0000000000000001;
for(int i = 1; i < 24; ++i)
{
tmpxor[0] = s[0] ^ s[5] ^ s[10] ^ s[15] ^ s[20];
tmpxor[1] = s[1] ^ s[6] ^ s[11] ^ s[16] ^ s[21];
tmpxor[2] = s[2] ^ s[7] ^ s[12] ^ s[17] ^ s[22];
tmpxor[3] = s[3] ^ s[8] ^ s[13] ^ s[18] ^ s[23];
tmpxor[4] = s[4] ^ s[9] ^ s[14] ^ s[19] ^ s[24];
bc[0] = tmpxor[0] ^ rotl64_1(tmpxor[2], 1);
bc[1] = tmpxor[1] ^ rotl64_1(tmpxor[3], 1);
bc[2] = tmpxor[2] ^ rotl64_1(tmpxor[4], 1);
bc[3] = tmpxor[3] ^ rotl64_1(tmpxor[0], 1);
bc[4] = tmpxor[4] ^ rotl64_1(tmpxor[1], 1);
tmp1 = s[1] ^ bc[0];
s[0] ^= bc[4];
s[1] = rotl64_2(s[6] ^ bc[0], 12);
s[6] = rotl64_1(s[9] ^ bc[3], 20);
s[9] = rotl64_2(s[22] ^ bc[1], 29);
s[22] = rotl64_2(s[14] ^ bc[3], 7);
s[14] = rotl64_1(s[20] ^ bc[4], 18);
s[20] = rotl64_2(s[2] ^ bc[1], 30);
s[2] = rotl64_2(s[12] ^ bc[1], 11);
s[12] = rotl64_1(s[13] ^ bc[2], 25);
s[13] = rotl64_1(s[19] ^ bc[3], 8);
s[19] = rotl64_2(s[23] ^ bc[2], 24);
s[23] = rotl64_2(s[15] ^ bc[4], 9);
s[15] = rotl64_1(s[4] ^ bc[3], 27);
s[4] = rotl64_1(s[24] ^ bc[3], 14);
s[24] = rotl64_1(s[21] ^ bc[0], 2);
s[21] = rotl64_2(s[8] ^ bc[2], 23);
s[8] = rotl64_2(s[16] ^ bc[0], 13);
s[16] = rotl64_2(s[5] ^ bc[4], 4);
s[5] = rotl64_1(s[3] ^ bc[2], 28);
s[3] = rotl64_1(s[18] ^ bc[2], 21);
s[18] = rotl64_1(s[17] ^ bc[1], 15);
s[17] = rotl64_1(s[11] ^ bc[0], 10);
s[11] = rotl64_1(s[7] ^ bc[1], 6);
s[7] = rotl64_1(s[10] ^ bc[4], 3);
s[10] = rotl64_1(tmp1, 1);
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
s[0] ^= keccakf_rndc[i];
}
}
__device__ __forceinline__
void cn_keccak(const uint32_t * __restrict__ in, uint64_t * __restrict__ md)
{
uint64_t st[25];
MEMCPY4(st, in, 19);
MEMSET8(&st[10], 0x00, 15);
st[9] = (st[9] & 0x00000000FFFFFFFFULL) | 0x0000000100000000ULL;
st[16] = 0x8000000000000000ULL;
cn_keccakf(st);
MEMCPY8(md, st, 25);
return;
}
+319
View File
@@ -0,0 +1,319 @@
typedef unsigned int uint_t; /* native unsigned integer */
#define SKEIN_MODIFIER_WORDS ( 2) /* number of modifier (tweak) words */
#define SKEIN_256_STATE_WORDS ( 4)
#define SKEIN_512_STATE_WORDS ( 8)
#define SKEIN_256_STATE_BYTES ( 8*SKEIN_256_STATE_WORDS)
#define SKEIN_512_STATE_BYTES ( 8*SKEIN_512_STATE_WORDS)
#define SKEIN_256_STATE_BITS (64*SKEIN_256_STATE_WORDS)
#define SKEIN_512_STATE_BITS (64*SKEIN_512_STATE_WORDS)
#define SKEIN_256_BLOCK_BYTES ( 8*SKEIN_256_STATE_WORDS)
#define SKEIN_512_BLOCK_BYTES ( 8*SKEIN_512_STATE_WORDS)
#define SKEIN_MK_64(hi32,lo32) ((lo32) + (((uint64_t) (hi32)) << 32))
#define SKEIN_KS_PARITY SKEIN_MK_64(0x1BD11BDA,0xA9FC1A22)
#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* offset 64 because it's the second word */
#define SKEIN_T1_POS_FIRST SKEIN_T1_BIT(126) /* bits 126 : first block flag */
#define SKEIN_T1_POS_BIT_PAD SKEIN_T1_BIT(119) /* bit 119 : partial final input byte */
#define SKEIN_T1_POS_FINAL SKEIN_T1_BIT(127) /* bit 127 : final block flag */
#define SKEIN_T1_POS_BLK_TYPE SKEIN_T1_BIT(120) /* bits 120..125: type field */
#define SKEIN_T1_FLAG_FIRST (((uint64_t) 1 ) << SKEIN_T1_POS_FIRST)
#define SKEIN_T1_FLAG_BIT_PAD (((uint64_t) 1 ) << SKEIN_T1_POS_BIT_PAD)
#define SKEIN_T1_FLAG_FINAL (((uint64_t) 1 ) << SKEIN_T1_POS_FINAL)
#define SKEIN_BLK_TYPE_MSG (48) /* message processing */
#define SKEIN_BLK_TYPE_OUT (63) /* output stage */
#define SKEIN_T1_BLK_TYPE(T) (((uint64_t) (SKEIN_BLK_TYPE_##T)) << SKEIN_T1_POS_BLK_TYPE)
#define SKEIN_T1_BLK_TYPE_MSG SKEIN_T1_BLK_TYPE(MSG) /* message processing */
#define SKEIN_T1_BLK_TYPE_OUT SKEIN_T1_BLK_TYPE(OUT) /* output stage */
#define SKEIN_T1_BLK_TYPE_OUT_FINAL (SKEIN_T1_BLK_TYPE_OUT | SKEIN_T1_FLAG_FINAL)
#define Skein_Set_Tweak(ctxPtr,TWK_NUM,tVal) {(ctxPtr)->h.T[TWK_NUM] = (tVal);}
#define Skein_Set_T0(ctxPtr,T0) Skein_Set_Tweak(ctxPtr,0,T0)
#define Skein_Set_T1(ctxPtr,T1) Skein_Set_Tweak(ctxPtr,1,T1)
#define Skein_Set_T0_T1(ctxPtr,T0,T1) { \
Skein_Set_T0(ctxPtr,(T0)); \
Skein_Set_T1(ctxPtr,(T1)); }
#define Skein_Start_New_Type(ctxPtr,BLK_TYPE) \
{ Skein_Set_T0_T1(ctxPtr,0,SKEIN_T1_FLAG_FIRST | SKEIN_T1_BLK_TYPE_##BLK_TYPE); (ctxPtr)->h.bCnt=0; }
#define Skein_Set_Bit_Pad_Flag(hdr) { (hdr).T[1] |= SKEIN_T1_FLAG_BIT_PAD; }
#define KW_TWK_BASE (0)
#define KW_KEY_BASE (3)
#define ks (kw + KW_KEY_BASE)
#define ts (kw + KW_TWK_BASE)
#define R512(p0,p1,p2,p3,p4,p5,p6,p7,R512ROT,rNum) \
X##p0 += X##p1; X##p1 = ROTL64(X##p1,R512ROT##_0); X##p1 ^= X##p0; \
X##p2 += X##p3; X##p3 = ROTL64(X##p3,R512ROT##_1); X##p3 ^= X##p2; \
X##p4 += X##p5; X##p5 = ROTL64(X##p5,R512ROT##_2); X##p5 ^= X##p4; \
X##p6 += X##p7; X##p7 = ROTL64(X##p7,R512ROT##_3); X##p7 ^= X##p6;
#define I512(R) \
X0 += ks[((R)+1) % 9]; \
X1 += ks[((R)+2) % 9]; \
X2 += ks[((R)+3) % 9]; \
X3 += ks[((R)+4) % 9]; \
X4 += ks[((R)+5) % 9]; \
X5 += ks[((R)+6) % 9] + ts[((R)+1) % 3]; \
X6 += ks[((R)+7) % 9] + ts[((R)+2) % 3]; \
X7 += ks[((R)+8) % 9] + (R)+1;
#define R512_8_rounds(R) \
R512(0,1,2,3,4,5,6,7,R_512_0,8*(R)+ 1); \
R512(2,1,4,7,6,5,0,3,R_512_1,8*(R)+ 2); \
R512(4,1,6,3,0,5,2,7,R_512_2,8*(R)+ 3); \
R512(6,1,0,7,2,5,4,3,R_512_3,8*(R)+ 4); \
I512(2*(R)); \
R512(0,1,2,3,4,5,6,7,R_512_4,8*(R)+ 5); \
R512(2,1,4,7,6,5,0,3,R_512_5,8*(R)+ 6); \
R512(4,1,6,3,0,5,2,7,R_512_6,8*(R)+ 7); \
R512(6,1,0,7,2,5,4,3,R_512_7,8*(R)+ 8); \
I512(2*(R)+1);
typedef struct
{
size_t hashBitLen;
size_t bCnt;
uint64_t T[SKEIN_MODIFIER_WORDS];
} Skein_Ctxt_Hdr_t;
typedef struct {
Skein_Ctxt_Hdr_t h;
uint64_t X[SKEIN_256_STATE_WORDS];
uint8_t b[SKEIN_256_BLOCK_BYTES];
} Skein_256_Ctxt_t;
typedef struct {
Skein_Ctxt_Hdr_t h;
uint64_t X[SKEIN_512_STATE_WORDS];
uint8_t b[SKEIN_512_BLOCK_BYTES];
} Skein_512_Ctxt_t;
typedef struct {
uint_t statebits;
union {
Skein_Ctxt_Hdr_t h;
Skein_256_Ctxt_t ctx_256;
Skein_512_Ctxt_t ctx_512;
} u;
} skeinHashState;
__device__
void cn_skein_init(skeinHashState *state, size_t hashBitLen)
{
const uint64_t SKEIN_512_IV_256[] =
{
SKEIN_MK_64(0xCCD044A1,0x2FDB3E13),
SKEIN_MK_64(0xE8359030,0x1A79A9EB),
SKEIN_MK_64(0x55AEA061,0x4F816E6F),
SKEIN_MK_64(0x2A2767A4,0xAE9B94DB),
SKEIN_MK_64(0xEC06025E,0x74DD7683),
SKEIN_MK_64(0xE7A436CD,0xC4746251),
SKEIN_MK_64(0xC36FBAF9,0x393AD185),
SKEIN_MK_64(0x3EEDBA18,0x33EDFC13)
};
Skein_512_Ctxt_t *ctx = &state->u.ctx_512;
ctx->h.hashBitLen = hashBitLen;
memcpy(ctx->X, SKEIN_512_IV_256, sizeof(ctx->X));
Skein_Start_New_Type(ctx, MSG);
}
__device__
void cn_skein_processblock(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ blkPtr, size_t blkCnt, size_t byteCntAdd)
{
enum {
R_512_0_0=46, R_512_0_1=36, R_512_0_2=19, R_512_0_3=37,
R_512_1_0=33, R_512_1_1=27, R_512_1_2=14, R_512_1_3=42,
R_512_2_0=17, R_512_2_1=49, R_512_2_2=36, R_512_2_3=39,
R_512_3_0=44, R_512_3_1= 9, R_512_3_2=54, R_512_3_3=56,
R_512_4_0=39, R_512_4_1=30, R_512_4_2=34, R_512_4_3=24,
R_512_5_0=13, R_512_5_1=50, R_512_5_2=10, R_512_5_3=17,
R_512_6_0=25, R_512_6_1=29, R_512_6_2=39, R_512_6_3=43,
R_512_7_0= 8, R_512_7_1=35, R_512_7_2=56, R_512_7_3=22
};
uint64_t X0,X1,X2,X3,X4,X5,X6,X7;
uint64_t w[SKEIN_512_STATE_WORDS];
uint64_t kw[SKEIN_512_STATE_WORDS+4];
ts[0] = ctx->h.T[0];
ts[1] = ctx->h.T[1];
do {
ts[0] += byteCntAdd;
ks[0] = ctx->X[0];
ks[1] = ctx->X[1];
ks[2] = ctx->X[2];
ks[3] = ctx->X[3];
ks[4] = ctx->X[4];
ks[5] = ctx->X[5];
ks[6] = ctx->X[6];
ks[7] = ctx->X[7];
ks[8] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^
ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^ SKEIN_KS_PARITY;
ts[2] = ts[0] ^ ts[1];
memcpy(w, blkPtr, SKEIN_512_STATE_WORDS << 3);
X0 = w[0] + ks[0];
X1 = w[1] + ks[1];
X2 = w[2] + ks[2];
X3 = w[3] + ks[3];
X4 = w[4] + ks[4];
X5 = w[5] + ks[5] + ts[0];
X6 = w[6] + ks[6] + ts[1];
X7 = w[7] + ks[7];
blkPtr += SKEIN_512_BLOCK_BYTES;
R512_8_rounds( 0);
R512_8_rounds( 1);
R512_8_rounds( 2);
R512_8_rounds( 3);
R512_8_rounds( 4);
R512_8_rounds( 5);
R512_8_rounds( 6);
R512_8_rounds( 7);
R512_8_rounds( 8);
ctx->X[0] = X0 ^ w[0];
ctx->X[1] = X1 ^ w[1];
ctx->X[2] = X2 ^ w[2];
ctx->X[3] = X3 ^ w[3];
ctx->X[4] = X4 ^ w[4];
ctx->X[5] = X5 ^ w[5];
ctx->X[6] = X6 ^ w[6];
ctx->X[7] = X7 ^ w[7];
ts[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt);
ctx->h.T[0] = ts[0];
ctx->h.T[1] = ts[1];
}
__device__
void cn_skein_block(Skein_512_Ctxt_t * __restrict__ ctx, const uint8_t * __restrict__ msg, size_t msgByteCnt)
{
size_t n;
if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES)
{
if (ctx->h.bCnt) {
n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt;
if (n) {
memcpy(&ctx->b[ctx->h.bCnt],msg,n);
msgByteCnt -= n;
msg += n;
ctx->h.bCnt += n;
}
cn_skein_processblock(ctx, ctx->b, 1, SKEIN_512_BLOCK_BYTES);
ctx->h.bCnt = 0;
}
if (msgByteCnt > SKEIN_512_BLOCK_BYTES) {
n = (msgByteCnt - 1) / SKEIN_512_BLOCK_BYTES;
cn_skein_processblock(ctx, msg, n, SKEIN_512_BLOCK_BYTES);
msgByteCnt -= n * SKEIN_512_BLOCK_BYTES;
msg += n * SKEIN_512_BLOCK_BYTES;
}
}
if (msgByteCnt) {
memcpy(&ctx->b[ctx->h.bCnt],msg,msgByteCnt);
ctx->h.bCnt += msgByteCnt;
}
}
__device__
void cn_skein_update(skeinHashState * __restrict__ state, const uint8_t * __restrict__ data, DataLength databitlen)
{
if ((databitlen & 7) == 0) {
cn_skein_block(&state->u.ctx_512, data, databitlen >> 3);
}
else {
size_t bCnt = (databitlen >> 3) + 1;
uint8_t b,mask;
mask = (uint8_t) (1u << (7 - (databitlen & 7)));
b = (uint8_t) ((data[bCnt-1] & (0-mask)) | mask);
cn_skein_block(&state->u.ctx_512, data, bCnt - 1);
cn_skein_block(&state->u.ctx_512, &b, 1);
Skein_Set_Bit_Pad_Flag(state->u.h);
}
}
__device__
void cn_skein_final(skeinHashState * __restrict__ state, uint8_t * __restrict__ hashVal)
{
uint64_t X[SKEIN_512_STATE_WORDS];
Skein_512_Ctxt_t *ctx = (Skein_512_Ctxt_t *)&state->u.ctx_512;
const int byteCnt = (ctx->h.hashBitLen + 7) >> 3;
ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL;
if (ctx->h.bCnt < SKEIN_512_BLOCK_BYTES)
{
memset(&ctx->b[ctx->h.bCnt], 0, SKEIN_512_BLOCK_BYTES - ctx->h.bCnt);
}
cn_skein_processblock(ctx, ctx->b, 1, ctx->h.bCnt);
memset(ctx->b, 0, sizeof(ctx->b));
memcpy(X, ctx->X, sizeof(X));
for (int i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++)
{
int n = byteCnt - i*SKEIN_512_BLOCK_BYTES;
if (n > SKEIN_512_BLOCK_BYTES) n = SKEIN_512_BLOCK_BYTES;
((uint64_t *)ctx->b)[0] = (uint64_t)i;
Skein_Start_New_Type(ctx, OUT_FINAL);
cn_skein_processblock(ctx, ctx->b, 1, sizeof(uint64_t));
memcpy(hashVal + (i*SKEIN_512_BLOCK_BYTES), ctx->X, n);
memcpy(ctx->X, X, sizeof(X)); // restore the counter mode key for next time
}
}
__device__
void cn_skein(const uint8_t * __restrict__ data, DataLength len, uint32_t * hashval)
{
int hashbitlen = 256;
DataLength databitlen = len << 3;
skeinHashState state;
state.statebits = 64*SKEIN_512_STATE_WORDS;
cn_skein_init(&state, hashbitlen);
cn_skein_update(&state, data, databitlen);
cn_skein_final(&state, (uint8_t*) hashval);
}
+122
View File
@@ -0,0 +1,122 @@
// keccak.c
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
// A baseline Keccak (3rd round) implementation.
#include "c_keccak.h"
const uint64_t keccakf_rndc[24] =
{
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
};
const int keccakf_rotc[24] =
{
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
};
const int keccakf_piln[24] =
{
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
};
// update the state with given number of rounds
void keccakf(uint64_t st[25], int rounds)
{
int i, j, round;
uint64_t t, bc[5];
for (round = 0; round < rounds; ++round) {
// Theta
bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
for (i = 0; i < 5; ++i) {
t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1);
st[i ] ^= t;
st[i + 5] ^= t;
st[i + 10] ^= t;
st[i + 15] ^= t;
st[i + 20] ^= t;
}
// Rho Pi
t = st[1];
for (i = 0; i < 24; ++i) {
bc[0] = st[keccakf_piln[i]];
st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]);
t = bc[0];
}
// Chi
for (j = 0; j < 25; j += 5) {
bc[0] = st[j ];
bc[1] = st[j + 1];
bc[2] = st[j + 2];
bc[3] = st[j + 3];
bc[4] = st[j + 4];
st[j ] ^= (~bc[1]) & bc[2];
st[j + 1] ^= (~bc[2]) & bc[3];
st[j + 2] ^= (~bc[3]) & bc[4];
st[j + 3] ^= (~bc[4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];
}
// Iota
st[0] ^= keccakf_rndc[round];
}
}
// compute a keccak hash (md) of given byte length from "in"
typedef uint64_t state_t[25];
int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
{
state_t st;
uint8_t temp[144];
int i, rsiz, rsizw;
rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
rsizw = rsiz / 8;
memset(st, 0, sizeof(st));
for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) {
for (i = 0; i < rsizw; i++)
st[i] ^= ((uint64_t *) in)[i];
keccakf(st, KECCAK_ROUNDS);
}
// last block and padding
memcpy(temp, in, inlen);
temp[inlen++] = 1;
memset(temp + inlen, 0, rsiz - inlen);
temp[rsiz - 1] |= 0x80;
for (i = 0; i < rsizw; i++)
st[i] ^= ((uint64_t *) temp)[i];
keccakf(st, KECCAK_ROUNDS);
memcpy(md, st, mdlen);
return 0;
}
void keccak1600(const uint8_t *in, int inlen, uint8_t *md)
{
keccak(in, inlen, md, sizeof(state_t));
}
+34
View File
@@ -0,0 +1,34 @@
// keccak.h
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
#ifndef KECCAK_H
#define KECCAK_H
#include <stdint.h>
#include <string.h>
#ifndef KECCAK_ROUNDS
#define KECCAK_ROUNDS 24
#endif
#ifndef ROTL64
#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
#endif
#ifndef HASH_SIZE
#define HASH_SIZE 32
#endif
#ifndef HASH_DATA_AREA
#define HASH_DATA_AREA 136
#endif
// compute a keccak hash (md) of given byte length from "in"
int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen);
// update the state
void keccakf(uint64_t st[25], int norounds);
void keccak1600(const uint8_t *in, int inlen, uint8_t *md);
#endif
+351
View File
@@ -0,0 +1,351 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "cryptolight.h"
#define LONG_SHL_IDX 18
#define LONG_LOOPS32 0x40000
#include "cn_aes.cuh"
#define MUL_SUM_XOR_DST(a,c,dst) { \
uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], ((uint64_t *)dst)[0], &hi) + ((uint64_t *)c)[1]; \
hi += ((uint64_t *)c)[0]; \
((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi; \
((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo; \
((uint64_t *)dst)[0] = hi; \
((uint64_t *)dst)[1] = lo; }
__device__ __forceinline__ uint64_t cuda_mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
{
*product_hi = __umul64hi(multiplier, multiplicand);
return(multiplier * multiplicand);
}
__global__
void cryptolight_core_gpu_phase1(int threads, uint32_t * long_state, uint32_t * ctx_state, uint32_t * ctx_key1)
{
__shared__ uint32_t __align__(16) sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
const int sub = (threadIdx.x & 7) << 2;
if(thread < threads)
{
const int oft = thread * 50 + sub + 16; // not aligned 16!
const int long_oft = (thread << LONG_SHL_IDX) + sub;
uint32_t __align__(16) key[40];
uint32_t __align__(16) text[4];
// copy 160 bytes
#pragma unroll
for (int i = 0; i < 40; i += 4)
AS_UINT4(&key[i]) = AS_UINT4(ctx_key1 + thread * 40 + i);
AS_UINT2(&text[0]) = AS_UINT2(&ctx_state[oft]);
AS_UINT2(&text[2]) = AS_UINT2(&ctx_state[oft + 2]);
__syncthreads();
for(int i = 0; i < LONG_LOOPS32; i += 32) {
cn_aes_pseudo_round_mut(sharedMemory, text, key);
AS_UINT4(&long_state[long_oft + i]) = AS_UINT4(text);
}
}
}
// --------------------------------------------------------------------------------------------------------------
__global__
void cryptolight_old_gpu_phase2(const int threads, const int bfactor, const int partidx, uint32_t * d_long_state, uint32_t * d_ctx_a, uint32_t * d_ctx_b)
{
__shared__ uint32_t __align__(16) sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
#if 0 && __CUDA_ARCH__ >= 300
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 2;
const int sub = threadIdx.x & 3;
if(thread < threads)
{
const int batchsize = ITER >> (2 + bfactor);
const int start = partidx * batchsize;
const int end = start + batchsize;
uint32_t * __restrict__ long_state = &d_long_state[thread << LONG_SHL_IDX];
uint32_t * __restrict__ ctx_a = d_ctx_a + thread * 4;
uint32_t * __restrict__ ctx_b = d_ctx_b + thread * 4;
uint32_t a, b, c, x[4];
uint32_t t1[4], t2[4], res;
uint64_t reshi, reslo;
int j;
a = ctx_a[sub];
b = ctx_b[sub];
#pragma unroll 8
for(int i = start; i < end; ++i)
{
//j = ((uint32_t *)a)[0] & 0xFFFF0;
j = (__shfl((int)a, 0, 4) & E2I_MASK1) >> 2;
//cn_aes_single_round(sharedMemory, &long_state[j], c, a);
x[0] = long_state[j + sub];
x[1] = __shfl((int)x[0], sub + 1, 4);
x[2] = __shfl((int)x[0], sub + 2, 4);
x[3] = __shfl((int)x[0], sub + 3, 4);
c = a ^
t_fn0(x[0] & 0xff) ^
t_fn1((x[1] >> 8) & 0xff) ^
t_fn2((x[2] >> 16) & 0xff) ^
t_fn3((x[3] >> 24) & 0xff);
//XOR_BLOCKS_DST(c, b, &long_state[j]);
long_state[j + sub] = c ^ b;
//MUL_SUM_XOR_DST(c, a, &long_state[((uint32_t *)c)[0] & 0xFFFF0]);
j = (__shfl((int)c, 0, 4) & E2I_MASK1) >> 2;
#pragma unroll
for(int k = 0; k < 2; k++)
t1[k] = __shfl((int)c, k, 4);
#pragma unroll
for(int k = 0; k < 4; k++)
t2[k] = __shfl((int)a, k, 4);
asm(
"mad.lo.u64 %0, %2, %3, %4;\n\t"
"mad.hi.u64 %1, %2, %3, %5;\n\t"
: "=l"(reslo), "=l"(reshi)
: "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0]));
res = (sub & 2 ? reslo : reshi) >> (sub & 1 ? 32 : 0);
a = long_state[j + sub] ^ res;
long_state[j + sub] = res;
//j = ((uint32_t *)a)[0] & 0xFFFF0;
j = (__shfl((int)a, 0, 4) & E2I_MASK1) >> 2;
//cn_aes_single_round(sharedMemory, &long_state[j], b, a);
x[0] = long_state[j + sub];
x[1] = __shfl((int)x[0], sub + 1, 4);
x[2] = __shfl((int)x[0], sub + 2, 4);
x[3] = __shfl((int)x[0], sub + 3, 4);
b = a ^
t_fn0(x[0] & 0xff) ^
t_fn1((x[1] >> 8) & 0xff) ^
t_fn2((x[2] >> 16) & 0xff) ^
t_fn3((x[3] >> 24) & 0xff);
//XOR_BLOCKS_DST(b, c, &long_state[j]);
long_state[j + sub] = c ^ b;
//MUL_SUM_XOR_DST(b, a, &long_state[((uint32_t *)b)[0] & 0xFFFF0]);
j = (__shfl((int)b, 0, 4) & E2I_MASK1) >> 2;
#pragma unroll
for(int k = 0; k < 2; k++)
t1[k] = __shfl((int)b, k, 4);
#pragma unroll
for(int k = 0; k < 4; k++)
t2[k] = __shfl((int)a, k, 4);
asm(
"mad.lo.u64 %0, %2, %3, %4;\n\t"
"mad.hi.u64 %1, %2, %3, %5;\n\t"
: "=l"(reslo), "=l"(reshi)
: "l"(((uint64_t *)t1)[0]), "l"(((uint64_t *)long_state)[j >> 1]), "l"(((uint64_t *)t2)[1]), "l"(((uint64_t *)t2)[0]));
res = (sub & 2 ? reslo : reshi) >> (sub & 1 ? 32 : 0);
a = long_state[j + sub] ^ res;
long_state[j + sub] = res;
}
if(bfactor > 0)
{
ctx_a[sub] = a;
ctx_b[sub] = b;
}
}
#else // __CUDA_ARCH__ < 300
const int thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
const int batchsize = ITER >> (2 + bfactor);
const int start = partidx * batchsize;
const int end = start + batchsize;
const int longptr = thread << LONG_SHL_IDX;
uint32_t * long_state = &d_long_state[longptr];
uint64_t * ctx_a = (uint64_t*)(&d_ctx_a[thread * 4]);
uint64_t * ctx_b = (uint64_t*)(&d_ctx_b[thread * 4]);
uint4 A = AS_UINT4(ctx_a);
uint4 B = AS_UINT4(ctx_b);
uint32_t* a = (uint32_t*)&A;
uint32_t* b = (uint32_t*)&B;
for (int i = start; i < end; i++) // end = 262144
{
uint32_t c[4];
uint32_t j = (a[0] >> 2) & E2I_MASK2;
cn_aes_single_round(sharedMemory, &long_state[j], c, a);
XOR_BLOCKS_DST(c, b, &long_state[j]);
MUL_SUM_XOR_DST(c, a, &long_state[(c[0] >> 2) & E2I_MASK2]);
j = (a[0] >> 2) & E2I_MASK2;
cn_aes_single_round(sharedMemory, &long_state[j], b, a);
XOR_BLOCKS_DST(b, c, &long_state[j]);
MUL_SUM_XOR_DST(b, a, &long_state[(b[0] >> 2) & E2I_MASK2]);
}
if (bfactor > 0) {
AS_UINT4(ctx_a) = A;
AS_UINT4(ctx_b) = B;
}
}
#endif // __CUDA_ARCH__ >= 300
}
__device__ __forceinline__ void store_variant1(uint32_t* long_state)
{
uint4* Z = (uint4*) long_state;
const uint32_t tmp = (Z->z >> 24); // __byte_perm(src, 0, 0x7773);
const uint32_t index = (((tmp >> 3) & 6u) | (tmp & 1u)) << 1;
Z->z = (Z->z & 0x00ffffffu) | ((tmp ^ ((0x75310u >> index) & 0x30u)) << 24);
}
#define MUL_SUM_XOR_DST_1(a,c,dst,tweak) { \
uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], ((uint64_t *)dst)[0], &hi) + ((uint64_t *)c)[1]; \
hi += ((uint64_t *)c)[0]; \
((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi; \
((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo; \
((uint64_t *)dst)[0] = hi; \
((uint64_t *)dst)[1] = lo ^ tweak; }
__global__
void cryptolight_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
uint32_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
uint64_t * __restrict__ d_tweak)
{
__shared__ __align__(16) uint32_t sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
const uint32_t batchsize = ITER >> (2 + bfactor);
const uint32_t start = partidx * batchsize;
const uint32_t end = start + batchsize;
const uint32_t longptr = thread << LONG_SHL_IDX;
uint32_t * long_state = &d_long_state[longptr];
uint64_t tweak = d_tweak[thread];
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
uint4 B = AS_UINT4(ctx_b);
uint32_t* a = (uint32_t*)&A;
uint32_t* b = (uint32_t*)&B;
for (int i = start; i < end; i++)
{
uint32_t c[4];
uint32_t j = (A.x >> 2) & E2I_MASK2;
cn_aes_single_round(sharedMemory, &long_state[j], c, a);
XOR_BLOCKS_DST(c, b, &long_state[j]);
store_variant1(&long_state[j]);
MUL_SUM_XOR_DST_1(c, a, &long_state[(c[0] >> 2) & E2I_MASK2], tweak);
j = (A.x >> 2) & E2I_MASK2;
cn_aes_single_round(sharedMemory, &long_state[j], b, a);
XOR_BLOCKS_DST(b, c, &long_state[j]);
store_variant1(&long_state[j]);
MUL_SUM_XOR_DST_1(b, a, &long_state[(b[0] >> 2) & E2I_MASK2], tweak);
}
if (bfactor) {
AS_UINT4(ctx_a) = A;
AS_UINT4(ctx_b) = B;
}
}
}
__global__
void cryptolight_core_gpu_phase3(int threads, const uint32_t * long_state, uint32_t * ctx_state, uint32_t * ctx_key2)
{
__shared__ uint32_t __align__(16) sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
const int thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
const int sub = (threadIdx.x & 7) << 2;
if(thread < threads)
{
const int long_oft = (thread << LONG_SHL_IDX) + sub;
const int oft = thread * 50 + sub + 16;
uint32_t __align__(16) key[40];
uint32_t __align__(16) text[4];
#pragma unroll
for (int i = 0; i < 40; i += 4)
AS_UINT4(&key[i]) = AS_UINT4(ctx_key2 + thread * 40 + i);
AS_UINT2(&text[0]) = AS_UINT2(&ctx_state[oft + 0]);
AS_UINT2(&text[2]) = AS_UINT2(&ctx_state[oft + 2]);
__syncthreads();
for(int i = 0; i < LONG_LOOPS32; i += 32)
{
#pragma unroll
for(int j = 0; j < 4; j++)
text[j] ^= long_state[long_oft + i + j];
cn_aes_pseudo_round_mut(sharedMemory, text, key);
}
AS_UINT2(&ctx_state[oft + 0]) = AS_UINT2(&text[0]);
AS_UINT2(&ctx_state[oft + 2]) = AS_UINT2(&text[2]);
}
}
extern int device_bfactor[MAX_GPUS];
__host__
void cryptolight_core_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state,
uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
{
dim3 grid(blocks);
dim3 block(threads);
dim3 block4(threads << 2);
dim3 block8(threads << 3);
const int bfactor = device_bfactor[thr_id];
const int bsleep = bfactor ? 100 : 0;
int i, partcount = 1 << bfactor;
int dev_id = device_map[thr_id];
cryptolight_core_gpu_phase1 <<<grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key1);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
if(partcount > 1) usleep(bsleep);
for(i = 0; i < partcount; i++)
{
dim3 b = device_sm[dev_id] >= 300 ? block4 : block;
if (variant == 0)
cryptolight_old_gpu_phase2 <<<grid, b>>> (blocks*threads, bfactor, i, d_long_state, d_ctx_a, d_ctx_b);
else
cryptolight_gpu_phase2 <<<grid, b>>> (blocks*threads, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
if(partcount > 1) usleep(bsleep);
}
cryptolight_core_gpu_phase3 <<<grid, block8 >>>(blocks*threads, d_long_state, d_ctx_state, d_ctx_key2);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
+246
View File
@@ -0,0 +1,246 @@
#include <miner.h>
#include <memory.h>
#include "oaes_lib.h"
#include "cryptolight.h"
extern "C" {
#include <sph/sph_blake.h>
#include <sph/sph_groestl.h>
#include <sph/sph_jh.h>
#include <sph/sph_skein.h>
#include "cpu/c_keccak.h"
}
struct cryptonight_ctx {
uint8_t long_state[MEMORY];
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE];
uint8_t b[AES_BLOCK_SIZE];
uint8_t c[AES_BLOCK_SIZE];
oaes_ctx* aes_ctx;
};
static void do_blake_hash(const void* input, int len, void* output)
{
uchar hash[32];
sph_blake256_context ctx;
sph_blake256_set_rounds(14);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, len);
sph_blake256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_groestl_hash(const void* input, int len, void* output)
{
uchar hash[32];
sph_groestl256_context ctx;
sph_groestl256_init(&ctx);
sph_groestl256(&ctx, input, len);
sph_groestl256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_jh_hash(const void* input, int len, void* output)
{
uchar hash[64];
sph_jh256_context ctx;
sph_jh256_init(&ctx);
sph_jh256(&ctx, input, len);
sph_jh256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_skein_hash(const void* input, int len, void* output)
{
uchar hash[32];
sph_skein256_context ctx;
sph_skein256_init(&ctx);
sph_skein256(&ctx, input, len);
sph_skein256_close(&ctx, hash);
memcpy(output, hash, 32);
}
// todo: use sph if possible
static void keccak_hash_permutation(union hash_state *state) {
keccakf((uint64_t*)state, 24);
}
static void keccak_hash_process(union hash_state *state, const uint8_t *buf, int count) {
keccak1600(buf, (int)count, (uint8_t*)state);
}
extern "C" int fast_aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern "C" int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern "C" int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
extern "C" int fast_aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
static void (* const extra_hashes[4])(const void*, int, void *) = {
do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash
};
static uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
{
// multiplier = ab = a * 2^32 + b
// multiplicand = cd = c * 2^32 + d
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
uint64_t a = hi_dword(multiplier);
uint64_t b = lo_dword(multiplier);
uint64_t c = hi_dword(multiplicand);
uint64_t d = lo_dword(multiplicand);
uint64_t ac = a * c;
uint64_t ad = a * d;
uint64_t bc = b * c;
uint64_t bd = b * d;
uint64_t adbc = ad + bc;
uint64_t adbc_carry = adbc < ad ? 1 : 0;
// multiplier * multiplicand = product_hi * 2^64 + product_lo
uint64_t product_lo = bd + (adbc << 32);
uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
*product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
return product_lo;
}
static size_t e2i(const uint8_t* a) {
//const uint32_t mask = (MEMORY / AES_BLOCK_SIZE - 1);
//return (*((uint64_t*) a) / AES_BLOCK_SIZE) & mask;
return *((uint64_t*) a) & 0xFFFF0; /* mask * AES_BLOCK_SIZE */
}
static void mul(const uint8_t* a, const uint8_t* b, uint8_t* res) {
((uint64_t*) res)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) res);
}
static void sum_half_blocks(uint8_t* a, const uint8_t* b) {
((uint64_t*) a)[0] += ((uint64_t*) b)[0];
((uint64_t*) a)[1] += ((uint64_t*) b)[1];
}
static void sum_half_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] + ((uint64_t*) b)[0];
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] + ((uint64_t*) b)[1];
}
static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, uint8_t* dst) {
((uint64_t*) dst)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) dst) + ((uint64_t*) c)[1];
((uint64_t*) dst)[0] += ((uint64_t*) c)[0];
}
static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak) {
uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1];
hi += ((uint64_t*) c)[0];
((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi;
((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo;
((uint64_t*) dst)[0] = hi;
((uint64_t*) dst)[1] = variant ? lo ^ tweak : lo;
}
static void copy_block(uint8_t* dst, const uint8_t* src) {
((uint64_t*) dst)[0] = ((uint64_t*) src)[0];
((uint64_t*) dst)[1] = ((uint64_t*) src)[1];
}
static void xor_blocks(uint8_t* a, const uint8_t* b) {
((uint64_t*) a)[0] ^= ((uint64_t*) b)[0];
((uint64_t*) a)[1] ^= ((uint64_t*) b)[1];
}
static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] ^ ((uint64_t*) b)[0];
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1];
}
static void cryptolight_store_variant(void* state, int variant) {
if (variant == 1) {
// use variant 1 like monero since june 2018
const uint8_t tmp = ((const uint8_t*)(state))[11];
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1;
((uint8_t*)(state))[11] = tmp ^ ((0x75310 >> index) & 0x30);
}
}
static void cryptolight_hash_ctx(void* output, const void* input, const int len, struct cryptonight_ctx* ctx, const int variant)
{
size_t i, j;
keccak_hash_process(&ctx->state.hs, (const uint8_t*) input, len);
ctx->aes_ctx = (oaes_ctx*) oaes_alloc();
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
const uint64_t tweak = variant ? *((uint64_t*) (((uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0;
oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
#undef RND
#define RND(p) aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * p], ctx->aes_ctx->key->exp_data);
RND(0);
RND(1);
RND(2);
RND(3);
RND(4);
RND(5);
RND(6);
RND(7);
memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
}
xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a);
xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b);
for (i = 0; likely(i < ITER / 4); ++i) {
j = e2i(ctx->a);
aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a);
xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
cryptolight_store_variant(&ctx->long_state[j], variant);
mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c)], variant, tweak);
j = e2i(ctx->a);
aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a);
xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]);
cryptolight_store_variant(&ctx->long_state[j], variant);
mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b)], variant, tweak);
}
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
#undef RND
#define RND(p) xor_blocks(&ctx->text[p * AES_BLOCK_SIZE], &ctx->long_state[i + p * AES_BLOCK_SIZE]); \
aesb_pseudo_round_mut(&ctx->text[p * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data);
RND(0);
RND(1);
RND(2);
RND(3);
RND(4);
RND(5);
RND(6);
RND(7);
}
memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
keccak_hash_permutation(&ctx->state.hs);
int extra_algo = ctx->state.hs.b[0] & 3;
extra_hashes[extra_algo](&ctx->state, 200, output);
if (opt_debug) applog(LOG_DEBUG, "extra algo=%d", extra_algo);
oaes_free((OAES_CTX **) &ctx->aes_ctx);
}
void cryptolight_hash_variant(void* output, const void* input, int len, int variant)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
cryptolight_hash_ctx(output, input, len, ctx, variant);
free(ctx);
}
void cryptolight_hash(void* output, const void* input)
{
cryptolight_hash_variant(output, input, 76, 1);
}
+176
View File
@@ -0,0 +1,176 @@
#include "cryptolight.h"
extern char *device_config[MAX_GPUS]; // -l 32x16
static __thread uint32_t cn_blocks = 32;
static __thread uint32_t cn_threads = 16;
static uint32_t *d_long_state[MAX_GPUS];
static uint32_t *d_ctx_state[MAX_GPUS];
static uint32_t *d_ctx_key1[MAX_GPUS];
static uint32_t *d_ctx_key2[MAX_GPUS];
static uint32_t *d_ctx_text[MAX_GPUS];
static uint64_t *d_ctx_tweak[MAX_GPUS];
static uint32_t *d_ctx_a[MAX_GPUS];
static uint32_t *d_ctx_b[MAX_GPUS];
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_cryptolight(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int variant)
{
int res = 0;
uint32_t throughput = 0;
uint32_t *ptarget = work->target;
uint8_t *pdata = (uint8_t*) work->data;
uint32_t *nonceptr = (uint32_t*) (&pdata[39]);
const uint32_t first_nonce = *nonceptr;
uint32_t nonce = first_nonce;
int dev_id = device_map[thr_id];
if(opt_benchmark) {
ptarget[7] = 0x00ff;
}
if(!init[thr_id])
{
if (!device_config[thr_id] && strcmp(device_name[dev_id], "TITAN V") == 0) {
device_config[thr_id] = strdup("80x32");
}
if (device_config[thr_id]) {
sscanf(device_config[thr_id], "%ux%u", &cn_blocks, &cn_threads);
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
gpulog(LOG_INFO, thr_id, "Using %u x %u kernel launch config, %u threads",
cn_blocks, cn_threads, throughput);
} else {
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
if (throughput != cn_blocks*cn_threads && cn_threads) {
cn_blocks = throughput / cn_threads;
throughput = cn_threads * cn_blocks;
}
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u threads (%ux%u)",
throughput2intensity(throughput), throughput, cn_blocks, cn_threads);
}
if(sizeof(size_t) == 4 && throughput > UINT32_MAX / MEMORY) {
gpulog(LOG_ERR, thr_id, "THE 32bit VERSION CAN'T ALLOCATE MORE THAN 4GB OF MEMORY!");
gpulog(LOG_ERR, thr_id, "PLEASE REDUCE THE NUMBER OF THREADS OR BLOCKS");
exit(1);
}
cudaSetDevice(device_map[thr_id]);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
const size_t alloc = MEMORY * throughput;
cryptonight_extra_init(thr_id);
cudaMalloc(&d_long_state[thr_id], alloc);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_state[thr_id], 25 * sizeof(uint64_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_key1[thr_id], 40 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_key2[thr_id], 40 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_text[thr_id], 32 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_a[thr_id], 4 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_b[thr_id], 4 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_tweak[thr_id], sizeof(uint64_t) * throughput);
init[thr_id] = true;
}
throughput = cn_blocks*cn_threads;
do
{
const uint32_t Htarg = ptarget[7];
uint32_t resNonces[2] = { UINT32_MAX, UINT32_MAX };
cryptonight_extra_setData(thr_id, pdata, ptarget);
cryptonight_extra_prepare(thr_id, throughput, nonce, d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
cryptolight_core_hash(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
cryptonight_extra_final(thr_id, throughput, nonce, resNonces, d_ctx_state[thr_id]);
*hashes_done = nonce - first_nonce + throughput;
if(resNonces[0] != UINT32_MAX)
{
uint32_t vhash[8];
uint32_t tempdata[19];
uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39);
memcpy(tempdata, pdata, 76);
*tempnonceptr = resNonces[0];
cryptolight_hash_variant(vhash, tempdata, 76, variant);
if(vhash[7] <= Htarg && fulltest(vhash, ptarget))
{
res = 1;
work->nonces[0] = resNonces[0];
work_set_target_ratio(work, vhash);
// second nonce
if(resNonces[1] != UINT32_MAX)
{
*tempnonceptr = resNonces[1];
cryptolight_hash_variant(vhash, tempdata, 76, variant);
if(vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
res++;
work->nonces[1] = resNonces[1];
} else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
}
}
goto done;
} else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", resNonces[0]);
}
}
if ((uint64_t) throughput + nonce >= max_nonce - 127) {
nonce = max_nonce;
break;
}
nonce += throughput;
gpulog(LOG_DEBUG, thr_id, "nonce %08x", nonce);
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + nonce);
done:
gpulog(LOG_DEBUG, thr_id, "nonce %08x exit", nonce);
work->valid_nonces = res;
*nonceptr = nonce;
return res;
}
void free_cryptolight(int thr_id)
{
if (!init[thr_id])
return;
cudaFree(d_long_state[thr_id]);
cudaFree(d_ctx_state[thr_id]);
cudaFree(d_ctx_key1[thr_id]);
cudaFree(d_ctx_key2[thr_id]);
cudaFree(d_ctx_text[thr_id]);
cudaFree(d_ctx_tweak[thr_id]);
cudaFree(d_ctx_a[thr_id]);
cudaFree(d_ctx_b[thr_id]);
cryptonight_extra_free(thr_id);
cudaDeviceSynchronize();
init[thr_id] = false;
}
+144
View File
@@ -0,0 +1,144 @@
#pragma once
#include <cuda_runtime.h>
#include <miner.h>
#ifdef __INTELLISENSE__
/* avoid red underlining */
#define __CUDA_ARCH__ 520
struct uint3 {
unsigned int x, y, z;
};
struct uint3 threadIdx;
struct uint3 blockIdx;
struct uint3 blockDim;
#define atomicExch(p,y) (*p) = y
#define __funnelshift_r(a,b,c) 1
#define __syncthreads()
#define __threadfence_block()
#define asm(x)
#define __shfl(a,b,c) 1
#define __umul64hi(a,b) a*b
#endif
#define MEMORY (1UL << 20) /* 1 MiB - 1048576 */
#define ITER (1UL << 19) /* 512k */
#define E2I_MASK1 0xFFFF0 /* MEMORY / AES_BLOCK_SIZE - 1 = 0xFFFF */
#define E2I_MASK2 0x3FFFC /* 0xFFFF0 >> 2 */
#define AES_BLOCK_SIZE 16
#define AES_KEY_SIZE 32
#define INIT_SIZE_BLK 8
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B
#define AES_RKEY_LEN 4
#define AES_COL_LEN 4
#define AES_ROUND_BASE 7
#ifndef HASH_SIZE
#define HASH_SIZE 32
#endif
#ifndef HASH_DATA_AREA
#define HASH_DATA_AREA 136
#endif
#define hi_dword(x) (x >> 32)
#define lo_dword(x) (x & 0xFFFFFFFF)
#define C32(x) ((uint32_t)(x ## U))
#define T32(x) ((x) & C32(0xFFFFFFFF))
#ifndef ROTL64
#if __CUDA_ARCH__ >= 350
__forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) {
uint2 result;
if(offset >= 32) {
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
} else {
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
}
return __double_as_longlong(__hiloint2double(result.y, result.x));
}
#define ROTL64(x, n) (cuda_ROTL64(x, n))
#else
#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
#endif
#endif
#ifndef ROTL32
#if __CUDA_ARCH__ < 350
#define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n))))
#else
#define ROTL32(x, n) __funnelshift_l( (x), (x), (n) )
#endif
#endif
#ifndef ROTR32
#if __CUDA_ARCH__ < 350
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#else
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
#endif
#endif
#define MEMSET8(dst,what,cnt) { \
int i_memset8; \
uint64_t *out_memset8 = (uint64_t *)(dst); \
for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \
out_memset8[i_memset8] = (what); }
#define MEMSET4(dst,what,cnt) { \
int i_memset4; \
uint32_t *out_memset4 = (uint32_t *)(dst); \
for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \
out_memset4[i_memset4] = (what); }
#define MEMCPY8(dst,src,cnt) { \
int i_memcpy8; \
uint64_t *in_memcpy8 = (uint64_t *)(src); \
uint64_t *out_memcpy8 = (uint64_t *)(dst); \
for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \
out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; }
#define MEMCPY4(dst,src,cnt) { \
int i_memcpy4; \
uint32_t *in_memcpy4 = (uint32_t *)(src); \
uint32_t *out_memcpy4 = (uint32_t *)(dst); \
for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \
out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; }
#define XOR_BLOCKS_DST(x,y,z) { \
((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \
((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; }
union hash_state {
uint8_t b[200];
uint64_t w[25];
};
union cn_slow_hash_state {
union hash_state hs;
struct {
uint8_t k[64];
uint8_t init[INIT_SIZE_BYTE];
};
};
static inline void exit_if_cudaerror(int thr_id, const char *src, int line)
{
cudaError_t err = cudaGetLastError();
if(err != cudaSuccess) {
gpulog(LOG_ERR, thr_id, "%s %s line %d", cudaGetErrorString(err), src, line);
exit(1);
}
}
void cryptolight_core_hash(int thr_id, int blocks, int threads, uint32_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget);
void cryptonight_extra_init(int thr_id/*, uint32_t threads*/);
void cryptonight_extra_free(int thr_id);
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resNonces, uint32_t *d_ctx_state);
+316
View File
@@ -0,0 +1,316 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <cuda.h>
#include <cuda_runtime.h>
#if CUDA_VERSION >= 9000 && __CUDA_ARCH__ >= 300
#undef __shfl
#define __shfl(var, srcLane, width) __shfl_sync(0xFFFFFFFFu, var, srcLane, width)
#endif
#include "cryptonight.h"
#define LONG_SHL32 19 // 1<<19 (uint32_t* index)
#define LONG_SHL64 18 // 1<<18 (uint64_t* index)
#define LONG_LOOPS32 0x80000U
#include "cn_aes.cuh"
__global__
void cryptonight_gpu_phase1(const uint32_t threads, uint32_t * __restrict__ d_long_state,
uint32_t * __restrict__ ctx_state, uint32_t * __restrict__ ctx_key1)
{
__shared__ uint32_t sharedMemory[1024];
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
if(thread < threads)
{
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t sub = (threadIdx.x & 0x7U) << 2;
uint32_t *longstate = &d_long_state[(thread << LONG_SHL32) + sub];
uint32_t __align__(8) key[40];
MEMCPY8(key, &ctx_key1[thread * 40U], 20);
uint32_t __align__(8) text[4];
MEMCPY8(text, &ctx_state[thread * 50U + sub + 16U], 2);
for(int i = 0; i < LONG_LOOPS32; i += 32)
{
cn_aes_pseudo_round_mut(sharedMemory, text, key);
MEMCPY8(&longstate[i], text, 2);
}
}
}
// --------------------------------------------------------------------------------------------------------------
__device__ __forceinline__ ulonglong2 cuda_mul128(const uint64_t multiplier, const uint64_t multiplicand)
{
ulonglong2 product;
product.x = __umul64hi(multiplier, multiplicand);
product.y = multiplier * multiplicand;
return product;
}
static __forceinline__ __device__ void operator += (ulonglong2 &a, const ulonglong2 b) {
a.x += b.x; a.y += b.y;
}
static __forceinline__ __device__ ulonglong2 operator ^ (const ulonglong2 &a, const ulonglong2 &b) {
return make_ulonglong2(a.x ^ b.x, a.y ^ b.y);
}
__device__ __forceinline__ void MUL_SUM_XOR_DST_0(const uint64_t m, uint4 &a, void* far_dst)
{
ulonglong2 d = AS_UL2(far_dst);
ulonglong2 p = cuda_mul128(m, d.x);
p += AS_UL2(&a);
AS_UL2(&a) = p ^ d;
AS_UL2(far_dst) = p;
}
__global__
#if __CUDA_ARCH__ >= 500
//__launch_bounds__(128,12) /* force 40 regs to allow -l ...x32 */
#endif
void cryptonight_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b)
{
__shared__ __align__(16) uint32_t sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
const uint32_t batchsize = ITER >> (2 + bfactor);
const uint32_t start = partidx * batchsize;
const uint32_t end = start + batchsize;
void * ctx_a = (void*)(&d_ctx_a[thread << 2U]);
void * ctx_b = (void*)(&d_ctx_b[thread << 2U]);
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
uint4 B = AS_UINT4(ctx_b);
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
for (int i = start; i < end; i++) // end = 262144
{
uint4 C;
uint32_t j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
AS_UINT4(&long_state[j]) = C ^ B; // st.global.u32.v4
MUL_SUM_XOR_DST_0((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3]);
j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
AS_UINT4(&long_state[j]) = C ^ B;
MUL_SUM_XOR_DST_0((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3]);
}
if (bfactor) {
AS_UINT4(ctx_a) = A;
AS_UINT4(ctx_b) = B;
}
}
}
// --------------------------------------------------------------------------------------------------------------
__device__ __forceinline__ void store_variant1(uint64_t* long_state, uint4 Z)
{
const uint32_t tmp = (Z.z >> 24); // __byte_perm(src, 0, 0x7773);
const uint32_t index = (((tmp >> 3) & 6u) | (tmp & 1u)) << 1;
Z.z = (Z.z & 0x00ffffffu) | ((tmp ^ ((0x75310u >> index) & 0x30u)) << 24);
AS_UINT4(long_state) = Z;
}
__device__ __forceinline__ void store_variant2(uint64_t* long_state, uint4 Z)
{
const uint32_t tmp = (Z.z >> 24); // __byte_perm(src, 0, 0x7773);
const uint32_t index = (((tmp >> 4) & 6u) | (tmp & 1u)) << 1;
Z.z = (Z.z & 0x00ffffffu) | ((tmp ^ ((0x75312u >> index) & 0x30u)) << 24);
AS_UINT4(long_state) = Z;
}
__device__ __forceinline__ void MUL_SUM_XOR_DST_1(const uint64_t m, uint4 &a, void* far_dst, uint64_t tweak)
{
ulonglong2 d = AS_UL2(far_dst);
ulonglong2 p = cuda_mul128(m, d.x);
p += AS_UL2(&a);
AS_UL2(&a) = p ^ d;
p.y = p.y ^ tweak;
AS_UL2(far_dst) = p;
}
__global__
void monero_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
uint64_t * __restrict__ d_tweak)
{
__shared__ __align__(16) uint32_t sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
const uint32_t batchsize = ITER >> (2 + bfactor);
const uint32_t start = partidx * batchsize;
const uint32_t end = start + batchsize;
uint64_t tweak = d_tweak[thread];
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
uint4 B = AS_UINT4(ctx_b);
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
for (int i = start; i < end; i++) // end = 262144
{
uint4 C;
uint32_t j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
store_variant1(&long_state[j], C ^ B); // st.global
MUL_SUM_XOR_DST_1((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3], tweak);
j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
store_variant1(&long_state[j], C ^ B);
MUL_SUM_XOR_DST_1((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3], tweak);
}
if (bfactor) {
AS_UINT4(ctx_a) = A;
AS_UINT4(ctx_b) = B;
}
}
}
// --------------------------------------------------------------------------------------------------------------
__global__
void stellite_gpu_phase2(const uint32_t threads, const uint16_t bfactor, const uint32_t partidx,
uint64_t * __restrict__ d_long_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
uint64_t * __restrict__ d_tweak)
{
__shared__ __align__(16) uint32_t sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if (thread < threads)
{
const uint32_t batchsize = ITER >> (2 + bfactor);
const uint32_t start = partidx * batchsize;
const uint32_t end = start + batchsize;
uint64_t tweak = d_tweak[thread];
void * ctx_a = (void*)(&d_ctx_a[thread << 2]);
void * ctx_b = (void*)(&d_ctx_b[thread << 2]);
uint4 A = AS_UINT4(ctx_a); // ld.global.u32.v4
uint4 B = AS_UINT4(ctx_b);
uint64_t * long_state = &d_long_state[thread << LONG_SHL64];
for (int i = start; i < end; i++) // end = 262144
{
uint4 C;
uint32_t j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &C);
store_variant2(&long_state[j], C ^ B); // st.global
MUL_SUM_XOR_DST_1((AS_UL2(&C)).x, A, &long_state[(C.x & E2I_MASK) >> 3], tweak);
j = (A.x & E2I_MASK) >> 3;
cn_aes_single_round_b((uint8_t*)sharedMemory, &long_state[j], A, &B);
store_variant2(&long_state[j], C ^ B);
MUL_SUM_XOR_DST_1((AS_UL2(&B)).x, A, &long_state[(B.x & E2I_MASK) >> 3], tweak);
}
if (bfactor) {
AS_UINT4(ctx_a) = A;
AS_UINT4(ctx_b) = B;
}
}
}
// --------------------------------------------------------------------------------------------------------------
__global__
void cryptonight_gpu_phase3(const uint32_t threads, const uint32_t * __restrict__ d_long_state,
uint32_t * __restrict__ d_ctx_state, const uint32_t * __restrict__ d_ctx_key2)
{
__shared__ uint32_t sharedMemory[1024];
cn_aes_gpu_init(sharedMemory);
__syncthreads();
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) >> 3;
if(thread < threads)
{
const int sub = (threadIdx.x & 7) << 2;
const uint32_t *longstate = &d_long_state[(thread << LONG_SHL32) + sub];
uint32_t key[40], text[4];
MEMCPY8(key, d_ctx_key2 + thread * 40, 20);
MEMCPY8(text, d_ctx_state + thread * 50 + sub + 16, 2);
for(int i = 0; i < LONG_LOOPS32; i += 32)
{
#pragma unroll
for(int j = 0; j < 4; ++j)
text[j] ^= longstate[i + j];
cn_aes_pseudo_round_mut(sharedMemory, text, key);
}
MEMCPY8(d_ctx_state + thread * 50 + sub + 16, text, 2);
}
}
// --------------------------------------------------------------------------------------------------------------
extern int device_bfactor[MAX_GPUS];
__host__
void cryptonight_core_cuda(int thr_id, uint32_t blocks, uint32_t threads, uint64_t *d_long_state, uint32_t *d_ctx_state,
uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
{
dim3 grid(blocks);
dim3 block(threads);
dim3 block4(threads << 2);
dim3 block8(threads << 3);
const uint16_t bfactor = (uint16_t) device_bfactor[thr_id];
const uint32_t partcount = 1U << bfactor;
const uint32_t throughput = (uint32_t) (blocks*threads);
const int bsleep = bfactor ? 100 : 0;
const int dev_id = device_map[thr_id];
cryptonight_gpu_phase1 <<<grid, block8>>> (throughput, (uint32_t*) d_long_state, d_ctx_state, d_ctx_key1);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
if(partcount > 1) usleep(bsleep);
for (uint32_t i = 0; i < partcount; i++)
{
dim3 b = device_sm[dev_id] >= 300 ? block4 : block;
if (variant == 0)
cryptonight_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b);
else if (variant == 1 || cryptonight_fork == 8)
monero_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
else if (variant == 2 && cryptonight_fork == 3)
stellite_gpu_phase2 <<<grid, b>>> (throughput, bfactor, i, d_long_state, d_ctx_a, d_ctx_b, d_ctx_tweak);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
if(partcount > 1) usleep(bsleep);
}
//cudaDeviceSynchronize();
//exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cryptonight_gpu_phase3 <<<grid, block8>>> (throughput, (uint32_t*) d_long_state, d_ctx_state, d_ctx_key2);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
+269
View File
@@ -0,0 +1,269 @@
#include <miner.h>
#include <memory.h>
#include "oaes_lib.h"
#include "cryptonight.h"
extern "C" {
#include <sph/sph_blake.h>
#include <sph/sph_groestl.h>
#include <sph/sph_jh.h>
#include <sph/sph_skein.h>
#include "cpu/c_keccak.h"
}
struct cryptonight_ctx {
uint8_t long_state[MEMORY];
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE];
uint8_t b[AES_BLOCK_SIZE];
uint8_t c[AES_BLOCK_SIZE];
oaes_ctx* aes_ctx;
};
static void do_blake_hash(const void* input, size_t len, void* output)
{
uchar hash[32];
sph_blake256_context ctx;
sph_blake256_set_rounds(14);
sph_blake256_init(&ctx);
sph_blake256(&ctx, input, len);
sph_blake256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_groestl_hash(const void* input, size_t len, void* output)
{
uchar hash[32];
sph_groestl256_context ctx;
sph_groestl256_init(&ctx);
sph_groestl256(&ctx, input, len);
sph_groestl256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_jh_hash(const void* input, size_t len, void* output)
{
uchar hash[64];
sph_jh256_context ctx;
sph_jh256_init(&ctx);
sph_jh256(&ctx, input, len);
sph_jh256_close(&ctx, hash);
memcpy(output, hash, 32);
}
static void do_skein_hash(const void* input, size_t len, void* output)
{
uchar hash[32];
sph_skein256_context ctx;
sph_skein256_init(&ctx);
sph_skein256(&ctx, input, len);
sph_skein256_close(&ctx, hash);
memcpy(output, hash, 32);
}
// todo: use sph if possible
static void keccak_hash_permutation(union hash_state *state) {
keccakf((uint64_t*)state, 24);
}
static void keccak_hash_process(union hash_state *state, const uint8_t *buf, size_t count) {
keccak1600(buf, (int)count, (uint8_t*)state);
}
extern "C" int fast_aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern "C" int aesb_single_round(const uint8_t *in, uint8_t*out, const uint8_t *expandedKey);
extern "C" int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
extern "C" int fast_aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey);
static void (* const extra_hashes[4])(const void*, size_t, void *) = {
do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash
};
static uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi)
{
// multiplier = ab = a * 2^32 + b
// multiplicand = cd = c * 2^32 + d
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
uint64_t a = hi_dword(multiplier);
uint64_t b = lo_dword(multiplier);
uint64_t c = hi_dword(multiplicand);
uint64_t d = lo_dword(multiplicand);
uint64_t ac = a * c;
uint64_t ad = a * d;
uint64_t bc = b * c;
uint64_t bd = b * d;
uint64_t adbc = ad + bc;
uint64_t adbc_carry = adbc < ad ? 1 : 0;
// multiplier * multiplicand = product_hi * 2^64 + product_lo
uint64_t product_lo = bd + (adbc << 32);
uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
*product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
return product_lo;
}
static size_t e2i(const uint8_t* a) {
return (*((uint64_t*) a) / AES_BLOCK_SIZE) & (MEMORY / AES_BLOCK_SIZE - 1);
}
static void mul(const uint8_t* a, const uint8_t* b, uint8_t* res) {
((uint64_t*) res)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) res);
}
static void sum_half_blocks(uint8_t* a, const uint8_t* b) {
((uint64_t*) a)[0] += ((uint64_t*) b)[0];
((uint64_t*) a)[1] += ((uint64_t*) b)[1];
}
static void sum_half_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] + ((uint64_t*) b)[0];
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] + ((uint64_t*) b)[1];
}
static void mul_sum_dst(const uint8_t* a, const uint8_t* b, const uint8_t* c, uint8_t* dst) {
((uint64_t*) dst)[1] = mul128(((uint64_t*) a)[0], ((uint64_t*) b)[0], (uint64_t*) dst) + ((uint64_t*) c)[1];
((uint64_t*) dst)[0] += ((uint64_t*) c)[0];
}
static void mul_sum_xor_dst(const uint8_t* a, uint8_t* c, uint8_t* dst, const int variant, const uint64_t tweak) {
uint64_t hi, lo = mul128(((uint64_t*) a)[0], ((uint64_t*) dst)[0], &hi) + ((uint64_t*) c)[1];
hi += ((uint64_t*) c)[0];
((uint64_t*) c)[0] = ((uint64_t*) dst)[0] ^ hi;
((uint64_t*) c)[1] = ((uint64_t*) dst)[1] ^ lo;
((uint64_t*) dst)[0] = hi;
((uint64_t*) dst)[1] = variant ? lo ^ tweak : lo;
}
static void copy_block(uint8_t* dst, const uint8_t* src) {
((uint64_t*) dst)[0] = ((uint64_t*) src)[0];
((uint64_t*) dst)[1] = ((uint64_t*) src)[1];
}
static void xor_blocks(uint8_t* a, const uint8_t* b) {
((uint64_t*) a)[0] ^= ((uint64_t*) b)[0];
((uint64_t*) a)[1] ^= ((uint64_t*) b)[1];
}
static void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* dst) {
((uint64_t*) dst)[0] = ((uint64_t*) a)[0] ^ ((uint64_t*) b)[0];
((uint64_t*) dst)[1] = ((uint64_t*) a)[1] ^ ((uint64_t*) b)[1];
}
static void cryptonight_store_variant(void* state, int variant) {
if (variant == 1 || cryptonight_fork == 8) {
// monero and graft
const uint8_t tmp = ((const uint8_t*)(state))[11];
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1;
((uint8_t*)(state))[11] = tmp ^ ((0x75310 >> index) & 0x30);
} else if (variant == 2 && cryptonight_fork == 3) {
// stellite
const uint8_t tmp = ((const uint8_t*)(state))[11];
const uint8_t index = (((tmp >> 4) & 6) | (tmp & 1)) << 1;
((uint8_t*)(state))[11] = tmp ^ ((0x75312 >> index) & 0x30);
}
}
static void cryptonight_hash_ctx(void* output, const void* input, const size_t len, struct cryptonight_ctx* ctx, const int variant)
{
size_t i, j;
keccak_hash_process(&ctx->state.hs, (const uint8_t*) input, len);
ctx->aes_ctx = (oaes_ctx*) oaes_alloc();
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
const uint64_t tweak = variant ? *((uint64_t*) (((uint8_t*)input) + 35)) ^ ctx->state.hs.w[24] : 0;
oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
#undef RND
#define RND(p) aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * p], ctx->aes_ctx->key->exp_data);
RND(0);
RND(1);
RND(2);
RND(3);
RND(4);
RND(5);
RND(6);
RND(7);
memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
}
xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a);
xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b);
for (i = 0; likely(i < ITER / 4); ++i) {
j = e2i(ctx->a) * AES_BLOCK_SIZE;
aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a);
xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
cryptonight_store_variant(&ctx->long_state[j], variant);
mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c) * AES_BLOCK_SIZE], variant, tweak);
j = e2i(ctx->a) * AES_BLOCK_SIZE;
aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a);
xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]);
cryptonight_store_variant(&ctx->long_state[j], variant);
mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b) * AES_BLOCK_SIZE], variant, tweak);
}
memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) {
#undef RND
#define RND(p) xor_blocks(&ctx->text[p * AES_BLOCK_SIZE], &ctx->long_state[i + p * AES_BLOCK_SIZE]); \
aesb_pseudo_round_mut(&ctx->text[p * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data);
RND(0);
RND(1);
RND(2);
RND(3);
RND(4);
RND(5);
RND(6);
RND(7);
}
memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
keccak_hash_permutation(&ctx->state.hs);
int extra_algo = ctx->state.hs.b[0] & 3;
extra_hashes[extra_algo](&ctx->state, 200, output);
if (opt_debug) applog(LOG_DEBUG, "extra algo=%d", extra_algo);
oaes_free((OAES_CTX **) &ctx->aes_ctx);
}
void cryptonight_hash_variant(void* output, const void* input, size_t len, int variant)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
cryptonight_hash_ctx(output, input, len, ctx, variant);
free(ctx);
}
void cryptonight_hash(void* output, const void* input)
{
cryptonight_fork = 1;
cryptonight_hash_variant(output, input, 76, 0);
}
void graft_hash(void* output, const void* input)
{
cryptonight_fork = 8;
cryptonight_hash_variant(output, input, 76, 1);
}
void monero_hash(void* output, const void* input)
{
cryptonight_fork = 7;
cryptonight_hash_variant(output, input, 76, 1);
}
void stellite_hash(void* output, const void* input)
{
cryptonight_fork = 3;
cryptonight_hash_variant(output, input, 76, 2);
}
+212
View File
@@ -0,0 +1,212 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <miner.h>
#include <cuda_helper.h>
#include "cryptonight.h"
static uint32_t *d_input[MAX_GPUS];
static uint32_t *d_target[MAX_GPUS];
static uint32_t *d_result[MAX_GPUS];
typedef uint8_t BitSequence;
typedef uint32_t DataLength;
#include "cn_keccak.cuh"
#include "cn_blake.cuh"
#include "cn_groestl.cuh"
#include "cn_jh.cuh"
#include "cn_skein.cuh"
__constant__ uint8_t d_sub_byte[16][16] = {
{0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76},
{0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0},
{0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15},
{0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75},
{0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84},
{0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf},
{0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8},
{0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2},
{0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73},
{0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb},
{0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79},
{0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08},
{0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a},
{0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e},
{0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf},
{0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16}
};
__device__ __forceinline__
void cryptonight_aes_set_key(uint32_t * __restrict__ key, const uint32_t * __restrict__ data)
{
const uint32_t aes_gf[10] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};
MEMCPY4(key, data, 8);
#pragma unroll
for(int i = 8; i < 40; i++)
{
uint8_t temp[4];
*(uint32_t *)temp = key[i - 1];
if(i % 8 == 0) {
*(uint32_t *)temp = ROTR32(*(uint32_t *)temp, 8);
for(int j = 0; j < 4; j++)
temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f];
*(uint32_t *)temp ^= aes_gf[i / 8 - 1];
}
else if(i % 8 == 4) {
#pragma unroll
for(int j = 0; j < 4; j++)
temp[j] = d_sub_byte[(temp[j] >> 4) & 0x0f][temp[j] & 0x0f];
}
key[i] = key[(i - 8)] ^ *(uint32_t *)temp;
}
}
__global__
void cryptonight_extra_gpu_prepare(const uint32_t threads, const uint32_t * __restrict__ d_input, uint32_t startNonce,
uint32_t * __restrict__ d_ctx_state, uint32_t * __restrict__ d_ctx_a, uint32_t * __restrict__ d_ctx_b,
uint32_t * __restrict__ d_ctx_key1, uint32_t * __restrict__ d_ctx_key2, int variant, uint64_t * d_ctx_tweak)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if(thread < threads)
{
uint64_t ctx_state[25];
uint32_t ctx_a[4];
uint32_t ctx_b[4];
uint32_t ctx_key1[40];
uint32_t ctx_key2[40];
uint32_t input[19];
MEMCPY4(input, d_input, 19);
uint32_t nonce = startNonce + thread;
*(((uint8_t *)input) + 39) = nonce & 0xff;
*(((uint8_t *)input) + 40) = (nonce >> 8) & 0xff;
*(((uint8_t *)input) + 41) = (nonce >> 16) & 0xff;
*(((uint8_t *)input) + 42) = (nonce >> 24) & 0xff;
cn_keccak(input, ctx_state);
MEMCPY4(&d_ctx_state[thread * 50U], ctx_state, 50);
cryptonight_aes_set_key(ctx_key1, (uint32_t*)(&ctx_state[0]));
cryptonight_aes_set_key(ctx_key2, (uint32_t*)(&ctx_state[4]));
MEMCPY4(&d_ctx_key1[thread * 40U], ctx_key1, 40);
MEMCPY4(&d_ctx_key2[thread * 40U], ctx_key2, 40);
XOR_BLOCKS_DST(&ctx_state[0], &ctx_state[4], ctx_a);
XOR_BLOCKS_DST(&ctx_state[2], &ctx_state[6], ctx_b);
MEMCPY4(&d_ctx_a[thread * 4U], ctx_a, 4);
MEMCPY4(&d_ctx_b[thread * 4U], ctx_b, 4);
if (variant) {
uint2 tweak = AS_UINT2(&ctx_state[24]);
//tweak.x ^= (input[8] >> 24) | (input[9] << 8);
tweak.x ^= __byte_perm(input[8], input[ 9], 0x6543);
tweak.y ^= __byte_perm(input[9], input[10], 0x6543);
MEMCPY4(&d_ctx_tweak[thread], &tweak, 2);
}
}
}
__global__
void cryptonight_extra_gpu_final(const uint32_t threads, uint32_t startNonce, const uint32_t * __restrict__ d_target,
uint32_t * __restrict__ resNonces, uint32_t * __restrict__ d_ctx_state)
{
const uint32_t thread = blockDim.x * blockIdx.x + threadIdx.x;
if(thread < threads)
{
uint32_t *ctx_state = &d_ctx_state[thread * 50U];
uint32_t hash[8];
uint32_t state[50];
#pragma unroll 25
for(int i = 0; i < 50; i+=2)
AS_UINT2(&state[i]) = AS_UINT2(&ctx_state[i]);
cn_keccakf2((uint64_t *)state);
int branch = ((uint8_t *)state)[0] & 0x03;
if(branch == 0)
cn_blake((const uint8_t *)state, 200, hash);
if(branch == 1)
cn_groestl((const uint8_t *)state, 200, hash);
if(branch == 2)
cn_jh((const uint8_t *)state, 200, hash);
if(branch == 3)
cn_skein((const uint8_t *)state, 200, hash);
if(hash[7] <= d_target[1] && hash[6] <= d_target[0])
{
const uint32_t nonce = startNonce + thread;
uint32_t tmp = atomicExch(resNonces, nonce);
if(tmp != UINT32_MAX)
resNonces[1] = tmp;
}
}
}
__host__
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget)
{
uint32_t *pTargetIn = (uint32_t*) ptarget;
cudaMemcpy(d_input[thr_id], data, 20 * sizeof(uint32_t), cudaMemcpyHostToDevice);
cudaMemcpy(d_target[thr_id], &pTargetIn[6], 2 * sizeof(uint32_t), cudaMemcpyHostToDevice);
cudaMemset(d_result[thr_id], 0xFF, 2 * sizeof(uint32_t));
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
__host__
void cryptonight_extra_init(int thr_id)
{
cudaMalloc(&d_input[thr_id], 20 * sizeof(uint32_t));
cudaMalloc(&d_target[thr_id], 2 * sizeof(uint32_t));
cudaMalloc(&d_result[thr_id], 2 * sizeof(uint32_t));
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
__host__
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak)
{
uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
cryptonight_extra_gpu_prepare <<<grid, block>>> (threads, d_input[thr_id], startNonce, d_ctx_state, d_ctx_a, d_ctx_b, d_ctx_key1, d_ctx_key2, variant, d_ctx_tweak);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
__host__
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resNonces, uint32_t *d_ctx_state)
{
uint32_t threadsperblock = 128;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cryptonight_extra_gpu_final <<<grid, block>>> (threads, startNonce, d_target[thr_id], d_result[thr_id], d_ctx_state);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMemcpy(resNonces, d_result[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
}
__host__
void cryptonight_extra_free(int thr_id)
{
if (d_input[thr_id]) {
cudaFree(d_input[thr_id]);
cudaFree(d_target[thr_id]);
cudaFree(d_result[thr_id]);
d_input[thr_id] = NULL;
}
}
+196
View File
@@ -0,0 +1,196 @@
#include "cryptonight.h"
extern char *device_config[MAX_GPUS]; // -l 32x16
static __thread uint32_t cn_blocks;
static __thread uint32_t cn_threads;
// used for gpu intensity on algo init
static __thread bool gpu_init_shown = false;
#define gpulog_init(p,thr,fmt, ...) if (!gpu_init_shown) \
gpulog(p, thr, fmt, ##__VA_ARGS__)
static uint64_t *d_long_state[MAX_GPUS];
static uint32_t *d_ctx_state[MAX_GPUS];
static uint32_t *d_ctx_key1[MAX_GPUS];
static uint32_t *d_ctx_key2[MAX_GPUS];
static uint32_t *d_ctx_text[MAX_GPUS];
static uint64_t *d_ctx_tweak[MAX_GPUS];
static uint32_t *d_ctx_a[MAX_GPUS];
static uint32_t *d_ctx_b[MAX_GPUS];
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_cryptonight(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int variant)
{
int res = 0;
uint32_t throughput = 0;
uint32_t *ptarget = work->target;
uint8_t *pdata = (uint8_t*) work->data;
uint32_t *nonceptr = (uint32_t*) (&pdata[39]);
const uint32_t first_nonce = *nonceptr;
uint32_t nonce = first_nonce;
int dev_id = device_map[thr_id];
if(opt_benchmark) {
ptarget[7] = 0x00ff;
}
if(!init[thr_id])
{
int mem = cuda_available_memory(thr_id);
int mul = device_sm[dev_id] >= 300 ? 4 : 1; // see cryptonight-core.cu
cn_threads = device_sm[dev_id] >= 600 ? 16 : 8; // real TPB is x4 on SM3+
cn_blocks = device_mpcount[dev_id] * 4;
if (cn_blocks*cn_threads*2.2 > mem) cn_blocks = device_mpcount[dev_id] * 2;
if (!opt_quiet)
gpulog_init(LOG_INFO, thr_id, "%s, %d MB available, %hd SMX", device_name[dev_id],
mem, device_mpcount[dev_id]);
if (!device_config[thr_id]) {
if(strcmp(device_name[dev_id], "TITAN V") == 0)
device_config[thr_id] = strdup("80x24");
if(strstr(device_name[dev_id], "V100"))
device_config[thr_id] = strdup("80x24");
}
if (device_config[thr_id]) {
int res = sscanf(device_config[thr_id], "%ux%u", &cn_blocks, &cn_threads);
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
gpulog_init(LOG_INFO, thr_id, "Using %ux%u(x%d) kernel launch config, %u threads",
cn_blocks, cn_threads, mul, throughput);
} else {
throughput = cuda_default_throughput(thr_id, cn_blocks*cn_threads);
if (throughput != cn_blocks*cn_threads && cn_threads) {
cn_blocks = throughput / cn_threads;
throughput = cn_threads * cn_blocks;
}
gpulog_init(LOG_INFO, thr_id, "%u threads (%g) with %u blocks",// of %ux%d",
throughput, throughput2intensity(throughput), cn_blocks);//, cn_threads, mul);
}
if(sizeof(size_t) == 4 && throughput > UINT32_MAX / MEMORY) {
gpulog(LOG_ERR, thr_id, "THE 32bit VERSION CAN'T ALLOCATE MORE THAN 4GB OF MEMORY!");
gpulog(LOG_ERR, thr_id, "PLEASE REDUCE THE NUMBER OF THREADS OR BLOCKS");
exit(1);
}
cudaSetDevice(dev_id);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
const size_t alloc = MEMORY * size_t(throughput);
cryptonight_extra_init(thr_id);
cudaMalloc(&d_long_state[thr_id], alloc);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_state[thr_id], 50 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_key1[thr_id], 40 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_key2[thr_id], 40 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_text[thr_id], 32 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_a[thr_id], 4 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_b[thr_id], 4 * sizeof(uint32_t) * throughput);
exit_if_cudaerror(thr_id, __FUNCTION__, __LINE__);
cudaMalloc(&d_ctx_tweak[thr_id], sizeof(uint64_t) * throughput);
exit_if_cudaerror(thr_id, __FILE__, __LINE__);
gpu_init_shown = true;
init[thr_id] = true;
}
throughput = cn_blocks*cn_threads;
do
{
const uint32_t Htarg = ptarget[7];
uint32_t resNonces[2] = { UINT32_MAX, UINT32_MAX };
cryptonight_extra_setData(thr_id, pdata, ptarget);
cryptonight_extra_prepare(thr_id, throughput, nonce, d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
cryptonight_core_cuda(thr_id, cn_blocks, cn_threads, d_long_state[thr_id], d_ctx_state[thr_id], d_ctx_a[thr_id], d_ctx_b[thr_id], d_ctx_key1[thr_id], d_ctx_key2[thr_id], variant, d_ctx_tweak[thr_id]);
cryptonight_extra_final(thr_id, throughput, nonce, resNonces, d_ctx_state[thr_id]);
*hashes_done = nonce - first_nonce + throughput;
if(resNonces[0] != UINT32_MAX)
{
uint32_t vhash[8];
uint32_t tempdata[19];
uint32_t *tempnonceptr = (uint32_t*)(((char*)tempdata) + 39);
memcpy(tempdata, pdata, 76);
*tempnonceptr = resNonces[0];
cryptonight_hash_variant(vhash, tempdata, 76, variant);
if(vhash[7] <= Htarg && fulltest(vhash, ptarget))
{
res = 1;
work->nonces[0] = resNonces[0];
work_set_target_ratio(work, vhash);
// second nonce
if(resNonces[1] != UINT32_MAX)
{
*tempnonceptr = resNonces[1];
cryptonight_hash_variant(vhash, tempdata, 76, variant);
if(vhash[7] <= Htarg && fulltest(vhash, ptarget)) {
res++;
work->nonces[1] = resNonces[1];
} else {
gpu_increment_reject(thr_id);
}
}
goto done;
} else if (vhash[7] > Htarg) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", resNonces[0]);
}
}
if ((uint64_t) throughput + nonce >= max_nonce - 127) {
nonce = max_nonce;
break;
}
nonce += throughput;
gpulog(LOG_DEBUG, thr_id, "nonce %08x", nonce);
} while (!work_restart[thr_id].restart && max_nonce > (uint64_t)throughput + nonce);
done:
gpulog(LOG_DEBUG, thr_id, "nonce %08x exit", nonce);
work->valid_nonces = res;
*nonceptr = nonce;
return res;
}
void free_cryptonight(int thr_id)
{
if (!init[thr_id])
return;
cudaFree(d_long_state[thr_id]);
cudaFree(d_ctx_state[thr_id]);
cudaFree(d_ctx_key1[thr_id]);
cudaFree(d_ctx_key2[thr_id]);
cudaFree(d_ctx_text[thr_id]);
cudaFree(d_ctx_tweak[thr_id]);
cudaFree(d_ctx_a[thr_id]);
cudaFree(d_ctx_b[thr_id]);
cryptonight_extra_free(thr_id);
cudaDeviceSynchronize();
init[thr_id] = false;
}
+144
View File
@@ -0,0 +1,144 @@
#pragma once
#include <cuda_runtime.h>
#include <miner.h>
#ifdef __INTELLISENSE__
/* avoid red underlining */
#define __CUDA_ARCH__ 520
struct uint3 {
unsigned int x, y, z;
};
struct uint3 threadIdx;
struct uint3 blockIdx;
struct uint3 blockDim;
#define atomicExch(p,y) (*p) = y
#define __funnelshift_r(a,b,c) 1
#define __syncthreads()
#define __threadfence_block()
#define asm(x)
#define __shfl(a,b,c) 1
#define __umul64hi(a,b) a*b
#endif
#define MEMORY (1U << 21) // 2 MiB / 2097152 B
#define ITER (1U << 20) // 1048576
#define E2I_MASK 0x1FFFF0u
#define AES_BLOCK_SIZE 16U
#define AES_KEY_SIZE 32
#define INIT_SIZE_BLK 8
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B
#define AES_RKEY_LEN 4
#define AES_COL_LEN 4
#define AES_ROUND_BASE 7
#ifndef HASH_SIZE
#define HASH_SIZE 32
#endif
#ifndef HASH_DATA_AREA
#define HASH_DATA_AREA 136
#endif
#define hi_dword(x) (x >> 32)
#define lo_dword(x) (x & 0xFFFFFFFF)
#define C32(x) ((uint32_t)(x ## U))
#define T32(x) ((x) & C32(0xFFFFFFFF))
#ifndef ROTL64
#if __CUDA_ARCH__ >= 350
__forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset) {
uint2 result;
if(offset >= 32) {
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
} else {
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
}
return __double_as_longlong(__hiloint2double(result.y, result.x));
}
#define ROTL64(x, n) (cuda_ROTL64(x, n))
#else
#define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
#endif
#endif
#ifndef ROTL32
#if __CUDA_ARCH__ < 350
#define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n))))
#else
#define ROTL32(x, n) __funnelshift_l( (x), (x), (n) )
#endif
#endif
#ifndef ROTR32
#if __CUDA_ARCH__ < 350
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#else
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
#endif
#endif
#define MEMSET8(dst,what,cnt) { \
int i_memset8; \
uint64_t *out_memset8 = (uint64_t *)(dst); \
for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \
out_memset8[i_memset8] = (what); }
#define MEMSET4(dst,what,cnt) { \
int i_memset4; \
uint32_t *out_memset4 = (uint32_t *)(dst); \
for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \
out_memset4[i_memset4] = (what); }
#define MEMCPY8(dst,src,cnt) { \
int i_memcpy8; \
uint64_t *in_memcpy8 = (uint64_t *)(src); \
uint64_t *out_memcpy8 = (uint64_t *)(dst); \
for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \
out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; }
#define MEMCPY4(dst,src,cnt) { \
int i_memcpy4; \
uint32_t *in_memcpy4 = (uint32_t *)(src); \
uint32_t *out_memcpy4 = (uint32_t *)(dst); \
for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \
out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; }
#define XOR_BLOCKS_DST(x,y,z) { \
((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \
((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; }
#define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff)))
union hash_state {
uint8_t b[200];
uint64_t w[25];
};
union cn_slow_hash_state {
union hash_state hs;
struct {
uint8_t k[64];
uint8_t init[INIT_SIZE_BYTE];
};
};
static inline void exit_if_cudaerror(int thr_id, const char *src, int line)
{
cudaError_t err = cudaGetLastError();
if(err != cudaSuccess) {
gpulog(LOG_ERR, thr_id, "%s %s line %d", cudaGetErrorString(err), src, line);
exit(1);
}
}
void cryptonight_core_cuda(int thr_id, uint32_t blocks, uint32_t threads, uint64_t *d_long_state, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
void cryptonight_extra_setData(int thr_id, const void *data, const void *ptarget);
void cryptonight_extra_init(int thr_id);
void cryptonight_extra_free(int thr_id);
void cryptonight_extra_prepare(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_ctx_state, uint32_t *d_ctx_a, uint32_t *d_ctx_b, uint32_t *d_ctx_key1, uint32_t *d_ctx_key2, int variant, uint64_t *d_ctx_tweak);
void cryptonight_extra_final(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *resnonce, uint32_t *d_ctx_state);
+573
View File
@@ -0,0 +1,573 @@
#ifndef UINT128_C_H
#define UINT128_C_H
struct __uint128 {
uint64_t Hi;
uint64_t Lo;
};
typedef struct __uint128 uint128;
void Increment(uint128 * N)
{
uint64_t T = (N->Lo + 1);
N->Hi += ((N->Lo ^T) & N->Lo) >> 63;
N->Lo = T;
}
void Decrement(uint128 * N)
{
uint64_t T = (N->Lo - 1);
N->Hi -= ((T ^ N->Lo) & T) >> 63;
N->Lo = T;
}
void Add(uint128 * Ans, uint128 N, uint128 M)
{
uint64_t C = (((N.Lo & M.Lo) & 1) + (N.Lo >> 1) + (M.Lo >> 1)) >> 63;
Ans->Hi = N.Hi + M.Hi + C;
Ans->Lo = N.Lo + M.Lo;
}
void Subtract(uint128 * Ans, uint128 N, uint128 M)
{
Ans->Lo = N.Lo - M.Lo;
uint64_t C = (((Ans->Lo & M.Lo) & 1) + (M.Lo >> 1) + (Ans->Lo >> 1)) >> 63;
Ans->Hi = N.Hi - (M.Hi + C);
}
void inc128(uint128 N, uint128* A)
{
A->Lo = (N.Lo + 1);
A->Hi = N.Hi + (((N.Lo ^ A->Lo) & N.Lo) >> 63);
}
void dec128(uint128 N, uint128* A)
{
A->Lo = N.Lo - 1;
A->Hi = N.Hi - (((A->Lo ^ N.Lo) & A->Lo) >> 63);
}
void add128(uint128 N, uint128 M, uint128* A)
{
uint64_t C = (((N.Lo & M.Lo) & 1) + (N.Lo >> 1) + (M.Lo >> 1)) >> 63;
A->Hi = N.Hi + M.Hi + C;
A->Lo = N.Lo + M.Lo;
}
void sub128(uint128 N, uint128 M, uint128* A)
{
A->Lo = N.Lo - M.Lo;
uint64_t C = (((A->Lo & M.Lo) & 1) + (M.Lo >> 1) + (A->Lo >> 1)) >> 63;
A->Hi = N.Hi - (M.Hi + C);
}
void mult64to128(uint64_t u, uint64_t v, uint64_t * h, uint64_t *l)
{
uint64_t u1 = (u & 0xffffffff);
uint64_t v1 = (v & 0xffffffff);
uint64_t t = (u1 * v1);
uint64_t w3 = (t & 0xffffffff);
uint64_t k = (t >> 32);
u >>= 32;
t = (u * v1) + k;
k = (t & 0xffffffff);
uint64_t w1 = (t >> 32);
v >>= 32;
t = (u1 * v) + k;
k = (t >> 32);
*h = (u * v) + w1 + k;
*l = (t << 32) + w3;
}
void mult128(uint128 N, uint128 M, uint128 * Ans)
{
mult64to128(N.Lo, M.Lo, &Ans->Hi, &Ans->Lo);
Ans->Hi += (N.Hi * M.Lo) + (N.Lo * M.Hi);
}
void mult128to256(uint128 N, uint128 M, uint128 * H, uint128 * L)
{
mult64to128(N.Hi, M.Hi, &H->Hi, &H->Lo);
mult64to128(N.Lo, M.Lo, &L->Hi, &L->Lo);
uint128 T;
mult64to128(N.Hi, M.Lo, &T.Hi, &T.Lo);
L->Hi += T.Lo;
if(L->Hi < T.Lo) // if L->Hi overflowed
{
Increment(H);
}
H->Lo += T.Hi;
if(H->Lo < T.Hi) // if H->Lo overflowed
{
++H->Hi;
}
mult64to128(N.Lo, M.Hi, &T.Hi, &T.Lo);
L->Hi += T.Lo;
if(L->Hi < T.Lo) // if L->Hi overflowed
{
Increment(H);
}
H->Lo += T.Hi;
if(H->Lo < T.Hi) // if H->Lo overflowed
{
++H->Hi;
}
}
void sqr64to128(uint64_t r, uint64_t * h, uint64_t *l)
{
uint64_t r1 = (r & 0xffffffff);
uint64_t t = (r1 * r1);
uint64_t w3 = (t & 0xffffffff);
uint64_t k = (t >> 32);
r >>= 32;
uint64_t m = (r * r1);
t = m + k;
uint64_t w2 = (t & 0xffffffff);
uint64_t w1 = (t >> 32);
t = m + w2;
k = (t >> 32);
*h = (r * r) + w1 + k;
*l = (t << 32) + w3;
}
void sqr128(uint128 R, uint128 * Ans)
{
sqr64to128(R.Lo, &Ans->Hi, &Ans->Lo);
Ans->Hi += (R.Hi * R.Lo) << 1;
}
void sqr128to256(uint128 R, uint128 * H, uint128 * L)
{
sqr64to128(R.Hi, &H->Hi, &H->Lo);
sqr64to128(R.Lo, &L->Hi, &L->Lo);
uint128 T;
mult64to128(R.Hi, R.Lo, &T.Hi, &T.Lo);
H->Hi += (T.Hi >> 63);
T.Hi = (T.Hi << 1) | (T.Lo >> 63); // Shift Left 1 bit
T.Lo <<= 1;
L->Hi += T.Lo;
if(L->Hi < T.Lo) // if L->Hi overflowed
{
Increment(H);
}
H->Lo += T.Hi;
if(H->Lo < T.Hi) // if H->Lo overflowed
{
++H->Hi;
}
}
void shiftleft128(uint128 N, size_t S, uint128 * A)
{
uint64_t M1, M2;
S &= 127;
M1 = ((((S + 127) | S) & 64) >> 6) - 1llu;
M2 = (S >> 6) - 1llu;
S &= 63;
A->Hi = (N.Lo << S) & (~M2);
A->Lo = (N.Lo << S) & M2;
A->Hi |= ((N.Hi << S) | ((N.Lo >> (64 - S)) & M1)) & M2;
/*
S &= 127;
if(S != 0)
{
if(S > 64)
{
A.Hi = N.Lo << (S - 64);
A.Lo = 0;
}
else if(S < 64)
{
A.Hi = (N.Hi << S) | (N.Lo >> (64 - S));
A.Lo = N.Lo << S;
}
else
{
A.Hi = N.Lo;
A.Lo = 0;
}
}
else
{
A.Hi = N.Hi;
A.Lo = N.Lo;
}
//*/
}
void shiftright128(uint128 N, size_t S, uint128 * A)
{
uint64_t M1, M2;
S &= 127;
M1 = ((((S + 127) | S) & 64) >> 6) - 1llu;
M2 = (S >> 6) - 1llu;
S &= 63;
A->Lo = (N.Hi >> S) & (~M2);
A->Hi = (N.Hi >> S) & M2;
A->Lo |= ((N.Lo >> S) | ((N.Hi << (64 - S)) & M1)) & M2;
/*
S &= 127;
if(S != 0)
{
if(S > 64)
{
A.Hi = N.Hi >> (S - 64);
A.Lo = 0;
}
else if(S < 64)
{
A.Lo = (N.Lo >> S) | (N.Hi << (64 - S));
A.Hi = N.Hi >> S;
}
else
{
A.Lo = N.Hi;
A.Hi = 0;
}
}
else
{
A.Hi = N.Hi;
A.Lo = N.Lo;
}
//*/
}
void not128(uint128 N, uint128 * A)
{
A->Hi = ~N.Hi;
A->Lo = ~N.Lo;
}
void or128(uint128 N1, uint128 N2, uint128 * A)
{
A->Hi = N1.Hi | N2.Hi;
A->Lo = N1.Lo | N2.Lo;
}
void and128(uint128 N1, uint128 N2, uint128 * A)
{
A->Hi = N1.Hi & N2.Hi;
A->Lo = N1.Lo & N2.Lo;
}
void xor128(uint128 N1, uint128 N2, uint128 * A)
{
A->Hi = N1.Hi ^ N2.Hi;
A->Lo = N1.Lo ^ N2.Lo;
}
size_t nlz64(uint64_t N)
{
uint64_t I;
size_t C;
I = ~N;
C = ((I ^ (I + 1)) & I) >> 63;
I = (N >> 32) + 0xffffffff;
I = ((I & 0x100000000) ^ 0x100000000) >> 27;
C += I; N <<= I;
I = (N >> 48) + 0xffff;
I = ((I & 0x10000) ^ 0x10000) >> 12;
C += I; N <<= I;
I = (N >> 56) + 0xff;
I = ((I & 0x100) ^ 0x100) >> 5;
C += I; N <<= I;
I = (N >> 60) + 0xf;
I = ((I & 0x10) ^ 0x10) >> 2;
C += I; N <<= I;
I = (N >> 62) + 3;
I = ((I & 4) ^ 4) >> 1;
C += I; N <<= I;
C += (N >> 63) ^ 1;
return C;
}
size_t ntz64(uint64_t N)
{
uint64_t I = ~N;
size_t C = ((I ^ (I + 1)) & I) >> 63;
I = (N & 0xffffffff) + 0xffffffff;
I = ((I & 0x100000000) ^ 0x100000000) >> 27;
C += I; N >>= I;
I = (N & 0xffff) + 0xffff;
I = ((I & 0x10000) ^ 0x10000) >> 12;
C += I; N >>= I;
I = (N & 0xff) + 0xff;
I = ((I & 0x100) ^ 0x100) >> 5;
C += I; N >>= I;
I = (N & 0xf) + 0xf;
I = ((I & 0x10) ^ 0x10) >> 2;
C += I; N >>= I;
I = (N & 3) + 3;
I = ((I & 4) ^ 4) >> 1;
C += I; N >>= I;
C += ((N & 1) ^ 1);
return C;
}
size_t popcnt64(uint64_t V)
{
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
V -= ((V >> 1) & 0x5555555555555555);
V = (V & 0x3333333333333333) + ((V >> 2) & 0x3333333333333333);
return ((V + (V >> 4) & 0xF0F0F0F0F0F0F0F) * 0x101010101010101) >> 56;
}
size_t popcnt128(uint128 N)
{
return popcnt64(N.Hi) + popcnt64(N.Lo);
}
size_t nlz128(uint128 N)
{
return (N.Hi == 0) ? nlz64(N.Lo) + 64 : nlz64(N.Hi);
}
size_t ntz128(uint128 N)
{
return (N.Lo == 0) ? ntz64(N.Hi) + 64 : ntz64(N.Lo);
}
int compare128(uint128 N1, uint128 N2)
{
return (((N1.Hi > N2.Hi) || ((N1.Hi == N2.Hi) && (N1.Lo > N2.Lo))) ? 1 : 0)
- (((N1.Hi < N2.Hi) || ((N1.Hi == N2.Hi) && (N1.Lo < N2.Lo))) ? 1 : 0);
}
void bindivmod128(uint128 M, uint128 N, uint128 * Q, uint128 *R)
{
Q->Hi = Q->Lo = 0;
size_t Shift = nlz128(N) - nlz128(M);
shiftleft128(N, Shift, &N);
do
{
shiftleft128(*Q, (size_t)1, Q);
if(compare128(M, N) >= 0)
{
sub128(M, N, &M);
Q->Lo |= 1;
}
shiftright128(N, 1, &N);
}while(Shift-- != 0);
R->Hi = M.Hi;
R->Lo = M.Lo;
}
void divmod128by64(const uint64_t u1, const uint64_t u0, uint64_t v, uint64_t * q, uint64_t * r)
{
const uint64_t b = 1ll << 32;
uint64_t un1, un0, vn1, vn0, q1, q0, un32, un21, un10, rhat, left, right;
size_t s;
s = nlz64(v);
v <<= s;
vn1 = v >> 32;
vn0 = v & 0xffffffff;
if (s > 0)
{
un32 = (u1 << s) | (u0 >> (64 - s));
un10 = u0 << s;
}
else
{
un32 = u1;
un10 = u0;
}
un1 = un10 >> 32;
un0 = un10 & 0xffffffff;
q1 = un32 / vn1;
rhat = un32 % vn1;
left = q1 * vn0;
right = (rhat << 32) + un1;
again1:
if ((q1 >= b) || (left > right))
{
--q1;
rhat += vn1;
if (rhat < b)
{
left -= vn0;
right = (rhat << 32) | un1;
goto again1;
}
}
un21 = (un32 << 32) + (un1 - (q1 * v));
q0 = un21 / vn1;
rhat = un21 % vn1;
left = q0 * vn0;
right = (rhat << 32) | un0;
again2:
if ((q0 >= b) || (left > right))
{
--q0;
rhat += vn1;
if (rhat < b)
{
left -= vn0;
right = (rhat << 32) | un0;
goto again2;
}
}
*r = ((un21 << 32) + (un0 - (q0 * v))) >> s;
*q = (q1 << 32) | q0;
}
static void divmod128by128(uint128 M, uint128 N, uint128 * Q, uint128 * R)
{
if (N.Hi == 0)
{
if (M.Hi < N.Lo)
{
divmod128by64(M.Hi, M.Lo, N.Lo, &Q->Lo, &R->Lo);
Q->Hi = 0;
R->Hi = 0;
return;
}
else
{
Q->Hi = M.Hi / N.Lo;
R->Hi = M.Hi % N.Lo;
divmod128by64(R->Hi, M.Lo, N.Lo, &Q->Lo, &R->Lo);
R->Hi = 0;
return;
}
}
else
{
size_t n = nlz64(N.Hi);
uint128 v1;
shiftleft128(N, n, &v1);
uint128 u1;
shiftright128(M, 1, &u1);
uint128 q1;
divmod128by64(u1.Hi, u1.Lo, v1.Hi, &q1.Hi, &q1.Lo);
q1.Hi = 0;
shiftright128(q1, 63 - n, &q1);
if ((q1.Hi | q1.Lo) != 0)
{
dec128(q1, &q1);
}
Q->Hi = q1.Hi;
Q->Lo = q1.Lo;
mult128(q1, N, &q1);
sub128(M, q1, R);
if (compare128(*R, N) >= 0)
{
inc128(*Q, Q);
sub128(*R, N, R);
}
return;
}
}
void divmod128(uint128 M, uint128 N, uint128 * Q, uint128 * R)
{
size_t Nlz, Mlz, Ntz;
int C;
Nlz = nlz128(N);
Mlz = nlz128(M);
Ntz = ntz128(N);
if(Nlz == 128)
{
return;
}
else if((M.Hi | N.Hi) == 0)
{
Q->Hi = R->Hi = 0;
Q->Lo = M.Lo / N.Lo;
R->Lo = M.Lo % N.Lo;
return;
}
else if(Nlz == 127)
{
*Q = M;
R->Hi = R->Lo = 0;
return;
}
else if((Ntz + Nlz) == 127)
{
shiftright128(M, Ntz, Q);
dec128(N, &N);
and128(N, M, R);
return;
}
C = compare128(M, N);
if(C < 0)
{
Q->Hi = Q->Lo = 0;
*R = M;
return;
}
else if(C == 0)
{
Q->Hi = R->Hi = R->Lo = 0;
Q->Lo = 1;
return;
}
if((Nlz - Mlz) > 5)
{
divmod128by128(M, N, Q, R);
}
else
{
bindivmod128(M, N, Q, R);
}
}
#endif
+180
View File
@@ -0,0 +1,180 @@
#include <windows.h>
#include <errno.h>
#include <io.h>
#include "mman.h"
#ifndef FILE_MAP_EXECUTE
#define FILE_MAP_EXECUTE 0x0020
#endif /* FILE_MAP_EXECUTE */
static int __map_mman_error(const DWORD err, const int deferr)
{
if (err == 0)
return 0;
//TODO: implement
return err;
}
static DWORD __map_mmap_prot_page(const int prot)
{
DWORD protect = 0;
if (prot == PROT_NONE)
return protect;
if ((prot & PROT_EXEC) != 0)
{
protect = ((prot & PROT_WRITE) != 0) ?
PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;
}
else
{
protect = ((prot & PROT_WRITE) != 0) ?
PAGE_READWRITE : PAGE_READONLY;
}
return protect;
}
static DWORD __map_mmap_prot_file(const int prot)
{
DWORD desiredAccess = 0;
if (prot == PROT_NONE)
return desiredAccess;
if ((prot & PROT_READ) != 0)
desiredAccess |= FILE_MAP_READ;
if ((prot & PROT_WRITE) != 0)
desiredAccess |= FILE_MAP_WRITE;
if ((prot & PROT_EXEC) != 0)
desiredAccess |= FILE_MAP_EXECUTE;
return desiredAccess;
}
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off)
{
HANDLE fm, h;
void * map = MAP_FAILED;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4293)
#endif
const DWORD dwFileOffsetLow = (sizeof(OffsetType) <= sizeof(DWORD)) ?
(DWORD)off : (DWORD)(off & 0xFFFFFFFFL);
const DWORD dwFileOffsetHigh = (sizeof(OffsetType) <= sizeof(DWORD)) ?
(DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL);
const DWORD protect = __map_mmap_prot_page(prot);
const DWORD desiredAccess = __map_mmap_prot_file(prot);
const OffsetType maxSize = off + (OffsetType)len;
const DWORD dwMaxSizeLow = (sizeof(OffsetType) <= sizeof(DWORD)) ?
(DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL);
const DWORD dwMaxSizeHigh = (sizeof(OffsetType) <= sizeof(DWORD)) ?
(DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
errno = 0;
if (len == 0
/* Unsupported flag combinations */
|| (flags & MAP_FIXED) != 0
/* Usupported protection combinations */
|| prot == PROT_EXEC)
{
errno = EINVAL;
return MAP_FAILED;
}
h = ((flags & MAP_ANONYMOUS) == 0) ?
(HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE;
if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return MAP_FAILED;
}
fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL);
if (fm == NULL)
{
errno = __map_mman_error(GetLastError(), EPERM);
return MAP_FAILED;
}
map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len);
CloseHandle(fm);
if (map == NULL)
{
errno = __map_mman_error(GetLastError(), EPERM);
return MAP_FAILED;
}
return map;
}
int munmap(void *addr, size_t len)
{
if (UnmapViewOfFile(addr))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
int _mprotect(void *addr, size_t len, int prot)
{
DWORD newProtect = __map_mmap_prot_page(prot);
DWORD oldProtect = 0;
if (VirtualProtect(addr, len, newProtect, &oldProtect))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
int msync(void *addr, size_t len, int flags)
{
if (FlushViewOfFile(addr, len))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
int mlock(const void *addr, size_t len)
{
if (VirtualLock((LPVOID)addr, len))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
int munlock(const void *addr, size_t len)
{
if (VirtualUnlock((LPVOID)addr, len))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
+63
View File
@@ -0,0 +1,63 @@
/*
* sys/mman.h
* mman-win32
*/
#ifndef _SYS_MMAN_H_
#define _SYS_MMAN_H_
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
/* All the headers include this file. */
#ifndef _MSC_VER
#include <_mingw.h>
#endif
/* Determine offset type */
#include <stdint.h>
#if defined(_WIN64)
typedef int64_t OffsetType;
#else
typedef uint32_t OffsetType;
#endif
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PROT_NONE 0
#define PROT_READ 1
#define PROT_WRITE 2
#define PROT_EXEC 4
#define MAP_FILE 0
#define MAP_SHARED 1
#define MAP_PRIVATE 2
#define MAP_TYPE 0xf
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void *)-1)
/* Flags for msync. */
#define MS_ASYNC 1
#define MS_SYNC 2
#define MS_INVALIDATE 4
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off);
int munmap(void *addr, size_t len);
int _mprotect(void *addr, size_t len, int prot);
int msync(void *addr, size_t len, int flags);
int mlock(const void *addr, size_t len);
int munlock(const void *addr, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MMAN_H_ */
+51
View File
@@ -0,0 +1,51 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ---------------------------------------------------------------------------
*/
#ifndef _OAES_CONFIG_H
#define _OAES_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
//#ifndef OAES_HAVE_ISAAC
//#define OAES_HAVE_ISAAC 1
//#endif // OAES_HAVE_ISAAC
//#ifndef OAES_DEBUG
//#define OAES_DEBUG 0
//#endif // OAES_DEBUG
//#define OAES_DEBUG 1
#ifdef __cplusplus
}
#endif
#endif // _OAES_CONFIG_H
+1447
View File
File diff suppressed because it is too large. Load diff
+214
View File
@@ -0,0 +1,214 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ---------------------------------------------------------------------------
*/
#ifndef _OAES_LIB_H
#define _OAES_LIB_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# ifdef OAES_SHARED
# ifdef oaes_lib_EXPORTS
# define OAES_API __declspec(dllexport)
# else
# define OAES_API __declspec(dllimport)
# endif
# else
# define OAES_API
# endif
#else
# define OAES_API
#endif // WIN32
#define OAES_VERSION "0.8.1"
#define OAES_BLOCK_SIZE 16
typedef void OAES_CTX;
typedef enum
{
OAES_RET_FIRST = 0,
OAES_RET_SUCCESS = 0,
OAES_RET_UNKNOWN,
OAES_RET_ARG1,
OAES_RET_ARG2,
OAES_RET_ARG3,
OAES_RET_ARG4,
OAES_RET_ARG5,
OAES_RET_NOKEY,
OAES_RET_MEM,
OAES_RET_BUF,
OAES_RET_HEADER,
OAES_RET_COUNT
} OAES_RET;
/*
* oaes_set_option() takes one of these values for its [option] parameter
* some options accept either an optional or a required [value] parameter
*/
// no option
#define OAES_OPTION_NONE 0
// enable ECB mode, disable CBC mode
#define OAES_OPTION_ECB 1
// enable CBC mode, disable ECB mode
// value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify
// the value of the initialization vector, iv
#define OAES_OPTION_CBC 2
#ifdef OAES_DEBUG
typedef int ( * oaes_step_cb ) (
const uint8_t state[OAES_BLOCK_SIZE],
const char * step_name,
int step_count,
void * user_data );
// enable state stepping mode
// value is required, must pass oaes_step_cb to receive the state at each step
#define OAES_OPTION_STEP_ON 4
// disable state stepping mode
#define OAES_OPTION_STEP_OFF 8
#endif // OAES_DEBUG
typedef uint16_t OAES_OPTION;
typedef struct _oaes_key
{
size_t data_len;
uint8_t *data;
size_t exp_data_len;
uint8_t *exp_data;
size_t num_keys;
size_t key_base;
} oaes_key;
typedef struct _oaes_ctx
{
#ifdef OAES_HAVE_ISAAC
randctx * rctx;
#endif // OAES_HAVE_ISAAC
#ifdef OAES_DEBUG
oaes_step_cb step_cb;
#endif // OAES_DEBUG
oaes_key * key;
OAES_OPTION options;
uint8_t iv[OAES_BLOCK_SIZE];
} oaes_ctx;
/*
* // usage:
*
* OAES_CTX * ctx = oaes_alloc();
* .
* .
* .
* {
* oaes_gen_key_xxx( ctx );
* {
* oaes_key_export( ctx, _buf, &_buf_len );
* // or
* oaes_key_export_data( ctx, _buf, &_buf_len );\
* }
* }
* // or
* {
* oaes_key_import( ctx, _buf, _buf_len );
* // or
* oaes_key_import_data( ctx, _buf, _buf_len );
* }
* .
* .
* .
* oaes_encrypt( ctx, m, m_len, c, &c_len );
* .
* .
* .
* oaes_decrypt( ctx, c, c_len, m, &m_len );
* .
* .
* .
* oaes_free( &ctx );
*/
OAES_API OAES_CTX * oaes_alloc(void);
OAES_API OAES_RET oaes_free( OAES_CTX ** ctx );
OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx,
OAES_OPTION option, const void * value );
OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx );
OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx );
OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx );
// export key with header information
// set data == NULL to get the required data_len
OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx,
uint8_t * data, size_t * data_len );
// directly export the data from key
// set data == NULL to get the required data_len
OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx,
uint8_t * data, size_t * data_len );
// import key with header information
OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx,
const uint8_t * data, size_t data_len );
// directly import data into key
OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx,
const uint8_t * data, size_t data_len );
// set c == NULL to get the required c_len
OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx,
const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len );
// set m == NULL to get the required m_len
OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx,
const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len );
// set buf == NULL to get the required buf_len
OAES_API OAES_RET oaes_sprintf(
char * buf, size_t * buf_len, const uint8_t * data, size_t data_len );
OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c );
OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c );
#ifdef __cplusplus
}
#endif
#endif // _OAES_LIB_H
+376
View File
@@ -0,0 +1,376 @@
// Memory-hard extension of keccak for PoW
// Copyright (c) 2012-2013 The Cryptonote developers
// Copyright (c) 2014 The Boolberry developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Modified for CPUminer by Lucas Jones
// Adapted for ccminer by Tanguy Pruvot - 2016
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <emmintrin.h>
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include "compat/bignum_ssl10.hpp"
#else
#include "bignum.hpp"
#endif
#include "int128_c.h"
#else
#include <x86intrin.h>
#endif
#include <miner.h>
#include "xmr-rpc.h"
extern uint64_t* pscratchpad_buff;
struct reciprocal_value64 {
uint64_t m;
uint8_t sh1, sh2;
};
static inline int fls64(uint64_t x)
{
#if defined(_WIN64)
unsigned long bitpos = 0;
_BitScanReverse64(&bitpos, x);
return (int) (bitpos + 1);
#elif defined(WIN32)
unsigned long hipos = 0, bitpos = 0;
uint32_t hi = x >> 32;
_BitScanReverse(&hipos, hi);
if (!hipos) {
_BitScanReverse(&bitpos, (uint32_t) x);
}
return (int) hipos ? hipos + 33 : bitpos + 1;
#else
/*
* AMD64 says BSRQ won't clobber the dest reg if x==0; Intel64 says the
* dest reg is undefined if x==0, but their CPU architect says its
* value is written to set it to the same as before.
*/
register long bitpos = -1;
asm("bsrq %1,%0" : "+r" (bitpos) : "rm" (x));
return bitpos + 1;
#endif
}
static inline struct reciprocal_value64 reciprocal_val64(uint64_t d)
{
struct reciprocal_value64 R;
int l;
l = fls64(d - 1);
#ifdef _MSC_VER
uint128 v1;
v1.Lo = (1ULL << l) - d;v1.Hi=0;
uint128 v2;
v2.Hi = 1; v2.Lo = 0;
uint128 v;
mult128(v1,v2,&v);
divmod128by64(v.Hi,v.Lo,d,&v.Hi,&v.Lo);
Increment(&v);
R.m = (uint64_t)v.Hi;
#else
__uint128_t m;
m = (((__uint128_t)1 << 64) * ((1ULL << l) - d));
m /= d;
++m;
R.m = (uint64_t)m;
#endif
R.sh1 = min(l, 1);
R.sh2 = max(l - 1, 0);
return R;
}
static inline uint64_t reciprocal_divide64(uint64_t a, struct reciprocal_value64 R)
{
#ifdef _MSC_VER
uint128 v;
mult64to128(a,R.m,&v.Hi,&v.Lo);
uint64_t t = v.Hi;
#else
uint64_t t = (uint64_t)(((__uint128_t)a * R.m) >> 64);
#endif
return (t + ((a - t) >> R.sh1)) >> R.sh2;
}
static inline uint64_t reciprocal_remainder64(uint64_t A, uint64_t B, struct reciprocal_value64 R)
{
uint64_t div, mod;
div = reciprocal_divide64(A, R);
mod = A - (uint64_t) (div * B);
if (mod >= B) mod -= B;
return mod;
}
//#define UNROLL_SCR_MIX
static inline uint64_t rotl641(uint64_t x) { return((x << 1) | (x >> 63)); }
static inline uint64_t rotl64_1(uint64_t x, uint64_t y) { return((x << y) | (x >> (64 - y))); }
static inline uint64_t rotl64_2(uint64_t x, uint64_t y) { return(rotl64_1((x >> 32) | (x << 32), y)); }
static inline uint64_t bitselect(uint64_t a, uint64_t b, uint64_t c) { return(a ^ (c & (b ^ a))); }
static inline void keccakf_mul(uint64_t *s)
{
uint64_t bc[5], t[5];
uint64_t tmp1, tmp2;
int i;
for(i = 0; i < 5; i++)
t[i] = s[i + 0] ^ s[i + 5] ^ s[i + 10] * s[i + 15] * s[i + 20];
bc[0] = t[0] ^ rotl641(t[2]);
bc[1] = t[1] ^ rotl641(t[3]);
bc[2] = t[2] ^ rotl641(t[4]);
bc[3] = t[3] ^ rotl641(t[0]);
bc[4] = t[4] ^ rotl641(t[1]);
tmp1 = s[1] ^ bc[0];
s[ 0] ^= bc[4];
s[ 1] = rotl64_1(s[ 6] ^ bc[0], 44);
s[ 6] = rotl64_1(s[ 9] ^ bc[3], 20);
s[ 9] = rotl64_1(s[22] ^ bc[1], 61);
s[22] = rotl64_1(s[14] ^ bc[3], 39);
s[14] = rotl64_1(s[20] ^ bc[4], 18);
s[20] = rotl64_1(s[ 2] ^ bc[1], 62);
s[ 2] = rotl64_1(s[12] ^ bc[1], 43);
s[12] = rotl64_1(s[13] ^ bc[2], 25);
s[13] = rotl64_1(s[19] ^ bc[3], 8);
s[19] = rotl64_1(s[23] ^ bc[2], 56);
s[23] = rotl64_1(s[15] ^ bc[4], 41);
s[15] = rotl64_1(s[ 4] ^ bc[3], 27);
s[ 4] = rotl64_1(s[24] ^ bc[3], 14);
s[24] = rotl64_1(s[21] ^ bc[0], 2);
s[21] = rotl64_1(s[ 8] ^ bc[2], 55);
s[ 8] = rotl64_1(s[16] ^ bc[0], 45);
s[16] = rotl64_1(s[ 5] ^ bc[4], 36);
s[ 5] = rotl64_1(s[ 3] ^ bc[2], 28);
s[ 3] = rotl64_1(s[18] ^ bc[2], 21);
s[18] = rotl64_1(s[17] ^ bc[1], 15);
s[17] = rotl64_1(s[11] ^ bc[0], 10);
s[11] = rotl64_1(s[ 7] ^ bc[1], 6);
s[ 7] = rotl64_1(s[10] ^ bc[4], 3);
s[10] = rotl64_1(tmp1, 1);
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]); s[4] = bitselect(s[4] ^ tmp2, s[4], tmp1);
tmp1 = s[5]; tmp2 = s[6]; s[5] = bitselect(s[5] ^ s[7], s[5], s[6]); s[6] = bitselect(s[6] ^ s[8], s[6], s[7]); s[7] = bitselect(s[7] ^ s[9], s[7], s[8]); s[8] = bitselect(s[8] ^ tmp1, s[8], s[9]); s[9] = bitselect(s[9] ^ tmp2, s[9], tmp1);
tmp1 = s[10]; tmp2 = s[11]; s[10] = bitselect(s[10] ^ s[12], s[10], s[11]); s[11] = bitselect(s[11] ^ s[13], s[11], s[12]); s[12] = bitselect(s[12] ^ s[14], s[12], s[13]); s[13] = bitselect(s[13] ^ tmp1, s[13], s[14]); s[14] = bitselect(s[14] ^ tmp2, s[14], tmp1);
tmp1 = s[15]; tmp2 = s[16]; s[15] = bitselect(s[15] ^ s[17], s[15], s[16]); s[16] = bitselect(s[16] ^ s[18], s[16], s[17]); s[17] = bitselect(s[17] ^ s[19], s[17], s[18]); s[18] = bitselect(s[18] ^ tmp1, s[18], s[19]); s[19] = bitselect(s[19] ^ tmp2, s[19], tmp1);
tmp1 = s[20]; tmp2 = s[21]; s[20] = bitselect(s[20] ^ s[22], s[20], s[21]); s[21] = bitselect(s[21] ^ s[23], s[21], s[22]); s[22] = bitselect(s[22] ^ s[24], s[22], s[23]); s[23] = bitselect(s[23] ^ tmp1, s[23], s[24]); s[24] = bitselect(s[24] ^ tmp2, s[24], tmp1);
s[0] ^= 0x0000000000000001ULL;
}
static inline void keccakf_mul_last(uint64_t *s)
{
uint64_t bc[5], xormul[5];
uint64_t tmp1, tmp2;
int i;
for(i = 0; i < 5; i++)
xormul[i] = s[i + 0] ^ s[i + 5] ^ s[i + 10] * s[i + 15] * s[i + 20];
bc[0] = xormul[0] ^ rotl641(xormul[2]);
bc[1] = xormul[1] ^ rotl641(xormul[3]);
bc[2] = xormul[2] ^ rotl641(xormul[4]);
bc[3] = xormul[3] ^ rotl641(xormul[0]);
bc[4] = xormul[4] ^ rotl641(xormul[1]);
s[0] ^= bc[4];
s[1] = rotl64_2(s[6] ^ bc[0], 12);
s[2] = rotl64_2(s[12] ^ bc[1], 11);
s[4] = rotl64_1(s[24] ^ bc[3], 14);
s[3] = rotl64_1(s[18] ^ bc[2], 21);
tmp1 = s[0]; tmp2 = s[1]; s[0] = bitselect(s[0] ^ s[2], s[0], s[1]); s[1] = bitselect(s[1] ^ s[3], s[1], s[2]); s[2] = bitselect(s[2] ^ s[4], s[2], s[3]); s[3] = bitselect(s[3] ^ tmp1, s[3], s[4]);
s[0] ^= 0x0000000000000001ULL;
}
struct reciprocal_value64 cached_recip;
static uint64_t cached_scr_size = 0;
static inline void scr_mix(uint64_t *st, uint64_t scr_size, struct reciprocal_value64 recip)
{
#define KK_MIXIN_SIZE 24
uint64_t _ALIGN(128) idx[KK_MIXIN_SIZE];
#ifdef _MSC_VER
#define pscr pscratchpad_buff
int x;
// non-optimized 64bit operations
for (x = 0; x < KK_MIXIN_SIZE; x++) {
idx[x] = reciprocal_remainder64(st[x], scr_size, recip) << 2;
}
if (idx[7] > scr_size*4) {
applog(LOG_WARNING, "Wrong remainder64 returned by the cpu hash %016llx > %016llx",
(unsigned long long) idx[7], (unsigned long long) scr_size*4);
return;
}
for(x = 0; x < KK_MIXIN_SIZE; x += 4) {
st[x + 0] ^= pscr[idx[x] + 0] ^ pscr[idx[x + 1] + 0] ^ pscr[idx[x + 2] + 0] ^ pscr[idx[x + 3] + 0];
st[x + 1] ^= pscr[idx[x] + 1] ^ pscr[idx[x + 1] + 1] ^ pscr[idx[x + 2] + 1] ^ pscr[idx[x + 3] + 1];
st[x + 2] ^= pscr[idx[x] + 2] ^ pscr[idx[x + 1] + 2] ^ pscr[idx[x + 2] + 2] ^ pscr[idx[x + 3] + 2];
st[x + 3] ^= pscr[idx[x] + 3] ^ pscr[idx[x + 1] + 3] ^ pscr[idx[x + 2] + 3] ^ pscr[idx[x + 3] + 3];
}
return;
#elif !defined(UNROLL_SCR_MIX)
#pragma GCC ivdep
for(int x = 0; x < 3; ++x)
{
__m128i *st0, *st1, *st2, *st3;
idx[0] = reciprocal_remainder64(st[(x << 3) + 0], scr_size, recip) << 2;
idx[1] = reciprocal_remainder64(st[(x << 3) + 1], scr_size, recip) << 2;
idx[2] = reciprocal_remainder64(st[(x << 3) + 2], scr_size, recip) << 2;
idx[3] = reciprocal_remainder64(st[(x << 3) + 3], scr_size, recip) << 2;
idx[4] = reciprocal_remainder64(st[(x << 3) + 4], scr_size, recip) << 2;
idx[5] = reciprocal_remainder64(st[(x << 3) + 5], scr_size, recip) << 2;
idx[6] = reciprocal_remainder64(st[(x << 3) + 6], scr_size, recip) << 2;
idx[7] = reciprocal_remainder64(st[(x << 3) + 7], scr_size, recip) << 2;
for(int y = 0; y < 8; y++) _mm_prefetch((const char*) (&pscratchpad_buff[idx[y]]), _MM_HINT_T1);
st0 = (__m128i *)&st[(x << 3) + 0];
st1 = (__m128i *)&st[(x << 3) + 2];
st2 = (__m128i *)&st[(x << 3) + 4];
st3 = (__m128i *)&st[(x << 3) + 6];
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[0]]));
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[1]]));
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[2]]));
*st0 = _mm_xor_si128(*st0, *((__m128i *)&pscratchpad_buff[idx[3]]));
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[0] + 2]));
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[1] + 2]));
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[2] + 2]));
*st1 = _mm_xor_si128(*st1, *((__m128i *)&pscratchpad_buff[idx[3] + 2]));
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[4]]));
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[5]]));
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[6]]));
*st2 = _mm_xor_si128(*st2, *((__m128i *)&pscratchpad_buff[idx[7]]));
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[4] + 2]));
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[5] + 2]));
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[6] + 2]));
*st3 = _mm_xor_si128(*st3, *((__m128i *)&pscratchpad_buff[idx[7] + 2]));
}
#else
#warning using AVX2 optimizations
idx[ 0] = reciprocal_remainder64(st[0], scr_size, recip) << 2;
idx[ 1] = reciprocal_remainder64(st[1], scr_size, recip) << 2;
idx[ 2] = reciprocal_remainder64(st[2], scr_size, recip) << 2;
idx[ 3] = reciprocal_remainder64(st[3], scr_size, recip) << 2;
idx[ 4] = reciprocal_remainder64(st[4], scr_size, recip) << 2;
idx[ 5] = reciprocal_remainder64(st[5], scr_size, recip) << 2;
idx[ 6] = reciprocal_remainder64(st[6], scr_size, recip) << 2;
idx[ 7] = reciprocal_remainder64(st[7], scr_size, recip) << 2;
for(int y = 0; y < 8; y++) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
idx[ 8] = reciprocal_remainder64(st[8], scr_size, recip) << 2;
idx[ 9] = reciprocal_remainder64(st[9], scr_size, recip) << 2;
idx[10] = reciprocal_remainder64(st[10], scr_size, recip) << 2;
idx[11] = reciprocal_remainder64(st[11], scr_size, recip) << 2;
idx[12] = reciprocal_remainder64(st[12], scr_size, recip) << 2;
idx[13] = reciprocal_remainder64(st[13], scr_size, recip) << 2;
idx[14] = reciprocal_remainder64(st[14], scr_size, recip) << 2;
idx[15] = reciprocal_remainder64(st[15], scr_size, recip) << 2;
for(int y = 8; y < 16; ++y) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
idx[16] = reciprocal_remainder64(st[16], scr_size, recip) << 2;
idx[17] = reciprocal_remainder64(st[17], scr_size, recip) << 2;
idx[18] = reciprocal_remainder64(st[18], scr_size, recip) << 2;
idx[19] = reciprocal_remainder64(st[19], scr_size, recip) << 2;
idx[20] = reciprocal_remainder64(st[20], scr_size, recip) << 2;
idx[21] = reciprocal_remainder64(st[21], scr_size, recip) << 2;
idx[22] = reciprocal_remainder64(st[22], scr_size, recip) << 2;
idx[23] = reciprocal_remainder64(st[23], scr_size, recip) << 2;
for(int y = 16; y < 24; ++y) _mm_prefetch(&pscratchpad_buff[idx[y]], _MM_HINT_T1);
__m256i *st0 = (__m256i *)&st[0];
for(int x = 0; x < 6; ++x)
{
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 0]]));
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 1]]));
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 2]]));
*st0 = _mm256_xor_si256(*st0, *((__m256i *)&pscratchpad_buff[idx[(x << 2) + 3]]));
++st0;
}
#endif
return;
}
static void wild_keccak_hash_dbl(uint8_t * __restrict md, const uint8_t * __restrict in)
{
uint64_t _ALIGN(32) st[25];
uint64_t scr_size, i;
struct reciprocal_value64 recip;
scr_size = scratchpad_size >> 2;
if (scr_size == cached_scr_size)
recip = cached_recip;
else {
cached_recip = recip = reciprocal_val64(scr_size);
cached_scr_size = scr_size;
}
// Wild Keccak #1
memcpy(st, in, 88);
st[10] = (st[10] & 0x00000000000000FFULL) | 0x0000000000000100ULL;
memset(&st[11], 0, 112);
st[16] |= 0x8000000000000000ULL;
for(i = 0; i < 23; i++) {
keccakf_mul(st);
scr_mix(st, scr_size, recip);
}
keccakf_mul_last(st);
// Wild Keccak #2
memset(&st[4], 0x00, 168);
st[ 4] = 0x0000000000000001ULL;
st[16] = 0x8000000000000000ULL;
for(i = 0; i < 23; i++) {
keccakf_mul(st);
scr_mix(st, scr_size, recip);
}
keccakf_mul_last(st);
memcpy(md, st, 32);
return;
}
void wildkeccak_hash(void* output, const void* input, uint64_t* scratchpad, uint64_t ssize)
{
if (scratchpad) pscratchpad_buff = scratchpad;
if (!scratchpad_size) scratchpad_size = ssize;
wild_keccak_hash_dbl((uint8_t*)output, (uint8_t*)input);
}
+381
View File
@@ -0,0 +1,381 @@
// WildKeccak CUDA Kernel, Code based on Linux Wolf0 bbr-miner implementation from 2014
// Adapted to ccminer 2.0 - tpruvot 2016-2017
//
// NOTE FOR SP: this ccminer version is licensed under GPLv3 Licence
extern "C" {
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
}
#include <miner.h>
#include <cuda_helper.h>
#include <cuda_vector_uint2x4.h> // todo
#include "wildkeccak.h"
extern char *device_config[MAX_GPUS]; // -l
extern uint64_t* pscratchpad_buff;
static uint64_t* d_input[MAX_GPUS];
static uint32_t* d_retnonce[MAX_GPUS];
static ulonglong4* d_scratchpad[MAX_GPUS];
static uint64_t* h_scratchpad[MAX_GPUS] = { 0 };
static cudaStream_t bufpad_stream[MAX_GPUS] = { 0 };
static cudaStream_t kernel_stream[MAX_GPUS] = { 0 };
uint64_t scratchpad_size = 0;
uint32_t WK_CUDABlocks = 64;
uint32_t WK_CUDAThreads = 256;
#define st0 vst0.x
#define st1 vst0.y
#define st2 vst0.z
#define st3 vst0.w
#define st4 vst4.x
#define st5 vst4.y
#define st6 vst4.z
#define st7 vst4.w
#define st8 vst8.x
#define st9 vst8.y
#define st10 vst8.z
#define st11 vst8.w
#define st12 vst12.x
#define st13 vst12.y
#define st14 vst12.z
#define st15 vst12.w
#define st16 vst16.x
#define st17 vst16.y
#define st18 vst16.z
#define st19 vst16.w
#define st20 vst20.x
#define st21 vst20.y
#define st22 vst20.z
#define st23 vst20.w
#if __CUDA_ARCH__ >= 320
__device__ __forceinline__ uint64_t cuda_rotl641(const uint64_t value)
{
uint2 result;
asm("shf.l.wrap.b32 %0, %1, %2, 1U;" : "=r"(result.x)
: "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))));
asm("shf.l.wrap.b32 %0, %1, %2, 1U;" : "=r"(result.y)
: "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))));
return __double_as_longlong(__hiloint2double(result.y, result.x));
}
#else
__noinline__ __device__ uint64_t cuda_rotl641(const uint64_t x) { return((x << 1) | (x >> 63)); }
#endif
__noinline__ __device__ uint64_t bitselect(const uint64_t a, const uint64_t b, const uint64_t c) { return(a ^ (c & (b ^ a))); }
#define ROTL641(x) (cuda_rotl641(x))
#define RND() \
bc[0] = st0 ^ st5 ^ st10 * st15 * st20 ^ ROTL641(st2 ^ st7 ^ st12 * st17 * st22); \
bc[1] = st1 ^ st6 ^ st11 * st16 * st21 ^ ROTL641(st3 ^ st8 ^ st13 * st18 * st23); \
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL641(st4 ^ st9 ^ st14 * st19 * st24); \
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL641(st0 ^ st5 ^ st10 * st15 * st20); \
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL641(st1 ^ st6 ^ st11 * st16 * st21); \
tmp1 = st1 ^ bc[0]; \
\
st0 ^= bc[4]; \
st1 = ROTL64(st6 ^ bc[0], 44); \
st6 = ROTL64(st9 ^ bc[3], 20); \
st9 = ROTL64(st22 ^ bc[1], 61); \
st22 = ROTL64(st14 ^ bc[3], 39); \
st14 = ROTL64(st20 ^ bc[4], 18); \
st20 = ROTL64(st2 ^ bc[1], 62); \
st2 = ROTL64(st12 ^ bc[1], 43); \
st12 = ROTL64(st13 ^ bc[2], 25); \
st13 = ROTL64(st19 ^ bc[3], 8); \
st19 = ROTL64(st23 ^ bc[2], 56); \
st23 = ROTL64(st15 ^ bc[4], 41); \
st15 = ROTL64(st4 ^ bc[3], 27); \
st4 = ROTL64(st24 ^ bc[3], 14); \
st24 = ROTL64(st21 ^ bc[0], 2); \
st21 = ROTL64(st8 ^ bc[2], 55); \
st8 = ROTL64(st16 ^ bc[0], 45); \
st16 = ROTL64(st5 ^ bc[4], 36); \
st5 = ROTL64(st3 ^ bc[2], 28); \
st3 = ROTL64(st18 ^ bc[2], 21); \
st18 = ROTL64(st17 ^ bc[1], 15); \
st17 = ROTL64(st11 ^ bc[0], 10); \
st11 = ROTL64(st7 ^ bc[1], 6); \
st7 = ROTL64(st10 ^ bc[4], 3); \
st10 = ROTL641(tmp1); \
\
tmp1 = st0; tmp2 = st1; st0 = bitselect(st0 ^ st2, st0, st1); st1 = bitselect(st1 ^ st3, st1, st2); \
st2 = bitselect(st2 ^ st4, st2, st3); st3 = bitselect(st3 ^ tmp1, st3, st4); st4 = bitselect(st4 ^ tmp2, st4, tmp1); \
tmp1 = st5; tmp2 = st6; st5 = bitselect(st5 ^ st7, st5, st6); st6 = bitselect(st6 ^ st8, st6, st7); \
st7 = bitselect(st7 ^ st9, st7, st8); st8 = bitselect(st8 ^ tmp1, st8, st9); st9 = bitselect(st9 ^ tmp2, st9, tmp1); \
tmp1 = st10; tmp2 = st11; st10 = bitselect(st10 ^ st12, st10, st11); st11 = bitselect(st11 ^ st13, st11, st12); \
st12 = bitselect(st12 ^ st14, st12, st13); st13 = bitselect(st13 ^ tmp1, st13, st14); st14 = bitselect(st14 ^ tmp2, st14, tmp1); \
tmp1 = st15; tmp2 = st16; st15 = bitselect(st15 ^ st17, st15, st16); st16 = bitselect(st16 ^ st18, st16, st17); \
st17 = bitselect(st17 ^ st19, st17, st18); st18 = bitselect(st18 ^ tmp1, st18, st19); st19 = bitselect(st19 ^ tmp2, st19, tmp1); \
tmp1 = st20; tmp2 = st21; st20 = bitselect(st20 ^ st22, st20, st21); st21 = bitselect(st21 ^ st23, st21, st22); \
st22 = bitselect(st22 ^ st24, st22, st23); st23 = bitselect(st23 ^ tmp1, st23, st24); st24 = bitselect(st24 ^ tmp2, st24, tmp1); \
st0 ^= 1;
#define LASTRND1() \
bc[0] = st0 ^ st5 ^ st10 * st15 * st20 ^ ROTL64(st2 ^ st7 ^ st12 * st17 * st22, 1); \
bc[1] = st1 ^ st6 ^ st11 * st16 * st21 ^ ROTL64(st3 ^ st8 ^ st13 * st18 * st23, 1); \
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL64(st4 ^ st9 ^ st14 * st19 * st24, 1); \
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL64(st0 ^ st5 ^ st10 * st15 * st20, 1); \
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL64(st1 ^ st6 ^ st11 * st16 * st21, 1); \
\
st0 ^= bc[4]; \
st1 = ROTL64(st6 ^ bc[0], 44); \
st2 = ROTL64(st12 ^ bc[1], 43); \
st4 = ROTL64(st24 ^ bc[3], 14); \
st3 = ROTL64(st18 ^ bc[2], 21); \
\
tmp1 = st0; st0 = bitselect(st0 ^ st2, st0, st1); st1 = bitselect(st1 ^ st3, st1, st2); st2 = bitselect(st2 ^ st4, st2, st3); st3 = bitselect(st3 ^ tmp1, st3, st4); \
st0 ^= 1;
#define LASTRND2() \
bc[2] = st2 ^ st7 ^ st12 * st17 * st22 ^ ROTL64(st4 ^ st9 ^ st14 * st19 * st24, 1); \
bc[3] = st3 ^ st8 ^ st13 * st18 * st23 ^ ROTL64(st0 ^ st5 ^ st10 * st15 * st20, 1); \
bc[4] = st4 ^ st9 ^ st14 * st19 * st24 ^ ROTL64(st1 ^ st6 ^ st11 * st16 * st21, 1); \
\
st0 ^= bc[4]; \
st4 = ROTL64(st24 ^ bc[3], 14); \
st3 = ROTL64(st18 ^ bc[2], 21); \
st3 = bitselect(st3 ^ st0, st3, st4);
__device__ ulonglong4 operator^(const ulonglong4 &a, const ulonglong4 &b)
{
return(make_ulonglong4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w));
}
#define MIX(vst) vst = vst ^ scratchpad[vst.x % scr_size] ^ scratchpad[vst.y % scr_size] ^ scratchpad[vst.z % scr_size] ^ scratchpad[vst.w % scr_size];
#define MIX_ALL MIX(vst0); MIX(vst4); MIX(vst8); MIX(vst12); MIX(vst16); MIX(vst20);
__global__
void wk(uint32_t* __restrict__ retnonce, const uint64_t* __restrict__ input, const ulonglong4* __restrict__ scratchpad,
const uint32_t scr_size, const uint32_t target, uint64_t startNonce)
{
ulonglong4 vst0, vst4, vst8, vst12, vst16, vst20;
uint64_t bc[5];
uint64_t st24, tmp1, tmp2;
const uint64_t nonce = startNonce + (blockDim.x * blockIdx.x) + threadIdx.x;
vst0 = make_ulonglong4((nonce << 8) + (input[0] & 0xFF), input[1] & 0xFFFFFFFFFFFFFF00ULL, input[2], input[3]);
vst4 = make_ulonglong4(input[4], input[5], input[6], input[7]);
vst8 = make_ulonglong4(input[8], input[9], (input[10] & 0xFF) | 0x100, 0);
vst12 = make_ulonglong4(0, 0, 0, 0);
vst16 = make_ulonglong4(0x8000000000000000ULL, 0, 0, 0);
vst20 = make_ulonglong4(0, 0, 0, 0);
st24 = 0;
RND();
MIX_ALL;
for(int i = 0; i < 22; i++) {
RND();
MIX_ALL;
}
LASTRND1();
vst4 = make_ulonglong4(1, 0, 0, 0);
vst8 = make_ulonglong4(0, 0, 0, 0);
vst12 = make_ulonglong4(0, 0, 0, 0);
vst16 = make_ulonglong4(0x8000000000000000ULL, 0, 0, 0);
vst20 = make_ulonglong4(0, 0, 0, 0);
st24 = 0;
RND();
MIX_ALL;
#pragma unroll
for(int i = 0; i < 22; i++) {
RND();
MIX_ALL;
}
LASTRND2();
if((st3 >> 32) <= target) {
retnonce[0] = (uint32_t) nonce;
retnonce[1] = retnonce[0];
}
}
__host__
void wildkeccak_kernel(const int thr_id, const uint32_t threads, const uint32_t startNounce, const uint2 target, uint32_t *resNonces)
{
CUDA_SAFE_CALL(cudaMemsetAsync(d_retnonce[thr_id], 0xff, 2 * sizeof(uint32_t), kernel_stream[thr_id]));
const uint32_t threadsperblock = WK_CUDAThreads;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
wk <<<grid, block, 0, kernel_stream[thr_id]>>> (d_retnonce[thr_id], d_input[thr_id], d_scratchpad[thr_id],
(uint32_t)(scratchpad_size >> 2), target.y, startNounce);
cudaMemcpyAsync(resNonces, d_retnonce[thr_id], 2*sizeof(uint32_t), cudaMemcpyDeviceToHost, kernel_stream[thr_id]);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_wildkeccak(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t *ptarget = work->target;
uint32_t throughput = 0;
uint64_t n, nonce, first;
uint8_t *pdata = (uint8_t*) work->data;
memcpy(&first, &pdata[1], 8);
n = nonce = first;
if (!scratchpad_size || !h_scratchpad[thr_id]) {
if (h_scratchpad[thr_id])
applog(LOG_ERR, "Scratchpad size is not set!");
work->data[0] = 0; // invalidate
sleep(1);
return -EBUSY;
}
if (!init[thr_id]) {
if (device_config[thr_id]) {
sscanf(device_config[thr_id], "%ux%u", &WK_CUDABlocks, &WK_CUDAThreads);
gpulog(LOG_INFO, thr_id, "Using %u x %u kernel launch config, %u threads",
WK_CUDABlocks, WK_CUDAThreads, throughput);
} else {
throughput = cuda_default_throughput(thr_id, WK_CUDABlocks*WK_CUDAThreads);
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput);
}
cudaSetDevice(device_map[thr_id]);
if (opt_cudaschedule == -1 && gpu_threads == 1) {
cudaDeviceReset();
// reduce cpu usage (linux)
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
CUDA_LOG_ERROR();
}
CUDA_SAFE_CALL(cudaMalloc(&d_input[thr_id], 88));
CUDA_SAFE_CALL(cudaMalloc(&d_retnonce[thr_id], 2*sizeof(uint32_t)));
int status = (int) cudaMalloc(&d_scratchpad[thr_id], WILD_KECCAK_SCRATCHPAD_BUFFSIZE);
if (status != cudaSuccess) {
gpulog(LOG_ERR, thr_id, "Unable to allocate device memory, %u MB, err %d",
(uint32_t) (WILD_KECCAK_SCRATCHPAD_BUFFSIZE/(1024*1024)), status);
exit(-ENOMEM);
}
cudaStreamCreate(&bufpad_stream[thr_id]);
cudaStreamCreate(&kernel_stream[thr_id]);
CUDA_SAFE_CALL(cudaMemcpyAsync(d_scratchpad[thr_id], h_scratchpad[thr_id], scratchpad_size << 3, cudaMemcpyHostToDevice, bufpad_stream[thr_id]));
init[thr_id] = true;
}
throughput = WK_CUDABlocks * WK_CUDAThreads;
cudaMemcpy(d_input[thr_id], pdata, 88, cudaMemcpyHostToDevice);
// cudaMemset(d_retnonce[thr_id], 0xFF, 2*sizeof(uint32_t));
if (h_scratchpad[thr_id]) {
cudaStreamSynchronize(bufpad_stream[thr_id]);
}
do {
// const uint32_t blocks = WK_CUDABlocks, threads = WK_CUDAThreads;
// const dim3 block(blocks);
// const dim3 thread(threads);
uint32_t h_retnonce[2] = { UINT32_MAX, UINT32_MAX };
uint2 target = make_uint2(ptarget[6], ptarget[7]);
wildkeccak_kernel(thr_id, throughput, (uint32_t) nonce, target, h_retnonce);
/*
wk <<<block, thread, 0, kernel_stream[thr_id]>>> (d_retnonce[thr_id], d_input[thr_id], d_scratchpad[thr_id],
(uint32_t)(scratchpad_size >> 2), nonce, ptarget[7]);
*/
*hashes_done = (unsigned long) (n - first + throughput);
cudaStreamSynchronize(kernel_stream[thr_id]);
if(h_retnonce[0] != UINT32_MAX) {
uint8_t _ALIGN(64) cpuhash[32];
uint32_t* vhash = (uint32_t*) cpuhash;
uint64_t nonce64;
memcpy(&pdata[1], &h_retnonce[0], sizeof(uint32_t));
memcpy(&nonce64, &pdata[1], 8);
wildkeccak_hash(cpuhash, pdata, pscratchpad_buff, scratchpad_size);
if (!cpuhash[31] && vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
work_set_target_ratio(work, vhash);
//applog_hex(pdata, 84);
//applog_hex(cpuhash, 32);
//applog_hex(ptarget, 32);
memcpy(work->nonces, &nonce64, 8);
if (n + throughput > max_nonce) {
*hashes_done = (unsigned long) (max_nonce - first);
}
work->valid_nonces = 1;
return 1;
} else if (vhash[7] > ptarget[7]) {
gpu_increment_reject(thr_id);
if (!opt_quiet)
gpulog(LOG_WARNING, thr_id, "result for nonce %08x does not validate on CPU!", h_retnonce[0]);
}
}
if (n + throughput >= max_nonce) {
n = max_nonce;
break;
}
n += throughput;
nonce += throughput;
} while(!work_restart[thr_id].restart);
*hashes_done = (unsigned long) (n - first + 1);
return 0;
}
void wildkeccak_scratchpad_need_update(uint64_t* pscratchpad_buff)
{
for(int i = 0; i < opt_n_threads; i++) {
h_scratchpad[i] = pscratchpad_buff;
if (init[i]) {
gpulog(LOG_DEBUG, i, "Starting scratchpad update...");
cudaMemcpyAsync(d_scratchpad[i], h_scratchpad[i], scratchpad_size << 3, cudaMemcpyHostToDevice, bufpad_stream[i]);
work_restart[i].restart = true;
}
}
}
void free_wildkeccak(int thr_id)
{
if (!init[thr_id])
return;
cudaThreadSynchronize();
cudaFree(d_scratchpad[thr_id]);
cudaFree(d_input[thr_id]);
cudaFree(d_retnonce[thr_id]);
cudaStreamDestroy(bufpad_stream[thr_id]);
cudaStreamDestroy(kernel_stream[thr_id]);
cudaDeviceSynchronize();
init[thr_id] = false;
}
+10
View File
@@ -0,0 +1,10 @@
#define WILD_KECCAK_SCRATCHPAD_BUFFSIZE 1ULL << 29
#define WILD_KECCAK_ADDENDUMS_ARRAY_SIZE 10
extern uint64_t scratchpad_size;
extern uint32_t WK_CUDABlocks, WK_CUDAThreads;
void wildkeccak_scratchpad_need_update(uint64_t* pscratchpad_buff);
+1337
View File
File diff suppressed because it is too large. Load diff
+41
View File
@@ -0,0 +1,41 @@
#include <jansson.h>
#include "wildkeccak.h"
#ifdef WIN32
#define _PACKED _ALIGN(4)
#else
#define _PACKED __attribute__((__packed__))
#endif
struct _PACKED scratchpad_hi {
unsigned char prevhash[32];
uint64_t height;
};
struct _PACKED addendums_array_entry {
struct scratchpad_hi prev_hi;
uint64_t add_size;
};
struct _PACKED scratchpad_file_header {
struct scratchpad_hi current_hi;
struct addendums_array_entry add_arr[WILD_KECCAK_ADDENDUMS_ARRAY_SIZE];
uint64_t scratchpad_size;
};
bool rpc2_job_decode(const json_t *job, struct work *work);
bool rpc2_stratum_job(struct stratum_ctx *sctx, json_t *id, json_t *params);
bool rpc2_stratum_gen_work(struct stratum_ctx *sctx, struct work *work);
bool rpc2_stratum_submit(struct pool_infos *pool, struct work *work);
int rpc2_stratum_thread_stuff(struct pool_infos* pool);
bool rpc2_login_decode(const json_t *val);
void rpc2_init();
void GetScratchpad();
+151 -64
View File
@@ -4,10 +4,6 @@
#include <unistd.h>
#include <map>
#ifndef _WIN32
#include <unistd.h>
#endif
// include thrust
#ifndef __cplusplus
#include <thrust/version.h>
@@ -23,34 +19,40 @@
#include "cuda_runtime.h"
#ifdef __cplusplus
/* miner.h functions are declared in C type, not C++ */
extern "C" {
#endif
// CUDA Devices on the System
int cuda_num_devices()
{
int version;
int version = 0, GPU_N = 0;
cudaError_t err = cudaDriverGetVersion(&version);
if (err != cudaSuccess)
{
if (err != cudaSuccess) {
applog(LOG_ERR, "Unable to query CUDA driver version! Is an nVidia driver installed?");
exit(1);
}
int maj = version / 1000, min = version % 100; // same as in deviceQuery sample
if (maj < 5 || (maj == 5 && min < 5))
{
applog(LOG_ERR, "Driver does not support CUDA %d.%d API! Update your nVidia driver!", 5, 5);
if (version < CUDART_VERSION) {
applog(LOG_ERR, "Your system does not support CUDA %d.%d API!",
CUDART_VERSION / 1000, (CUDART_VERSION % 1000) / 10);
exit(1);
}
int GPU_N;
err = cudaGetDeviceCount(&GPU_N);
if (err != cudaSuccess)
{
if (err != cudaSuccess) {
applog(LOG_ERR, "Unable to query number of CUDA devices! Is an nVidia driver installed?");
exit(1);
}
return GPU_N;
}
int cuda_version()
{
return (int) CUDART_VERSION;
}
void cuda_devicenames()
{
cudaError_t err;
@@ -62,29 +64,32 @@ void cuda_devicenames()
exit(1);
}
GPU_N = min(MAX_GPUS, GPU_N);
if (opt_n_threads)
GPU_N = min(MAX_GPUS, opt_n_threads);
for (int i=0; i < GPU_N; i++)
{
char vendorname[32] = { 0 };
int dev_id = device_map[i];
cudaDeviceProp props;
cudaGetDeviceProperties(&props, device_map[i]);
cudaGetDeviceProperties(&props, dev_id);
device_sm[i] = (props.major * 100 + props.minor * 10);
device_sm[dev_id] = (props.major * 100 + props.minor * 10);
device_mpcount[dev_id] = (short) props.multiProcessorCount;
if (device_name[i]) {
free(device_name[i]);
device_name[i] = NULL;
if (device_name[dev_id]) {
free(device_name[dev_id]);
device_name[dev_id] = NULL;
}
#ifdef USE_WRAPNVML
if (gpu_vendor((uint8_t)props.pciBusID, vendorname) > 0 && strlen(vendorname)) {
device_name[i] = (char*) calloc(1, strlen(vendorname) + strlen(props.name) + 2);
device_name[dev_id] = (char*) calloc(1, strlen(vendorname) + strlen(props.name) + 2);
if (!strncmp(props.name, "GeForce ", 8))
sprintf(device_name[i], "%s %s", vendorname, &props.name[8]);
sprintf(device_name[dev_id], "%s %s", vendorname, &props.name[8]);
else
sprintf(device_name[i], "%s %s", vendorname, props.name);
sprintf(device_name[dev_id], "%s %s", vendorname, props.name);
} else
#endif
device_name[i] = strdup(props.name);
device_name[dev_id] = strdup(props.name);
}
}
@@ -93,18 +98,32 @@ void cuda_print_devices()
int ngpus = cuda_num_devices();
cuda_devicenames();
for (int n=0; n < ngpus; n++) {
int m = device_map[n];
int dev_id = device_map[n % MAX_GPUS];
cudaDeviceProp props;
cudaGetDeviceProperties(&props, m);
cudaGetDeviceProperties(&props, dev_id);
if (!opt_n_threads || n < opt_n_threads) {
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", m, props.major, props.minor, device_name[n]);
fprintf(stderr, "GPU #%d: SM %d.%d %s @ %.0f MHz (MEM %.0f)\n", dev_id,
props.major, props.minor, device_name[dev_id],
(double) props.clockRate/1000,
(double) props.memoryClockRate/1000);
#ifdef USE_WRAPNVML
if (opt_debug) nvml_print_device_info(dev_id);
#ifdef WIN32
if (opt_debug) {
unsigned int devNum = nvapi_devnum(dev_id);
nvapi_pstateinfo(devNum);
}
#endif
#endif
}
}
}
void cuda_shutdown()
{
cudaDeviceSynchronize();
// require gpu init first
//if (thr_info != NULL)
// cudaDeviceSynchronize();
cudaDeviceReset();
}
@@ -143,19 +162,120 @@ int cuda_finddevice(char *name)
return -1;
}
uint32_t device_intensity(int thr_id, const char *func, uint32_t defcount)
// since 1.7
uint32_t cuda_default_throughput(int thr_id, uint32_t defcount)
{
//int dev_id = device_map[thr_id % MAX_GPUS];
uint32_t throughput = gpus_intensity[thr_id] ? gpus_intensity[thr_id] : defcount;
api_set_throughput(thr_id, throughput);
if (gpu_threads > 1 && throughput == defcount) throughput /= (gpu_threads-1);
if (api_thr_id != -1) api_set_throughput(thr_id, throughput);
//gpulog(LOG_INFO, thr_id, "throughput %u", throughput);
return throughput;
}
// since 1.8.3
double throughput2intensity(uint32_t throughput)
{
double intensity = 0.;
uint32_t ws = throughput;
uint8_t i = 0;
while (ws > 1 && i++ < 32)
ws = ws >> 1;
intensity = (double) i;
if (i && ((1U << i) < throughput)) {
intensity += ((double) (throughput-(1U << i)) / (1U << i));
}
return intensity;
}
// if we use 2 threads on the same gpu, we need to reinit the threads
void cuda_reset_device(int thr_id, bool *init)
{
int dev_id = device_map[thr_id % MAX_GPUS];
cudaSetDevice(dev_id);
if (init != NULL) {
// with init array, its meant to be used in algo's scan code...
for (int i=0; i < MAX_GPUS; i++) {
if (device_map[i] == dev_id) {
init[i] = false;
}
}
// force exit from algo's scan loops/function
restart_threads();
cudaDeviceSynchronize();
while (cudaStreamQuery(NULL) == cudaErrorNotReady)
usleep(1000);
}
cudaDeviceReset();
if (opt_cudaschedule >= 0) {
cudaSetDeviceFlags((unsigned)(opt_cudaschedule & cudaDeviceScheduleMask));
} else {
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
}
cudaDeviceSynchronize();
}
// return free memory in megabytes
int cuda_available_memory(int thr_id)
{
int dev_id = device_map[thr_id % MAX_GPUS];
#if defined(_WIN32) && defined(USE_WRAPNVML)
uint64_t tot64 = 0, free64 = 0;
// cuda (6.5) one can crash on pascal and dont handle 8GB
nvapiMemGetInfo(dev_id, &free64, &tot64);
return (int) (free64 / (1024));
#else
size_t mtotal = 0, mfree = 0;
cudaSetDevice(dev_id);
cudaDeviceSynchronize();
cudaMemGetInfo(&mfree, &mtotal);
return (int) (mfree / (1024 * 1024));
#endif
}
// Check (and reset) last cuda error, and report it in logs
void cuda_log_lasterror(int thr_id, const char* func, int line)
{
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess && !opt_quiet)
gpulog(LOG_WARNING, thr_id, "%s:%d %s", func, line, cudaGetErrorString(err));
}
// Clear any cuda error in non-cuda unit (.c/.cpp)
void cuda_clear_lasterror()
{
cudaGetLastError();
}
#ifdef __cplusplus
} /* extern "C" */
#endif
int cuda_gpu_info(struct cgpu_info *gpu)
{
cudaDeviceProp props;
if (cudaGetDeviceProperties(&props, gpu->gpu_id) == cudaSuccess) {
gpu->gpu_clock = (uint32_t) props.clockRate;
gpu->gpu_memclock = (uint32_t) props.memoryClockRate;
gpu->gpu_mem = (uint64_t) (props.totalGlobalMem / 1024); // kB
#if defined(_WIN32) && defined(USE_WRAPNVML)
// required to get mem size > 4GB (size_t too small for bytes on 32bit)
nvapiMemGetInfo(gpu->gpu_id, &gpu->gpu_memfree, &gpu->gpu_mem); // kB
#endif
gpu->gpu_mem = gpu->gpu_mem / 1024; // MB
return 0;
}
return -1;
}
// Zeitsynchronisations-Routine von cudaminer mit CPU sleep
// Note: if you disable all of these calls, CPU usage will hit 100%
typedef struct { double value[8]; } tsumarray;
cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id)
{
cudaError_t result = cudaSuccess;
if (abort_flag)
return result;
if (situation >= 0)
{
static std::map<int, tsumarray> tsum;
@@ -181,43 +301,10 @@ cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id)
return result;
}
int cuda_gpu_clocks(struct cgpu_info *gpu)
{
cudaDeviceProp props;
if (cudaGetDeviceProperties(&props, gpu->gpu_id) == cudaSuccess) {
gpu->gpu_clock = props.clockRate;
gpu->gpu_memclock = props.memoryClockRate;
gpu->gpu_mem = props.totalGlobalMem;
return 0;
}
return -1;
}
// if we use 2 threads on the same gpu, we need to reinit the threads
void cuda_reset_device(int thr_id, bool *init)
{
int dev_id = device_map[thr_id];
cudaSetDevice(dev_id);
if (init != NULL) {
// with init array, its meant to be used in algo's scan code...
for (int i=0; i < MAX_GPUS; i++) {
if (device_map[i] == dev_id) {
init[i] = false;
}
}
// force exit from algo's scan loops/function
restart_threads();
cudaDeviceSynchronize();
while (cudaStreamQuery(NULL) == cudaErrorNotReady)
usleep(1000);
}
cudaDeviceReset();
}
void cudaReportHardwareFailure(int thr_id, cudaError_t err, const char* func)
{
struct cgpu_info *gpu = &thr_info[thr_id].gpu;
gpu->hw_errors++;
applog(LOG_ERR, "GPU #%d: %s %s", device_map[thr_id], func, cudaGetErrorString(err));
gpulog(LOG_ERR, thr_id, "%s %s", func, cudaGetErrorString(err));
sleep(1);
}
+63 -6
View File
@@ -11,18 +11,29 @@
__constant__ uint32_t pTarget[8]; // 32 bytes
// store MAX_GPUS device arrays of 8 nonces
static uint32_t* h_resNonces[MAX_GPUS];
static uint32_t* d_resNonces[MAX_GPUS];
static bool init_done = false;
static uint32_t* h_resNonces[MAX_GPUS] = { NULL };
static uint32_t* d_resNonces[MAX_GPUS] = { NULL };
static __thread bool init_done = false;
__host__
void cuda_check_cpu_init(int thr_id, uint32_t threads)
{
CUDA_CALL_OR_RET(cudaMallocHost(&h_resNonces[thr_id], 32));
CUDA_CALL_OR_RET(cudaMalloc(&d_resNonces[thr_id], 32));
CUDA_SAFE_CALL(cudaMallocHost(&h_resNonces[thr_id], 32));
init_done = true;
}
__host__
void cuda_check_cpu_free(int thr_id)
{
if (!init_done) return;
cudaFree(d_resNonces[thr_id]);
cudaFreeHost(h_resNonces[thr_id]);
d_resNonces[thr_id] = NULL;
h_resNonces[thr_id] = NULL;
init_done = false;
}
// Target Difficulty
__host__
void cuda_check_cpu_setTarget(const void *ptarget)
@@ -89,6 +100,21 @@ void cuda_checkhash_64(uint32_t threads, uint32_t startNounce, uint32_t *hash, u
}
}
__global__ __launch_bounds__(512, 4)
void cuda_checkhash_32(uint32_t threads, uint32_t startNounce, uint32_t *hash, uint32_t *resNonces)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t *inpHash = &hash[thread << 3];
if (resNonces[0] == UINT32_MAX) {
if (hashbelowtarget(inpHash, pTarget))
resNonces[0] = (startNounce + thread);
}
}
}
__host__
uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash)
{
@@ -99,6 +125,9 @@ uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uin
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
if (bench_algo >= 0) // dont interrupt the global benchmark
return UINT32_MAX;
if (!init_done) {
applog(LOG_ERR, "missing call to cuda_check_cpu_init");
return UINT32_MAX;
@@ -111,6 +140,31 @@ uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uin
return h_resNonces[thr_id][0];
}
__host__
uint32_t cuda_check_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash)
{
cudaMemset(d_resNonces[thr_id], 0xff, sizeof(uint32_t));
const uint32_t threadsperblock = 512;
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
dim3 block(threadsperblock);
if (bench_algo >= 0) // dont interrupt the global benchmark
return UINT32_MAX;
if (!init_done) {
applog(LOG_ERR, "missing call to cuda_check_cpu_init");
return UINT32_MAX;
}
cuda_checkhash_32 <<<grid, block>>> (threads, startNounce, d_inputHash, d_resNonces[thr_id]);
cudaThreadSynchronize();
cudaMemcpy(h_resNonces[thr_id], d_resNonces[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
return h_resNonces[thr_id][0];
}
/* --------------------------------------------------------------------------------------------- */
__global__ __launch_bounds__(512, 4)
@@ -148,7 +202,7 @@ uint32_t cuda_check_hash_suppl(int thr_id, uint32_t threads, uint32_t startNounc
cuda_checkhash_64_suppl <<<grid, block>>> (startNounce, d_inputHash, d_resNonces[thr_id]);
cudaThreadSynchronize();
cudaMemcpy(h_resNonces[thr_id], d_resNonces[thr_id], 8*sizeof(uint32_t), cudaMemcpyDeviceToHost);
cudaMemcpy(h_resNonces[thr_id], d_resNonces[thr_id], 32, cudaMemcpyDeviceToHost);
rescnt = h_resNonces[thr_id][0];
if (rescnt > numNonce) {
if (numNonce <= rescnt) {
@@ -193,9 +247,12 @@ uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNoun
uint32_t result = UINT32_MAX;
if (bench_algo >= 0) // dont interrupt the global benchmark
return result;
if (!init_done) {
applog(LOG_ERR, "missing call to cuda_check_cpu_init");
return UINT32_MAX;
return result;
}
cudaMemset(d_resNonces[thr_id], 0xff, sizeof(uint32_t));
+47
View File
@@ -0,0 +1,47 @@
/**
* Helper to trace gpu computed data with --cputest
*
* Sample usage in an algo scan cuda unit :
*
* #define _DEBUG
* #define _DEBUG_PREFIX "x11-"
* #include "cuda_debug.cuh"
*
* TRACE64("luffa", d_hash);
* or
* TRACE("luffa")
*
* Dont forget to link the scan function in util.cpp (do_gpu_tests)
*
*/
#include <stdio.h>
//#include "cuda_helper.h"
#ifndef _DEBUG_PREFIX
#define _DEBUG_PREFIX ""
#endif
#ifdef _DEBUG
#define TRACE64(algo, d_buf) { \
if (max_nonce == 1 && pdata[19] <= 1 && !opt_benchmark) { \
uint32_t oft = 0; \
uint32_t* debugbuf = NULL; \
cudaMallocHost(&debugbuf, 16*sizeof(uint32_t)); \
cudaMemcpy(debugbuf, d_buf[thr_id] + oft, 16*sizeof(uint32_t), cudaMemcpyDeviceToHost); \
printf(_DEBUG_PREFIX "%s %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", \
algo, \
swab32(debugbuf[0]), swab32(debugbuf[1]), swab32(debugbuf[2]), swab32(debugbuf[3]), \
swab32(debugbuf[4]), swab32(debugbuf[5]), swab32(debugbuf[6]), swab32(debugbuf[7]), \
swab32(debugbuf[8]), swab32(debugbuf[9]), swab32(debugbuf[10]),swab32(debugbuf[11]), \
swab32(debugbuf[12]),swab32(debugbuf[13]),swab32(debugbuf[14]),swab32(debugbuf[15])); \
cudaFreeHost(debugbuf); \
} \
}
#else
#define TRACE64(algo, d_buf) {}
#endif
// simplified default
#define TRACE(algo) TRACE64(algo, d_hash)
+4 -3
View File
@@ -1,8 +1,9 @@
#ifndef _CUDA_FUGUE512_H
#define _CUDA_FUGUE512_H
#ifndef _CUDA_FUGUE256_H
#define _CUDA_FUGUE256_H
void fugue256_cpu_hash(int thr_id, uint32_t threads, int startNounce, void *outputHashes, uint32_t *nounce);
void fugue256_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce);
void fugue256_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
void fugue256_cpu_init(int thr_id, uint32_t threads);
void fugue256_cpu_free(int thr_id);
#endif
+23 -21
View File
@@ -5,6 +5,11 @@
#include "cuda_helper.h"
#ifdef __INTELLISENSE__
#define __CUDA_ARCH__ 500
#define __byte_perm(x,y,n) x
#endif
#include "miner.h"
__constant__ uint32_t pTarget[8]; // Single GPU
@@ -85,9 +90,8 @@ void groestlcoin_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t
}
}
if(rc == true)
if(resNounce[0] > nounce)
resNounce[0] = nounce;
if(rc && resNounce[0] > nounce)
resNounce[0] = nounce;
}
}
#endif
@@ -99,15 +103,20 @@ void groestlcoin_cpu_init(int thr_id, uint32_t threads)
// to check if the binary supports SM3+
cuda_get_arch(thr_id);
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
CUDA_SAFE_CALL(cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t)));
}
__host__
void groestlcoin_cpu_free(int thr_id)
{
cudaFree(d_resultNonce[thr_id]);
}
__host__
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
{
uint32_t msgBlock[32];
uint32_t msgBlock[32] = { 0 };
memset(msgBlock, 0, sizeof(uint32_t) * 32);
memcpy(&msgBlock[0], data, 80);
// Erweitere die Nachricht auf den Nachrichtenblock (padding)
@@ -119,18 +128,14 @@ void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
// auf der GPU ausgeführt)
// Blockheader setzen (korrekte Nonce und Hefty Hash fehlen da drin noch)
cudaMemcpyToSymbol( groestlcoin_gpu_msg,
msgBlock,
128);
cudaMemcpyToSymbol(groestlcoin_gpu_msg, msgBlock, 128);
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
cudaMemcpyToSymbol( pTarget,
pTargetIn,
sizeof(uint32_t) * 8 );
cudaMemcpyToSymbol(pTarget, pTargetIn, 32);
}
__host__
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce)
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonce)
{
uint32_t threadsperblock = 256;
@@ -138,24 +143,21 @@ void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, vo
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
int factor = 4;
// berechne wie viele Thread Blocks wir brauchen
// berechne wie viele Thread Blocks wir brauchen
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
dim3 block(threadsperblock);
// Größe des dynamischen Shared Memory Bereichs
size_t shared_size = 0;
int dev_id = device_map[thr_id];
if (device_sm[dev_id] < 300 || cuda_arch[dev_id] < 300) {
printf("Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
gpulog(LOG_ERR, thr_id, "Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
proper_exit(EXIT_CODE_CUDA_ERROR);
}
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
groestlcoin_gpu_hash_quad<<<grid, block, shared_size>>>(threads, startNounce, d_resultNonce[thr_id]);
groestlcoin_gpu_hash_quad <<<grid, block>>> (threads, startNounce, d_resultNonce[thr_id]);
// Strategisches Sleep Kommando zur Senkung der CPU Last
MyStreamSynchronize(NULL, 0, thr_id);
// MyStreamSynchronize(NULL, 0, thr_id);
cudaMemcpy(nounce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
cudaMemcpy(resNonce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
}
+2 -1
View File
@@ -2,7 +2,8 @@
#define _CUDA_GROESTLCOIN_H
void groestlcoin_cpu_init(int thr_id, uint32_t threads);
void groestlcoin_cpu_free(int thr_id);
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce);
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNonce);
#endif
+88 -79
View File
@@ -11,6 +11,7 @@
#define __launch_bounds__(max_tpb, min_blocks)
#endif
#include <stdbool.h>
#include <stdint.h>
#ifndef UINT32_MAX
@@ -24,13 +25,13 @@
extern "C" short device_map[MAX_GPUS];
extern "C" long device_sm[MAX_GPUS];
extern "C" short device_mpcount[MAX_GPUS];
extern int cuda_arch[MAX_GPUS];
// common functions
extern int cuda_get_arch(int thr_id);
extern void cuda_reset_device(int thr_id, bool *init);
extern void cuda_check_cpu_init(int thr_id, uint32_t threads);
extern void cuda_check_cpu_free(int thr_id);
extern void cuda_check_cpu_setTarget(const void *ptarget);
extern uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash);
extern uint32_t cuda_check_hash_suppl(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash, uint8_t numNonce);
@@ -76,6 +77,12 @@ extern const uint3 threadIdx;
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
#endif
#define AS_U32(addr) *((uint32_t*)(addr))
#define AS_U64(addr) *((uint64_t*)(addr))
#define AS_UINT2(addr) *((uint2*)(addr))
#define AS_UINT4(addr) *((uint4*)(addr))
#define AS_UL2(addr) *((ulonglong2*)(addr))
__device__ __forceinline__ uint64_t MAKE_ULONGLONG(uint32_t LO, uint32_t HI)
{
#if __CUDA_ARCH__ >= 130
@@ -132,8 +139,16 @@ __device__ __forceinline__ uint64_t cuda_swab64(uint64_t x)
{
// Input: 77665544 33221100
// Output: 00112233 44556677
uint64_t result = __byte_perm((uint32_t) x, 0, 0x0123);
return (result << 32) | __byte_perm(_HIDWORD(x), 0, 0x0123);
uint64_t result;
//result = __byte_perm((uint32_t) x, 0, 0x0123);
//return (result << 32) + __byte_perm(_HIDWORD(x), 0, 0x0123);
asm("{ .reg .b32 x, y; // swab64\n\t"
"mov.b64 {x,y}, %1;\n\t"
"prmt.b32 x, x, 0, 0x0123;\n\t"
"prmt.b32 y, y, 0, 0x0123;\n\t"
"mov.b64 %0, {y,x};\n\t"
"}\n" : "=l"(result): "l"(x));
return result;
}
#else
/* host */
@@ -197,7 +212,7 @@ __device__ __forceinline__
uint64_t xor1(uint64_t a, uint64_t b)
{
uint64_t result;
asm("xor.b64 %0, %1, %2;" : "=l"(result) : "l"(a), "l"(b));
asm("xor.b64 %0, %1, %2; // xor1" : "=l"(result) : "l"(a), "l"(b));
return result;
}
#else
@@ -210,7 +225,7 @@ __device__ __forceinline__
uint64_t xor3(uint64_t a, uint64_t b, uint64_t c)
{
uint64_t result;
asm("xor.b64 %0, %2, %3;\n\t"
asm("xor.b64 %0, %2, %3; // xor3\n\t"
"xor.b64 %0, %0, %1;\n\t"
/* output : input registers */
: "=l"(result) : "l"(a), "l"(b), "l"(c));
@@ -245,49 +260,31 @@ uint64_t xandx(uint64_t a, uint64_t b, uint64_t c)
{
#ifdef __CUDA_ARCH__
uint64_t result;
asm("{\n\t"
asm("{ // xandx \n\t"
".reg .u64 n;\n\t"
"xor.b64 %0, %2, %3;\n\t"
"and.b64 n, %0, %1;\n\t"
"xor.b64 %0, n, %3;"
"}\n"
: "=l"(result) : "l"(a), "l"(b), "l"(c));
"xor.b64 %0, n, %3;\n\t"
"}\n" : "=l"(result) : "l"(a), "l"(b), "l"(c));
return result;
#else
return ((b^c) & a) ^ c;
#endif
}
// device asm for x17
__device__ __forceinline__
uint64_t sph_t64(uint64_t x)
{
#ifdef __CUDA_ARCH__
uint64_t result;
asm("{\n\t"
"and.b64 %0,%1,0xFFFFFFFFFFFFFFFF;\n\t"
"}\n"
: "=l"(result) : "l"(x));
return result;
#else
return x;
#endif
}
// device asm for x17
__device__ __forceinline__
uint64_t andor(uint64_t a, uint64_t b, uint64_t c)
{
#ifdef __CUDA_ARCH__
uint64_t result;
asm("{\n\t"
asm("{ // andor\n\t"
".reg .u64 m,n;\n\t"
"and.b64 m, %1, %2;\n\t"
" or.b64 n, %1, %2;\n\t"
"and.b64 %0, n, %3;\n\t"
" or.b64 %0, %0, m ;\n\t"
"}\n"
: "=l"(result) : "l"(a), "l"(b), "l"(c));
" or.b64 %0, %0, m;\n\t"
"}\n" : "=l"(result) : "l"(a), "l"(b), "l"(c));
return result;
#else
return ((a | b) & c) | (a & b);
@@ -301,7 +298,6 @@ uint64_t shr_t64(uint64_t x, uint32_t n)
#ifdef __CUDA_ARCH__
uint64_t result;
asm("shr.b64 %0,%1,%2;\n\t"
"and.b64 %0,%0,0xFFFFFFFFFFFFFFFF;\n\t" /* useful ? */
: "=l"(result) : "l"(x), "r"(n));
return result;
#else
@@ -315,7 +311,6 @@ uint64_t shl_t64(uint64_t x, uint32_t n)
#ifdef __CUDA_ARCH__
uint64_t result;
asm("shl.b64 %0,%1,%2;\n\t"
"and.b64 %0,%0,0xFFFFFFFFFFFFFFFF;\n\t" /* useful ? */
: "=l"(result) : "l"(x), "r"(n));
return result;
#else
@@ -369,15 +364,14 @@ __device__ __forceinline__
uint64_t ROTR64(const uint64_t x, const int offset)
{
uint64_t result;
asm("{\n\t"
asm("{ // ROTR64 \n\t"
".reg .b64 lhs;\n\t"
".reg .u32 roff;\n\t"
"shr.b64 lhs, %1, %2;\n\t"
"sub.u32 roff, 64, %2;\n\t"
"shl.b64 %0, %1, roff;\n\t"
"add.u64 %0, %0, lhs;\n\t"
"}\n"
: "=l"(result) : "l"(x), "r"(offset));
"}\n" : "=l"(result) : "l"(x), "r"(offset));
return result;
}
#else
@@ -404,15 +398,14 @@ __device__ __forceinline__
uint64_t ROTL64(const uint64_t x, const int offset)
{
uint64_t result;
asm("{\n\t"
asm("{ // ROTL64 \n\t"
".reg .b64 lhs;\n\t"
".reg .u32 roff;\n\t"
"shl.b64 lhs, %1, %2;\n\t"
"sub.u32 roff, 64, %2;\n\t"
"shr.b64 %0, %1, roff;\n\t"
"add.u64 %0, lhs, %0;\n\t"
"}\n"
: "=l"(result) : "l"(x), "r"(offset));
"}\n" : "=l"(result) : "l"(x), "r"(offset));
return result;
}
#elif __CUDA_ARCH__ >= 320 && USE_ROT_ASM_OPT == 3
@@ -420,7 +413,7 @@ __device__
uint64_t ROTL64(const uint64_t x, const int offset)
{
uint64_t res;
asm("{\n\t"
asm("{ // ROTL64 \n\t"
".reg .u32 tl,th,vl,vh;\n\t"
".reg .pred p;\n\t"
"mov.b64 {tl,th}, %1;\n\t"
@@ -429,8 +422,7 @@ uint64_t ROTL64(const uint64_t x, const int offset)
"setp.lt.u32 p, %2, 32;\n\t"
"@!p mov.b64 %0, {vl,vh};\n\t"
"@p mov.b64 %0, {vh,vl};\n\t"
"}"
: "=l"(res) : "l"(x) , "r"(offset)
"}\n" : "=l"(res) : "l"(x) , "r"(offset)
);
return res;
}
@@ -495,33 +487,12 @@ static __device__ __forceinline__ uint2 operator~ (uint2 a) { return make_uint2(
static __device__ __forceinline__ void operator^= (uint2 &a, uint2 b) { a = a ^ b; }
static __device__ __forceinline__ uint2 operator+ (uint2 a, uint2 b) {
#ifdef __CUDA_ARCH__
uint2 result;
asm("{\n\t"
"add.cc.u32 %0,%2,%4; \n\t"
"addc.u32 %1,%3,%5; \n\t"
"}\n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
return result;
#else
return vectorize(devectorize(a) + devectorize(b));
#endif
}
static __device__ __forceinline__ void operator+= (uint2 &a, uint2 b) { a = a + b; }
static __device__ __forceinline__ uint2 operator- (uint2 a, uint2 b) {
#if defined(__CUDA_ARCH__) && CUDA_VERSION < 7000
uint2 result;
asm("{\n\t"
"sub.cc.u32 %0,%2,%4; \n\t"
"subc.u32 %1,%3,%5; \n\t"
"}\n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
return result;
#else
return vectorize(devectorize(a) - devectorize(b));
#endif
}
static __device__ __forceinline__ void operator-= (uint2 &a, uint2 b) { a = a - b; }
@@ -533,13 +504,12 @@ static __device__ __forceinline__ uint2 operator* (uint2 a, uint2 b)
{
#ifdef __CUDA_ARCH__
uint2 result;
asm("{\n\t"
"mul.lo.u32 %0,%2,%4; \n\t"
"mul.hi.u32 %1,%2,%4; \n\t"
"mad.lo.cc.u32 %1,%3,%4,%1; \n\t"
"madc.lo.u32 %1,%3,%5,%1; \n\t"
"}\n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
asm("{ // uint2 a*b \n\t"
"mul.lo.u32 %0, %2, %4; \n\t"
"mul.hi.u32 %1, %2, %4; \n\t"
"mad.lo.cc.u32 %1, %3, %4, %1; \n\t"
"madc.lo.u32 %1, %3, %5, %1; \n\t"
"}\n" : "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b.x), "r"(b.y));
return result;
#else
// incorrect but unused host equiv
@@ -606,6 +576,37 @@ uint2 SWAPUINT2(uint2 value)
return make_uint2(value.y, value.x);
}
/* Byte aligned Rotations (lyra2) */
#ifdef __CUDA_ARCH__
__device__ __inline__ uint2 ROL8(const uint2 a)
{
uint2 result;
result.x = __byte_perm(a.y, a.x, 0x6543);
result.y = __byte_perm(a.y, a.x, 0x2107);
return result;
}
__device__ __inline__ uint2 ROR16(const uint2 a)
{
uint2 result;
result.x = __byte_perm(a.y, a.x, 0x1076);
result.y = __byte_perm(a.y, a.x, 0x5432);
return result;
}
__device__ __inline__ uint2 ROR24(const uint2 a)
{
uint2 result;
result.x = __byte_perm(a.y, a.x, 0x2107);
result.y = __byte_perm(a.y, a.x, 0x6543);
return result;
}
#else
#define ROL8(u) ROL2(u, 8)
#define ROR16(u) ROR2(u,16)
#define ROR24(u) ROR2(u,24)
#endif
/* uint2 for bmw512 - to double check later */
__device__ __forceinline__
@@ -614,17 +615,15 @@ static uint2 SHL2(uint2 a, int offset)
#if __CUDA_ARCH__ > 300
uint2 result;
if (offset < 32) {
asm("{\n\t"
"shf.l.clamp.b32 %1,%2,%3,%4; \n\t"
"shl.b32 %0,%2,%4; \n\t"
"}\n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(offset));
asm("{ // SHL2 (l) \n\t"
"shf.l.clamp.b32 %1, %2, %3, %4; \n\t"
"shl.b32 %0, %2, %4; \n\t"
"}\n" : "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(offset));
} else {
asm("{\n\t"
"shf.l.clamp.b32 %1,%2,%3,%4; \n\t"
"shl.b32 %0,%2,%4; \n\t"
"}\n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.y), "r"(a.x), "r"(offset));
asm("{ // SHL2 (h) \n\t"
"shf.l.clamp.b32 %1, %2, %3, %4; \n\t"
"shl.b32 %0, %2, %4; \n\t"
"}\n" : "=r"(result.x), "=r"(result.y) : "r"(a.y), "r"(a.x), "r"(offset));
}
return result;
#else
@@ -670,4 +669,14 @@ static uint2 SHR2(uint2 a, int offset)
#endif
}
// CUDA 9+ deprecated functions warnings (new mask param)
#if CUDA_VERSION >= 9000 && __CUDA_ARCH__ >= 300
#undef __shfl
#define __shfl(var, srcLane, width) __shfl_sync(0xFFFFFFFFu, var, srcLane, width)
#undef __shfl_up
#define __shfl_up(var, delta, width) __shfl_up_sync(0xFFFFFFFF, var, delta, width)
#undef __any
#define __any(p) __any_sync(0xFFFFFFFFu, p)
#endif
#endif // #ifndef CUDA_HELPER_H
+264 -292
View File
@@ -5,6 +5,12 @@
#include "cuda_helper.h"
#ifdef __INTELLISENSE__
#define __CUDA_ARCH__ 500
#define __funnelshift_r(x,y,n) (x >> n)
#define atomicExch(p,x) x
#endif
#if __CUDA_ARCH__ >= 300
// 64 Registers Variant for Compute 3.0
#include "quark/groestl_functions_quad.h"
@@ -12,290 +18,276 @@
#endif
// globaler Speicher für alle HeftyHashes aller Threads
__constant__ uint32_t pTarget[8]; // Single GPU
uint32_t *d_outputHashes[MAX_GPUS];
static uint32_t *d_resultNonce[MAX_GPUS];
static uint32_t *d_outputHashes[MAX_GPUS];
static uint32_t *d_resultNonces[MAX_GPUS];
__constant__ uint32_t pTarget[2]; // Same for all GPU
__constant__ uint32_t myriadgroestl_gpu_msg[32];
// muss expandiert werden
__constant__ uint32_t myr_sha256_gpu_constantTable[64];
__constant__ uint32_t myr_sha256_gpu_constantTable2[64];
__constant__ uint32_t myr_sha256_gpu_hashTable[8];
uint32_t myr_sha256_cpu_hashTable[] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
uint32_t myr_sha256_cpu_constantTable[] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
const uint32_t myr_sha256_cpu_constantTable[] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
};
uint32_t myr_sha256_cpu_w2Table[] = {
0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200,
0x80000000, 0x01400000, 0x00205000, 0x00005088, 0x22000800, 0x22550014, 0x05089742, 0xa0000020,
0x5a880000, 0x005c9400, 0x0016d49d, 0xfa801f00, 0xd33225d0, 0x11675959, 0xf6e6bfda, 0xb30c1549,
0x08b2b050, 0x9d7c4c27, 0x0ce2a393, 0x88e6e1ea, 0xa52b4335, 0x67a16f49, 0xd732016f, 0x4eeb2e91,
0x5dbf55e5, 0x8eee2335, 0xe2bc5ec2, 0xa83f4394, 0x45ad78f7, 0x36f3d0cd, 0xd99c05e8, 0xb0511dc7,
0x69bc7ac4, 0xbd11375b, 0xe3ba71e5, 0x3b209ff2, 0x18feee17, 0xe25ad9e7, 0x13375046, 0x0515089d,
0x4f0d0f04, 0x2627484e, 0x310128d2, 0xc668b434, 0x420841cc, 0x62d311b8, 0xe59ba771, 0x85a7a484 };
const uint32_t myr_sha256_cpu_w2Table[] = {
0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200,
0x80000000, 0x01400000, 0x00205000, 0x00005088, 0x22000800, 0x22550014, 0x05089742, 0xa0000020,
0x5a880000, 0x005c9400, 0x0016d49d, 0xfa801f00, 0xd33225d0, 0x11675959, 0xf6e6bfda, 0xb30c1549,
0x08b2b050, 0x9d7c4c27, 0x0ce2a393, 0x88e6e1ea, 0xa52b4335, 0x67a16f49, 0xd732016f, 0x4eeb2e91,
0x5dbf55e5, 0x8eee2335, 0xe2bc5ec2, 0xa83f4394, 0x45ad78f7, 0x36f3d0cd, 0xd99c05e8, 0xb0511dc7,
0x69bc7ac4, 0xbd11375b, 0xe3ba71e5, 0x3b209ff2, 0x18feee17, 0xe25ad9e7, 0x13375046, 0x0515089d,
0x4f0d0f04, 0x2627484e, 0x310128d2, 0xc668b434, 0x420841cc, 0x62d311b8, 0xe59ba771, 0x85a7a484
};
#define SWAB32(x) ( ((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24) )
#define SWAB32(x) cuda_swab32(x)
#if __CUDA_ARCH__ < 320
// Kepler (Compute 3.0)
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
// Kepler (Compute 3.0)
#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#else
// Kepler (Compute 3.5)
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
// Kepler (Compute 3.5)
#define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
#endif
#define R(x, n) ((x) >> (n))
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
#define R(x, n) ((x) >> (n))
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
#define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22))
#define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25))
#define s0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ R(x, 3))
#define s1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ R(x, 10))
#define S0(x) (ROTR32(x, 2) ^ ROTR32(x, 13) ^ ROTR32(x, 22))
#define S1(x) (ROTR32(x, 6) ^ ROTR32(x, 11) ^ ROTR32(x, 25))
#define s0(x) (ROTR32(x, 7) ^ ROTR32(x, 18) ^ R(x, 3))
#define s1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ R(x, 10))
__device__ void myriadgroestl_gpu_sha256(uint32_t *message)
__device__ __forceinline__
void myriadgroestl_gpu_sha256(uint32_t *message)
{
uint32_t W1[16];
uint32_t W2[16];
uint32_t W1[16];
#pragma unroll
for(int k=0; k<16; k++)
W1[k] = SWAB32(message[k]);
// Initialisiere die register a bis h mit der Hash-Tabelle
uint32_t regs[8];
uint32_t hash[8];
uint32_t regs[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
// pre
#pragma unroll 8
for (int k=0; k < 8; k++)
{
regs[k] = myr_sha256_gpu_hashTable[k];
hash[k] = regs[k];
}
// Progress W1
#pragma unroll
for(int j=0; j<16; j++)
{
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j] + W1[j];
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
#pragma unroll 16
for(int k=0;k<16;k++)
W1[k] = SWAB32(message[k]);
#pragma unroll 7
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
regs[0] = T1 + T2;
regs[4] += T1;
}
// Progress W1
#pragma unroll 16
for(int j=0;j<16;j++)
{
uint32_t T1, T2;
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j] + W1[j];
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
// Progress W2...W3
uint32_t W2[16];
#pragma unroll 7
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
regs[0] = T1 + T2;
regs[4] += T1;
}
////// PART 1
#pragma unroll
for(int j=0; j<2; j++)
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
// Progress W2...W3
////// PART 1
#pragma unroll 2
for(int j=0;j<2;j++)
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
#pragma unroll 5
for(int j=2;j<7;j++)
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
#pragma unroll 5
for(int j=2; j<7;j++)
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
#pragma unroll 8
for(int j=7;j<15;j++)
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
#pragma unroll
for(int j=7; j<15; j++)
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
// Rundenfunktion
#pragma unroll 16
for(int j=0;j<16;j++)
{
uint32_t T1, T2;
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 16] + W2[j];
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
// Round function
#pragma unroll
for(int j=0; j<16; j++)
{
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 16] + W2[j];
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
////// PART 2
#pragma unroll 2
for(int j=0;j<2;j++)
W1[j] = s1(W2[14+j]) + W2[9+j] + s0(W2[1+j]) + W2[j];
#pragma unroll 5
for(int j=2;j<7;j++)
W1[j] = s1(W1[j-2]) + W2[9+j] + s0(W2[1+j]) + W2[j];
////// PART 2
#pragma unroll
for(int j=0; j<2; j++)
W1[j] = s1(W2[14+j]) + W2[9+j] + s0(W2[1+j]) + W2[j];
#pragma unroll 5
for(int j=2; j<7; j++)
W1[j] = s1(W1[j-2]) + W2[9+j] + s0(W2[1+j]) + W2[j];
#pragma unroll 8
for(int j=7;j<15;j++)
W1[j] = s1(W1[j-2]) + W1[j-7] + s0(W2[1+j]) + W2[j];
#pragma unroll
for(int j=7; j<15; j++)
W1[j] = s1(W1[j-2]) + W1[j-7] + s0(W2[1+j]) + W2[j];
W1[15] = s1(W1[13]) + W1[8] + s0(W1[0]) + W2[15];
W1[15] = s1(W1[13]) + W1[8] + s0(W1[0]) + W2[15];
// Rundenfunktion
#pragma unroll 16
for(int j=0;j<16;j++)
{
uint32_t T1, T2;
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 32] + W1[j];
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
// Round function
#pragma unroll
for(int j=0; j<16; j++)
{
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 32] + W1[j];
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
////// PART 3
#pragma unroll 2
for(int j=0;j<2;j++)
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
#pragma unroll 5
for(int j=2;j<7;j++)
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
////// PART 3
#pragma unroll
for(int j=0; j<2; j++)
W2[j] = s1(W1[14+j]) + W1[9+j] + s0(W1[1+j]) + W1[j];
#pragma unroll 8
for(int j=7;j<15;j++)
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
#pragma unroll 5
for(int j=2; j<7; j++)
W2[j] = s1(W2[j-2]) + W1[9+j] + s0(W1[1+j]) + W1[j];
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
#pragma unroll
for(int j=7; j<15; j++)
W2[j] = s1(W2[j-2]) + W2[j-7] + s0(W1[1+j]) + W1[j];
// Rundenfunktion
#pragma unroll 16
for(int j=0;j<16;j++)
{
uint32_t T1, T2;
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 48] + W2[j];
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
W2[15] = s1(W2[13]) + W2[8] + s0(W2[0]) + W1[15];
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
// Round function
#pragma unroll
for(int j=0; j<16; j++)
{
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable[j + 48] + W2[j];
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
#pragma unroll 8
for(int k=0;k<8;k++)
hash[k] += regs[k];
#pragma unroll 7
for (int l=6; l >= 0; l--) regs[l+1] = regs[l];
regs[0] = T1 + T2;
regs[4] += T1;
}
/////
///// Zweite Runde (wegen Msg-Padding)
/////
#pragma unroll 8
for(int k=0;k<8;k++)
regs[k] = hash[k];
uint32_t hash[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
// Progress W1
#pragma unroll 64
for(int j=0;j<64;j++)
{
uint32_t T1, T2;
T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable2[j];
T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
#pragma unroll 8
for(int k=0; k<8; k++)
hash[k] += regs[k];
#pragma unroll 7
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
regs[0] = T1 + T2;
regs[4] += T1;
}
/////
///// 2nd Round (wegen Msg-Padding)
/////
#pragma unroll
for(int k=0; k<8; k++)
regs[k] = hash[k];
#pragma unroll 8
for(int k=0;k<8;k++)
hash[k] += regs[k];
// Progress W1
#pragma unroll
for(int j=0; j<64; j++)
{
uint32_t T1 = regs[7] + S1(regs[4]) + Ch(regs[4], regs[5], regs[6]) + myr_sha256_gpu_constantTable2[j];
uint32_t T2 = S0(regs[0]) + Maj(regs[0], regs[1], regs[2]);
//// FERTIG
#pragma unroll 7
for (int k=6; k >= 0; k--) regs[k+1] = regs[k];
regs[0] = T1 + T2;
regs[4] += T1;
}
#pragma unroll 8
for(int k=0;k<8;k++)
message[k] = SWAB32(hash[k]);
}
#if 0
// Full sha hash
#pragma unroll
for(int k=0; k<8; k++)
hash[k] += regs[k];
__global__ void __launch_bounds__(256, 4)
myriadgroestl_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer)
{
#if __CUDA_ARCH__ >= 300
// durch 4 dividieren, weil jeweils 4 Threads zusammen ein Hash berechnen
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) / 4;
if (thread < threads)
{
// GROESTL
uint32_t paddedInput[8];
#pragma unroll 8
for(int k=0;k<8;k++) paddedInput[k] = myriadgroestl_gpu_msg[4*k+threadIdx.x%4];
uint32_t nounce = startNounce + thread;
if ((threadIdx.x % 4) == 3)
paddedInput[4] = SWAB32(nounce); // 4*4+3 = 19
uint32_t msgBitsliced[8];
to_bitslice_quad(paddedInput, msgBitsliced);
uint32_t state[8];
groestl512_progressMessage_quad(state, msgBitsliced);
uint32_t out_state[16];
from_bitslice_quad(state, out_state);
if ((threadIdx.x & 0x03) == 0)
{
uint32_t *outpHash = &hashBuffer[16 * thread];
#pragma unroll 16
for(int k=0;k<16;k++) outpHash[k] = out_state[k];
}
}
#pragma unroll
for(int k=0; k<8; k++)
message[k] = SWAB32(hash[k]);
#else
message[6] = SWAB32(hash[6] + regs[6]);
message[7] = SWAB32(hash[7] + regs[7]);
#endif
}
__global__ void
myriadgroestl_gpu_hash_quad2(uint32_t threads, uint32_t startNounce, uint32_t *resNounce, uint32_t *hashBuffer)
__global__
//__launch_bounds__(256, 6) // we want <= 40 regs
void myriadgroestl_gpu_hash_sha(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer, uint32_t *resNonces)
{
#if __CUDA_ARCH__ >= 300
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t nounce = startNounce + thread;
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
const uint32_t nonce = startNounce + thread;
uint32_t out_state[16];
uint32_t *inpHash = &hashBuffer[16 * thread];
#pragma unroll 16
for (int i=0; i < 16; i++)
out_state[i] = inpHash[i];
uint32_t out_state[16];
uint32_t *inpHash = &hashBuffer[16 * thread];
myriadgroestl_gpu_sha256(out_state);
#pragma unroll 16
for (int i=0; i < 16; i++)
out_state[i] = inpHash[i];
int i, position = -1;
bool rc = true;
myriadgroestl_gpu_sha256(out_state);
#pragma unroll 8
for (i = 7; i >= 0; i--) {
if (out_state[i] > pTarget[i]) {
if(position < i) {
position = i;
rc = false;
}
}
if (out_state[i] < pTarget[i]) {
if(position < i) {
position = i;
rc = true;
}
}
}
if (out_state[7] <= pTarget[1] && out_state[6] <= pTarget[0])
{
uint32_t tmp = atomicExch(&resNonces[0], nonce);
if (tmp != UINT32_MAX)
resNonces[1] = tmp;
}
}
#endif
}
if(rc == true)
if(resNounce[0] > nounce)
resNounce[0] = nounce;
}
__global__
__launch_bounds__(256, 4)
void myriadgroestl_gpu_hash_quad(uint32_t threads, uint32_t startNounce, uint32_t *hashBuffer)
{
#if __CUDA_ARCH__ >= 300
// durch 4 dividieren, weil jeweils 4 Threads zusammen ein Hash berechnen
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x) / 4;
if (thread < threads)
{
// GROESTL
uint32_t paddedInput[8];
#pragma unroll 8
for(int k=0; k<8; k++)
paddedInput[k] = myriadgroestl_gpu_msg[4*k+threadIdx.x%4];
uint32_t nounce = startNounce + thread;
if ((threadIdx.x % 4) == 3)
paddedInput[4] = SWAB32(nounce); // 4*4+3 = 19
uint32_t msgBitsliced[8];
to_bitslice_quad(paddedInput, msgBitsliced);
uint32_t state[8];
groestl512_progressMessage_quad(state, msgBitsliced);
uint32_t out_state[16];
from_bitslice_quad(state, out_state);
if ((threadIdx.x & 0x03) == 0)
{
uint32_t *outpHash = &hashBuffer[16 * thread];
#pragma unroll 16
for(int k=0; k<16; k++) outpHash[k] = out_state[k];
}
}
#endif
}
@@ -303,86 +295,66 @@ __global__ void
__host__
void myriadgroestl_cpu_init(int thr_id, uint32_t threads)
{
cudaMemcpyToSymbol( myr_sha256_gpu_hashTable,
myr_sha256_cpu_hashTable,
sizeof(uint32_t) * 8 );
uint32_t temp[64];
for(int i=0; i<64; i++)
temp[i] = myr_sha256_cpu_w2Table[i] + myr_sha256_cpu_constantTable[i];
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable,
myr_sha256_cpu_constantTable,
sizeof(uint32_t) * 64 );
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable2, temp, sizeof(uint32_t) * 64 );
// zweite CPU-Tabelle bauen und auf die GPU laden
uint32_t temp[64];
for(int i=0;i<64;i++)
temp[i] = myr_sha256_cpu_w2Table[i] + myr_sha256_cpu_constantTable[i];
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable,
myr_sha256_cpu_constantTable,
sizeof(uint32_t) * 64 );
cudaMemcpyToSymbol( myr_sha256_gpu_constantTable2,
temp,
sizeof(uint32_t) * 64 );
// to check if the binary supports SM3+
cuda_get_arch(thr_id);
// Speicher für Gewinner-Nonce belegen
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
// Speicher für temporäreHashes
cudaMalloc(&d_outputHashes[thr_id], 16*sizeof(uint32_t)*threads);
cudaMalloc(&d_outputHashes[thr_id], (size_t) 64 * threads);
cudaMalloc(&d_resultNonces[thr_id], 2 * sizeof(uint32_t));
}
__host__
void myriadgroestl_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
void myriadgroestl_cpu_free(int thr_id)
{
// Nachricht expandieren und setzen
uint32_t msgBlock[32];
memset(msgBlock, 0, sizeof(uint32_t) * 32);
memcpy(&msgBlock[0], data, 80);
// Erweitere die Nachricht auf den Nachrichtenblock (padding)
// Unsere Nachricht hat 80 Byte
msgBlock[20] = 0x80;
msgBlock[31] = 0x01000000;
// groestl512 braucht hierfür keinen CPU-Code (die einzige Runde wird
// auf der GPU ausgeführt)
// Blockheader setzen (korrekte Nonce und Hefty Hash fehlen da drin noch)
cudaMemcpyToSymbol( myriadgroestl_gpu_msg,
msgBlock,
128);
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
cudaMemcpyToSymbol( pTarget,
pTargetIn,
sizeof(uint32_t) * 8 );
cudaFree(d_outputHashes[thr_id]);
cudaFree(d_resultNonces[thr_id]);
}
__host__
void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce)
void myriadgroestl_cpu_setBlock(int thr_id, void *data, uint32_t *pTargetIn)
{
uint32_t threadsperblock = 256;
uint32_t msgBlock[32] = { 0 };
memcpy(&msgBlock[0], data, 80);
msgBlock[20] = 0x80;
msgBlock[31] = 0x01000000;
// Compute 3.0 benutzt die registeroptimierte Quad Variante mit Warp Shuffle
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
const int factor=4;
cudaMemcpyToSymbol(myriadgroestl_gpu_msg, msgBlock, 128);
cudaMemcpyToSymbol(pTarget, &pTargetIn[6], 2 * sizeof(uint32_t));
}
// Größe des dynamischen Shared Memory Bereichs
size_t shared_size = 0;
__host__
void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
{
uint32_t threadsperblock = 256;
cudaMemset(d_resultNonce[thr_id], 0xFF, sizeof(uint32_t));
// berechne wie viele Thread Blocks wir brauchen
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
dim3 block(threadsperblock);
cudaMemset(d_resultNonces[thr_id], 0xFF, 2 * sizeof(uint32_t));
if (device_sm[device_map[thr_id]] < 300) {
printf("Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
return;
}
// Compute 3.0 benutzt die registeroptimierte Quad Variante mit Warp Shuffle
// mit den Quad Funktionen brauchen wir jetzt 4 threads pro Hash, daher Faktor 4 bei der Blockzahl
const int factor = 4;
myriadgroestl_gpu_hash_quad<<<grid, block, shared_size>>>(threads, startNounce, d_outputHashes[thr_id]);
dim3 grid2((threads + threadsperblock-1)/threadsperblock);
myriadgroestl_gpu_hash_quad2<<<grid2, block, shared_size>>>(threads, startNounce, d_resultNonce[thr_id], d_outputHashes[thr_id]);
dim3 grid(factor*((threads + threadsperblock-1)/threadsperblock));
dim3 block(threadsperblock);
// Strategisches Sleep Kommando zur Senkung der CPU Last
MyStreamSynchronize(NULL, 0, thr_id);
int dev_id = device_map[thr_id];
if (device_sm[dev_id] < 300 || cuda_arch[dev_id] < 300) {
printf("Sorry, This algo is not supported by this GPU arch (SM 3.0 required)");
return;
}
cudaMemcpy(nounce, d_resultNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
myriadgroestl_gpu_hash_quad <<< grid, block >>> (threads, startNounce, d_outputHashes[thr_id]);
dim3 grid2((threads + threadsperblock-1)/threadsperblock);
myriadgroestl_gpu_hash_sha <<< grid2, block >>> (threads, startNounce, d_outputHashes[thr_id], d_resultNonces[thr_id]);
cudaMemcpy(resNounce, d_resultNonces[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
}
-145
View File
@@ -1,145 +0,0 @@
extern "C"
{
#include "sph/sph_blake.h"
#include "sph/sph_groestl.h"
#include "sph/sph_skein.h"
#include "sph/sph_jh.h"
#include "sph/sph_keccak.h"
}
#include "miner.h"
#include "cuda_helper.h"
static uint32_t *d_hash[MAX_GPUS];
extern void quark_blake512_cpu_init(int thr_id, uint32_t threads);
extern void quark_blake512_cpu_setBlock_80(int thr_id, uint32_t *pdata);
extern void quark_blake512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash);
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
// Original nist5hash Funktion aus einem miner Quelltext
extern "C" void nist5hash(void *state, const void *input)
{
sph_blake512_context ctx_blake;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
uint8_t hash[64];
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, input, 80);
sph_blake512_close(&ctx_blake, (void*) hash);
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
sph_groestl512_close(&ctx_groestl, (void*) hash);
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, (const void*) hash, 64);
sph_jh512_close(&ctx_jh, (void*) hash);
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, (const void*) hash, 64);
sph_keccak512_close(&ctx_keccak, (void*) hash);
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, (const void*) hash, 64);
sph_skein512_close(&ctx_skein, (void*) hash);
memcpy(state, hash, 32);
}
static bool init[MAX_GPUS] = { 0 };
extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce,
unsigned long *hashes_done)
{
const uint32_t first_nonce = pdata[19];
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 20); // 256*256*16
throughput = min(throughput, (max_nonce - first_nonce));
if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x00FF;
if (!init[thr_id])
{
cudaSetDevice(device_map[thr_id]);
// Konstanten kopieren, Speicher belegen
quark_blake512_cpu_init(thr_id, throughput);
quark_groestl512_cpu_init(thr_id, throughput);
quark_jh512_cpu_init(thr_id, throughput);
quark_keccak512_cpu_init(thr_id, throughput);
quark_skein512_cpu_init(thr_id, throughput);
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 16 * sizeof(uint32_t) * throughput));
cuda_check_cpu_init(thr_id, throughput);
init[thr_id] = true;
}
uint32_t endiandata[20];
for (int k=0; k < 20; k++)
be32enc(&endiandata[k], pdata[k]);
quark_blake512_cpu_setBlock_80(thr_id, endiandata);
cuda_check_cpu_setTarget(ptarget);
do {
int order = 0;
// Hash with CUDA
quark_blake512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); order++;
quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
if (foundNonce != UINT32_MAX)
{
const uint32_t Htarg = ptarget[7];
uint32_t vhash64[8];
be32enc(&endiandata[19], foundNonce);
nist5hash(vhash64, endiandata);
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
int res = 1;
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
*hashes_done = pdata[19] - first_nonce + throughput;
if (secNonce != 0) {
pdata[21] = secNonce;
res++;
}
pdata[19] = foundNonce;
return res;
}
else {
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
}
}
pdata[19] += throughput;
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
*hashes_done = pdata[19] - first_nonce + 1;
return 0;
}
+6 -1
View File
@@ -708,6 +708,12 @@ __host__
void skeincoin_init(int thr_id)
{
cuda_get_arch(thr_id);
CUDA_SAFE_CALL(cudaMalloc(&d_found[thr_id], 2 * sizeof(uint32_t)));
}
__host__
void skeincoin_free(int thr_id) {
cudaFree(d_found[thr_id]);
}
__host__
@@ -716,7 +722,6 @@ void skeincoin_setBlock_80(int thr_id, void *pdata)
uint64_t message[16];
memcpy(&message[0], pdata, 80);
CUDA_SAFE_CALL(cudaMalloc(&(d_found[thr_id]), 2 * sizeof(uint32_t)));
cudaMemcpyToSymbol(c_message16, &message[8], 16, 0, cudaMemcpyHostToDevice);
precalc(message);
-248
View File
@@ -1,248 +0,0 @@
#ifndef CUDA_VECTOR_H
#define CUDA_VECTOR_H
///////////////////////////////////////////////////////////////////////////////////
#if (defined(_MSC_VER) && defined(_WIN64)) || defined(__LP64__)
#define __LDG_PTR "l"
#else
#define __LDG_PTR "r"
#endif
#include "cuda_helper.h"
//typedef __device_builtin__ struct ulong16 ulong16;
typedef struct __align__(32) uint8
{
unsigned int s0, s1, s2, s3, s4, s5, s6, s7;
} uint8;
typedef struct __align__(64) uint16
{
union {
struct {unsigned int s0, s1, s2, s3, s4, s5, s6, s7;};
uint8 lo;
};
union {
struct {unsigned int s8, s9, sa, sb, sc, sd, se, sf;};
uint8 hi;
};
} uint16;
static __inline__ __host__ __device__ uint16 make_uint16(
unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4, unsigned int s5, unsigned int s6, unsigned int s7,
unsigned int s8, unsigned int s9, unsigned int sa, unsigned int sb, unsigned int sc, unsigned int sd, unsigned int se, unsigned int sf)
{
uint16 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
t.s8 = s8; t.s9 = s9; t.sa = sa; t.sb = sb; t.sc = sc; t.sd = sd; t.se = se; t.sf = sf;
return t;
}
static __inline__ __host__ __device__ uint16 make_uint16(const uint8 &a, const uint8 &b)
{
uint16 t; t.lo=a; t.hi=b; return t;
}
static __inline__ __host__ __device__ uint8 make_uint8(
unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4, unsigned int s5, unsigned int s6, unsigned int s7)
{
uint8 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
return t;
}
static __forceinline__ __device__ uchar4 operator^ (uchar4 a, uchar4 b) { return make_uchar4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); }
static __forceinline__ __device__ uchar4 operator+ (uchar4 a, uchar4 b) { return make_uchar4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
static __forceinline__ __device__ uint4 operator^ (uint4 a, uint4 b) { return make_uint4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); }
static __forceinline__ __device__ uint4 operator+ (uint4 a, uint4 b) { return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
static __forceinline__ __device__ ulonglong4 operator^ (ulonglong4 a, ulonglong4 b) { return make_ulonglong4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); }
static __forceinline__ __device__ ulonglong4 operator+ (ulonglong4 a, ulonglong4 b) { return make_ulonglong4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
static __forceinline__ __device__ ulonglong2 operator^ (ulonglong2 a, ulonglong2 b) { return make_ulonglong2(a.x ^ b.x, a.y ^ b.y); }
static __forceinline__ __device__ __host__ uint8 operator^ (const uint8 &a, const uint8 &b) { return make_uint8(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7); }
static __forceinline__ __device__ __host__ uint8 operator+ (const uint8 &a, const uint8 &b) { return make_uint8(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7); }
static __forceinline__ __device__ __host__ uint16 operator^ (const uint16 &a, const uint16 &b) {
return make_uint16(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7,
a.s8 ^ b.s8, a.s9 ^ b.s9, a.sa ^ b.sa, a.sb ^ b.sb, a.sc ^ b.sc, a.sd ^ b.sd, a.se ^ b.se, a.sf ^ b.sf);
}
static __forceinline__ __device__ __host__ uint16 operator+ (const uint16 &a, const uint16 &b) {
return make_uint16(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7,
a.s8 + b.s8, a.s9 + b.s9, a.sa + b.sa, a.sb + b.sb, a.sc + b.sc, a.sd + b.sd, a.se + b.se, a.sf + b.sf);
}
static __forceinline__ __device__ void operator^= (uint4 &a, uint4 b) { a = a ^ b; }
static __forceinline__ __device__ void operator^= (uchar4 &a, uchar4 b) { a = a ^ b; }
static __forceinline__ __device__ __host__ void operator^= (uint8 &a, const uint8 &b) { a = a ^ b; }
static __forceinline__ __device__ __host__ void operator^= (uint16 &a, const uint16 &b) { a = a ^ b; }
static __forceinline__ __device__ void operator^= (ulonglong4 &a, const ulonglong4 &b) { a = a ^ b; }
static __forceinline__ __device__ void operator^= (ulonglong2 &a, const ulonglong2 &b) { a = a ^ b; }
static __forceinline__ __device__ void operator+= (uint4 &a, uint4 b) { a = a + b; }
static __forceinline__ __device__ void operator+= (uchar4 &a, uchar4 b) { a = a + b; }
static __forceinline__ __device__ __host__ void operator+= (uint8 &a, const uint8 &b) { a = a + b; }
static __forceinline__ __device__ __host__ void operator+= (uint16 &a, const uint16 &b) { a = a + b; }
#if __CUDA_ARCH__ < 320
#define rotateL ROTL32
#define rotateR ROTR32
#else
static __forceinline__ __device__ uint32_t rotateL(uint32_t vec4, uint32_t shift)
{
uint32_t ret;
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret) : "r"(vec4), "r"(vec4), "r"(shift));
return ret;
}
static __forceinline__ __device__ uint32_t rotateR(uint32_t vec4, uint32_t shift)
{
uint32_t ret;
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret) : "r"(vec4), "r"(vec4), "r"(shift));
return ret;
}
static __device__ __inline__ uint8 __ldg8(const uint8_t *ptr)
{
uint8 test;
asm volatile ("ld.global.nc.v4.u32 {%0,%1,%2,%3},[%4];" : "=r"(test.s0), "=r"(test.s1), "=r"(test.s2), "=r"(test.s3) : __LDG_PTR(ptr));
asm volatile ("ld.global.nc.v4.u32 {%0,%1,%2,%3},[%4+16];" : "=r"(test.s4), "=r"(test.s5), "=r"(test.s6), "=r"(test.s7) : __LDG_PTR(ptr));
return (test);
}
static __device__ __inline__ uint32_t __ldgtoint(const uint8_t *ptr)
{
uint32_t test;
asm volatile ("ld.global.nc.u32 {%0},[%1];" : "=r"(test) : __LDG_PTR(ptr));
return (test);
}
static __device__ __inline__ uint32_t __ldgtoint64(const uint8_t *ptr)
{
uint64_t test;
asm volatile ("ld.global.nc.u64 {%0},[%1];" : "=l"(test) : __LDG_PTR(ptr));
return (test);
}
static __device__ __inline__ uint32_t __ldgtoint_unaligned(const uint8_t *ptr)
{
uint32_t test;
asm volatile ("{\n\t"
".reg .u8 a,b,c,d; \n\t"
"ld.global.nc.u8 a,[%1]; \n\t"
"ld.global.nc.u8 b,[%1+1]; \n\t"
"ld.global.nc.u8 c,[%1+2]; \n\t"
"ld.global.nc.u8 d,[%1+3]; \n\t"
"mov.b32 %0,{a,b,c,d}; }\n\t"
: "=r"(test) : __LDG_PTR(ptr));
return (test);
}
static __device__ __inline__ uint64_t __ldgtoint64_unaligned(const uint8_t *ptr)
{
uint64_t test;
asm volatile ("{\n\t"
".reg .u8 a,b,c,d,e,f,g,h; \n\t"
".reg .u32 i,j; \n\t"
"ld.global.nc.u8 a,[%1]; \n\t"
"ld.global.nc.u8 b,[%1+1]; \n\t"
"ld.global.nc.u8 c,[%1+2]; \n\t"
"ld.global.nc.u8 d,[%1+3]; \n\t"
"ld.global.nc.u8 e,[%1+4]; \n\t"
"ld.global.nc.u8 f,[%1+5]; \n\t"
"ld.global.nc.u8 g,[%1+6]; \n\t"
"ld.global.nc.u8 h,[%1+7]; \n\t"
"mov.b32 i,{a,b,c,d}; \n\t"
"mov.b32 j,{e,f,g,h}; \n\t"
"mov.b64 %0,{i,j}; }\n\t"
: "=l"(test) : __LDG_PTR(ptr));
return (test);
}
static __device__ __inline__ uint64_t __ldgtoint64_trunc(const uint8_t *ptr)
{
uint32_t zero = 0;
uint64_t test;
asm volatile ("{\n\t"
".reg .u8 a,b,c,d; \n\t"
".reg .u32 i; \n\t"
"ld.global.nc.u8 a,[%1]; \n\t"
"ld.global.nc.u8 b,[%1+1]; \n\t"
"ld.global.nc.u8 c,[%1+2]; \n\t"
"ld.global.nc.u8 d,[%1+3]; \n\t"
"mov.b32 i,{a,b,c,d}; \n\t"
"mov.b64 %0,{i,%1}; }\n\t"
: "=l"(test) : __LDG_PTR(ptr), "r"(zero));
return (test);
}
static __device__ __inline__ uint32_t __ldgtoint_unaligned2(const uint8_t *ptr)
{
uint32_t test;
asm("{\n\t"
".reg .u8 e,b,c,d; \n\t"
"ld.global.nc.u8 e,[%1]; \n\t"
"ld.global.nc.u8 b,[%1+1]; \n\t"
"ld.global.nc.u8 c,[%1+2]; \n\t"
"ld.global.nc.u8 d,[%1+3]; \n\t"
"mov.b32 %0,{e,b,c,d}; }\n\t"
: "=r"(test) : __LDG_PTR(ptr));
return (test);
}
#endif
static __forceinline__ __device__ uint8 swapvec(const uint8 *buf)
{
uint8 vec;
vec.s0 = cuda_swab32(buf[0].s0);
vec.s1 = cuda_swab32(buf[0].s1);
vec.s2 = cuda_swab32(buf[0].s2);
vec.s3 = cuda_swab32(buf[0].s3);
vec.s4 = cuda_swab32(buf[0].s4);
vec.s5 = cuda_swab32(buf[0].s5);
vec.s6 = cuda_swab32(buf[0].s6);
vec.s7 = cuda_swab32(buf[0].s7);
return vec;
}
static __forceinline__ __device__ uint16 swapvec(const uint16 *buf)
{
uint16 vec;
vec.s0 = cuda_swab32(buf[0].s0);
vec.s1 = cuda_swab32(buf[0].s1);
vec.s2 = cuda_swab32(buf[0].s2);
vec.s3 = cuda_swab32(buf[0].s3);
vec.s4 = cuda_swab32(buf[0].s4);
vec.s5 = cuda_swab32(buf[0].s5);
vec.s6 = cuda_swab32(buf[0].s6);
vec.s7 = cuda_swab32(buf[0].s7);
vec.s8 = cuda_swab32(buf[0].s8);
vec.s9 = cuda_swab32(buf[0].s9);
vec.sa = cuda_swab32(buf[0].sa);
vec.sb = cuda_swab32(buf[0].sb);
vec.sc = cuda_swab32(buf[0].sc);
vec.sd = cuda_swab32(buf[0].sd);
vec.se = cuda_swab32(buf[0].se);
vec.sf = cuda_swab32(buf[0].sf);
return vec;
}
#endif // #ifndef CUDA_VECTOR_H
+62
View File
@@ -0,0 +1,62 @@
#ifndef CUDA_VECTOR_UINT2x4_H
#define CUDA_VECTOR_UINT2x4_H
///////////////////////////////////////////////////////////////////////////////////
#if (defined(_MSC_VER) && defined(_WIN64)) || defined(__LP64__)
#define __LDG_PTR "l"
#else
#define __LDG_PTR "r"
#endif
#include "cuda_helper.h"
typedef struct __align__(16) uint2x4 {
uint2 x, y, z, w;
} uint2x4;
static __inline__ __device__ uint2x4 make_uint2x4(uint2 s0, uint2 s1, uint2 s2, uint2 s3)
{
uint2x4 t;
t.x = s0; t.y = s1; t.z = s2; t.w = s3;
return t;
}
static __forceinline__ __device__ uint2x4 operator^ (const uint2x4 &a, const uint2x4 &b) {
return make_uint2x4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
}
static __forceinline__ __device__ uint2x4 operator+ (const uint2x4 &a, const uint2x4 &b) {
return make_uint2x4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
/////////////////////////
static __forceinline__ __device__ void operator^= (uint2x4 &a, const uint2x4 &b) { a = a ^ b; }
static __forceinline__ __device__ void operator+= (uint2x4 &a, const uint2x4 &b) { a = a + b; }
#if __CUDA_ARCH__ >= 320
static __device__ __inline__ uint2x4 __ldg4(const uint2x4 *ptr)
{
uint2x4 ret;
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4];" : "=r"(ret.x.x), "=r"(ret.x.y), "=r"(ret.y.x), "=r"(ret.y.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+16];" : "=r"(ret.z.x), "=r"(ret.z.y), "=r"(ret.w.x), "=r"(ret.w.y) : __LDG_PTR(ptr));
return ret;
}
static __device__ __inline__ void ldg4(const uint2x4 *ptr, uint2x4 *ret)
{
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4];" : "=r"(ret[0].x.x), "=r"(ret[0].x.y), "=r"(ret[0].y.x), "=r"(ret[0].y.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+16];" : "=r"(ret[0].z.x), "=r"(ret[0].z.y), "=r"(ret[0].w.x), "=r"(ret[0].w.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+32];" : "=r"(ret[1].x.x), "=r"(ret[1].x.y), "=r"(ret[1].y.x), "=r"(ret[1].y.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+48];" : "=r"(ret[1].z.x), "=r"(ret[1].z.y), "=r"(ret[1].w.x), "=r"(ret[1].w.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+64];" : "=r"(ret[2].x.x), "=r"(ret[2].x.y), "=r"(ret[2].y.x), "=r"(ret[2].y.y) : __LDG_PTR(ptr));
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+80];" : "=r"(ret[2].z.x), "=r"(ret[2].z.y), "=r"(ret[2].w.x), "=r"(ret[2].w.y) : __LDG_PTR(ptr));
}
#elif !defined(__ldg4)
#define __ldg4(x) (*(x))
#define ldg4(ptr, ret) { *(ret) = (*(ptr)); }
#endif
#endif // H
+47
View File
@@ -0,0 +1,47 @@
#include "cuda_helper.h"
/* Macros for uint2 operations (used by skein) */
__device__ __forceinline__
uint2 ROR8(const uint2 a) {
uint2 result;
result.x = __byte_perm(a.x, a.y, 0x4321);
result.y = __byte_perm(a.y, a.x, 0x4321);
return result;
}
__device__ __forceinline__
uint2 ROL24(const uint2 a) {
uint2 result;
result.x = __byte_perm(a.x, a.y, 0x0765);
result.y = __byte_perm(a.y, a.x, 0x0765);
return result;
}
static __device__ __forceinline__ uint2 operator+ (const uint2 a, const uint32_t b)
{
#if 0 && defined(__CUDA_ARCH__) && CUDA_VERSION < 7000
uint2 result;
asm(
"add.cc.u32 %0,%2,%4; \n\t"
"addc.u32 %1,%3,%5; \n\t"
: "=r"(result.x), "=r"(result.y) : "r"(a.x), "r"(a.y), "r"(b), "r"(0));
return result;
#else
return vectorize(devectorize(a) + b);
#endif
}
/* whirlpool ones */
#ifdef __CUDA_ARCH__
__device__ __forceinline__
uint2 ROL16(const uint2 a) {
uint2 result;
result.x = __byte_perm(a.x, a.y, 0x1076);
result.y = __byte_perm(a.y, a.x, 0x1076);
return result;
}
#else
#define ROL16(a) make_uint2(a.x, a.y) /* bad, just to define it */
#endif
+81
View File
@@ -0,0 +1,81 @@
/*
BLAKE2 reference source code package - optimized C implementations
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#pragma once
#ifndef __BLAKE2_CONFIG_H__
#define __BLAKE2_CONFIG_H__
// These don't work everywhere
#if (defined(__SSE2__) || defined(_M_AMD_64) || defined(_M_X64))
#define HAVE_SSE2
#endif
#if defined(__SSSE3__)
#define HAVE_SSSE3
#endif
#if defined(__SSE4_1__)
#define HAVE_SSE41
#endif
#if defined(__AVX__)
#define HAVE_AVX
#endif
#if defined(__XOP__)
#define HAVE_XOP
#endif
#ifdef HAVE_AVX2
#ifndef HAVE_AVX
#define HAVE_AVX
#endif
#endif
#ifdef HAVE_XOP
#ifndef HAVE_AVX
#define HAVE_AVX
#endif
#endif
#ifdef HAVE_AVX
#ifndef HAVE_SSE41
#define HAVE_SSE41
#endif
#endif
#ifdef HAVE_SSE41
#ifndef HAVE_SSSE3
#define HAVE_SSSE3
#endif
#endif
#ifdef HAVE_SSSE3
#define HAVE_SSE2
#endif
#if !defined(HAVE_SSE2)
#ifdef _MSC_VER
// enforce required stuff for now
#define HAVE_SSE2
//#define HAVE_SSSE3
#define HAVE_SSE41
#else
# error "This code requires at least SSE 4.1"
#endif
#endif
#endif
Loaded 100 of 286 files, more files were not shown because too many files have changed in this diff. Show more