sha256d.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2012-2014 Luke Dashjr
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #include "config.h"
  10. #include <math.h>
  11. #include <string.h>
  12. #include <uthash.h>
  13. #include "logging.h"
  14. #include "miner.h"
  15. #include "ocl.h"
  16. #include "util.h"
  17. static
  18. void hash_data(void *out_hash, const void *data)
  19. {
  20. unsigned char blkheader[80];
  21. // data is past the first SHA256 step (padding and interpreting as big endian on a little endian platform), so we need to flip each 32-bit chunk around to get the original input block header
  22. swap32yes(blkheader, data, 80 / 4);
  23. // double-SHA256 to get the block hash
  24. gen_hash(blkheader, out_hash, 80);
  25. }
  26. #ifdef USE_OPENCL
  27. static
  28. float opencl_oclthreads_to_intensity_sha256d(const unsigned long oclthreads)
  29. {
  30. return log2f(oclthreads) - 15.;
  31. }
  32. static
  33. unsigned long opencl_intensity_to_oclthreads_sha256d(float intensity)
  34. {
  35. return powf(2, intensity + 15);
  36. }
  37. static
  38. char *opencl_get_default_kernel_file_sha256d(const struct mining_algorithm * const malgo, struct cgpu_info * const cgpu, struct _clState * const clState)
  39. {
  40. const char * const vbuff = clState->platform_ver_str;
  41. if (clState->is_mesa)
  42. {
  43. applog(LOG_INFO, "Selecting phatk kernel for Mesa");
  44. return strdup("phatk");
  45. }
  46. /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
  47. if (!strstr(cgpu->name, "Tahiti") &&
  48. (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK
  49. strstr(vbuff, "851.4") || // Windows 64 bit ""
  50. strstr(vbuff, "831.4") ||
  51. strstr(vbuff, "898.1") || // 12.2 driver SDK
  52. strstr(vbuff, "923.1") || // 12.4
  53. strstr(vbuff, "938.2") || // SDK 2.7
  54. strstr(vbuff, "1113.2"))) // SDK 2.8
  55. {
  56. applog(LOG_INFO, "Selecting diablo kernel");
  57. return strdup("diablo");
  58. }
  59. /* Detect all 7970s, older ATI and NVIDIA and use poclbm */
  60. if (strstr(cgpu->name, "Tahiti") || !clState->hasBitAlign)
  61. {
  62. applog(LOG_INFO, "Selecting poclbm kernel");
  63. return strdup("poclbm");
  64. }
  65. /* Use phatk for the rest R5xxx R6xxx */
  66. {
  67. applog(LOG_INFO, "Selecting phatk kernel");
  68. return strdup("phatk");
  69. }
  70. }
  71. #endif /* USE_OPENCL */
  72. struct mining_algorithm malgo_sha256d = {
  73. .name = "SHA256d",
  74. .aliases = "SHA256d|SHA256|SHA2",
  75. .algo = POW_SHA256D,
  76. .ui_skip_hash_bytes = 4,
  77. .worktime_skip_prevblk_u32 = 1,
  78. .reasonable_low_nonce_diff = 1.,
  79. .hash_data_f = hash_data,
  80. #ifdef USE_OPENCL
  81. .opencl_nodefault = true,
  82. .opencl_oclthreads_to_intensity = opencl_oclthreads_to_intensity_sha256d,
  83. .opencl_intensity_to_oclthreads = opencl_intensity_to_oclthreads_sha256d,
  84. .opencl_min_oclthreads = 0x20, // intensity -10
  85. .opencl_max_oclthreads = 0x20000000, // intensity 14
  86. .opencl_min_nonce_diff = 1.,
  87. .opencl_get_default_kernel_file = opencl_get_default_kernel_file_sha256d,
  88. #endif
  89. };
  90. static
  91. __attribute__((constructor))
  92. void init_sha256d(void)
  93. {
  94. LL_APPEND(mining_algorithms, (&malgo_sha256d));
  95. }