sha256d.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. float opencl_oclthreads_to_intensity_sha256d(const unsigned long oclthreads)
  28. {
  29. return log2f(oclthreads) - 15.;
  30. }
  31. unsigned long opencl_intensity_to_oclthreads_sha256d(float intensity)
  32. {
  33. return powf(2, intensity + 15);
  34. }
  35. static
  36. char *opencl_get_default_kernel_file_sha256d(const struct mining_algorithm * const malgo, struct cgpu_info * const cgpu, struct _clState * const clState)
  37. {
  38. const char * const vbuff = clState->platform_ver_str;
  39. if (clState->is_mesa)
  40. {
  41. applog(LOG_INFO, "Selecting phatk kernel for Mesa");
  42. return strdup("phatk");
  43. }
  44. /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
  45. if (!strstr(cgpu->name, "Tahiti") &&
  46. (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK
  47. strstr(vbuff, "851.4") || // Windows 64 bit ""
  48. strstr(vbuff, "831.4") ||
  49. strstr(vbuff, "898.1") || // 12.2 driver SDK
  50. strstr(vbuff, "923.1") || // 12.4
  51. strstr(vbuff, "938.2") || // SDK 2.7
  52. strstr(vbuff, "1113.2"))) // SDK 2.8
  53. {
  54. applog(LOG_INFO, "Selecting diablo kernel");
  55. return strdup("diablo");
  56. }
  57. /* Detect all 7970s, older ATI and NVIDIA and use poclbm */
  58. if (strstr(cgpu->name, "Tahiti") || !clState->hasBitAlign)
  59. {
  60. applog(LOG_INFO, "Selecting poclbm kernel");
  61. return strdup("poclbm");
  62. }
  63. /* Use phatk for the rest R5xxx R6xxx */
  64. {
  65. applog(LOG_INFO, "Selecting phatk kernel");
  66. return strdup("phatk");
  67. }
  68. }
  69. #endif /* USE_OPENCL */
  70. struct mining_algorithm malgo_sha256d = {
  71. .name = "SHA256d",
  72. .aliases = "SHA256d|SHA256|SHA2",
  73. .algo = POW_SHA256D,
  74. .ui_skip_hash_bytes = 4,
  75. .worktime_skip_prevblk_u32 = 1,
  76. .reasonable_low_nonce_diff = 1.,
  77. .hash_data_f = hash_data,
  78. #ifdef USE_OPENCL
  79. .opencl_nodefault = true,
  80. .opencl_oclthreads_to_intensity = opencl_oclthreads_to_intensity_sha256d,
  81. .opencl_intensity_to_oclthreads = opencl_intensity_to_oclthreads_sha256d,
  82. .opencl_min_oclthreads = 0x20, // intensity -10
  83. .opencl_max_oclthreads = 0x20000000, // intensity 14
  84. .opencl_get_default_kernel_file = opencl_get_default_kernel_file_sha256d,
  85. #endif
  86. };
  87. static
  88. __attribute__((constructor))
  89. void init_sha256d(void)
  90. {
  91. LL_APPEND(mining_algorithms, (&malgo_sha256d));
  92. }