Justin

Compiling Stockfish

Jul 3rd, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. Protocol to Compile "Stockfish" for Haswell Architecture
  2. -----------------------------------------
  3. 1) Launch MSYS2 (C:\msys64\mingw64.exe) and in the terminal enter the following:
  4.  
  5. wget https://github.com/official-stockfish/Stockfish/archive/master.zip
  6. unzip master.zip
  7. cd Stockfish-master/src
  8.  
  9. 2) Insert the following line into "Makefile" (C:\msys64\home\Justin\Stockfish-master\src) section 3, line 2:
  10.  
  11. CXXFLAGS += -march=native
  12.  
  13.  
  14. 3) Return to cmd and enter the following:
  15.  
  16. gcc -Q -march=native --help=target |egrep "(march|mtune|enabled)"
  17.    
  18. cd Stockfish-master/src
  19.  
  20. make profile-build ARCH=x86-64-bmi2 COMP=gcc -j 4
  21. make profile-build ARCH=x86-64-modern COMP=gcc -j 40
  22.  
  23.  
  24. strip stockfish.exe
  25. or
  26. strip sugar.exe
  27.  
  28. mv stockfish.exe ../../stockfish_x64_bmi2.exe
  29. or
  30. mv sugar.exe ../../S_XPrO.110118.x64.POPCNT.exe
  31.  
  32. make clean
  33. cd
  34. -----------------------------------------
  35.  
  36. (Optional Customizations Only)
  37.  
  38. 4) In Makefile:
  39.  
  40. Replace:
  41. material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o \
  42.  
  43.  material.o misc.o movegen.o movepick.o opt.o pawns.o position.o psqt.o \
  44.  
  45. 5) main.cpp
  46.  
  47. +   void SETUP_PRIVILEGES();
  48. +   void FREE_MEM(void *);
  49. +  
  50.     int main(int argc, char* argv[]) {
  51.  
  52.         std::cout << engine_info() << std::endl;
  53. -
  54. +   #ifndef BENCH
  55. +       SETUP_PRIVILEGES();
  56. +   #endif
  57.         UCI::init(Options);
  58. +   TT.resize(Options["Hash"]);
  59.     PSQT::init();
  60.     Bitboards::init();
  61.     Position::init();
  62.  
  63.     Pawns::init();
  64.     Threads.init();
  65.     Tablebases::init(Options["SyzygyPath"]);
  66.     TT.resize(Options["Hash"]);
  67.  
  68.     UCI::loop(argc, argv);
  69.  
  70. +   if (large_use) {
  71. +   FREE_MEM(TT. mem);
  72. +   TT.mem = nullptr;
  73. +   }
  74. +
  75.     Threads.exit();
  76.     }
  77.  
  78.  
  79. 6) tt.cpp
  80.  
  81. TranspositionTable TT; // Our global transposition table
  82.  
  83. +void CREATE_MEM2(void **,uint64_t);
  84. +void FREE_MEM(void *);
  85.  
  86. Ill TranspositionTable: :resize() sets the size of the transposition table, Ill measured in megabytes. Transposition table consists of a power of 2 number
  87.    
  88. clustercount = newClusterCount;
  89.  
  90. +   mem = nullptr;
  91. +   FREE_MEM(mem);
  92. +   CREATE_MEM2(&mem, clustercount * sizeof(Cluster));
  93. +   large_use = true;
  94. +
  95. + if (!mem)
  96. +   {
  97.     free(mem);
  98.     mem = calloc(clustercount * sizeof(Cluster) + CacheLineSize - 1, 1);
  99. +       large_use = false;
  100. +   }
  101.  
  102. 7) tt.h
  103.  
  104. +   extern int large_use;
  105. +   void FREE_MEM (void *);
  106. +
  107.  
  108. class TranspositionTable {
  109.     static const int cacheLinesize = 64;
  110.  
  111.     static_assert(sizeof(Cluster) == CacheLineSize / 2, "Cluster size incorrect");
  112.  
  113. public:
  114. - ~TranspositionTable() { free(mem); }
  115. + void* mem;
  116. + ~TranspositionTable() { large_use ? FREE_MEM (mem) : free(mem); }
  117.     void new_search() {generations+= 4; } // Lower 2 bits are used by Bound
  118.     uint8_t generation() const { return generations; }
  119.     TTEntry* probe(const Key key, bool& found) const;  
  120.  
  121. private:
  122.     size t clustercount;
  123.     cluster* table;
  124.     void* mem;
  125.     uint8_t generation8; // Size must be not bigger than TTEntry::genBound8
  126.  
  127.     };
  128.  
  129.  
  130.  
  131.  
  132. ------------------------------
  133.  
  134. Finally, in order to customize your engine follow the following steps:
  135.  
  136. 8) misc.cpp
  137.  
  138. const string Version = "";
  139. to
  140.  static const string Version = "SF091015MZ"
  141.  
  142. AND
  143.  
  144. ss << "Stockfish" << Version << setfill('0');
  145. to
  146.  ss << " " << Version << setfill('0');
Add Comment
Please, Sign In to add comment