Skip to content

Commit

Permalink
Merge pull request #69 from kobanium/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yssaya authored Feb 24, 2024
2 parents b452d10 + 179f7b4 commit 577b4c1
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ AobaZeroはShogiGUIでも動作しますがengineに送られてくる局面が
ShogiGUIのページ
<http://shogigui.siganus.com/>

# Compileの仕方は?
[こちら](readme.txt)をご覧ください。

# AobaZeroの紹介ページ
今までに作成した棋譜や重み、棋譜のサンプルなどを公開しています。
<http://www.yss-aya.com/aobazero/>
Expand Down
9 changes: 6 additions & 3 deletions src/common/nnet-ocl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void wmma_mma(uint *mc, __local const uint *ma, __local const uint *mb) {
"r"(mb[SGEMM_NLN*WRAP_SIZE*4]), "r"(mb[SGEMM_NLN*WRAP_SIZE*5]),
"r"(mb[SGEMM_NLN*WRAP_SIZE*6]), "r"(mb[SGEMM_NLN*WRAP_SIZE*7])); }
void wmma_store(__global float *dest, const float *src) {
void wmma_store(__global void *dest, const uint *src) {
asm("{ wmma.store.d.sync.aligned.row" SGEMM_TDM ".global.f16\n"
" [%4], {%0, %1, %2, %3}, %5; }"
:: "r"(src[0]), "r"(src[1]), "r"(src[2]), "r"(src[3]),
Expand All @@ -565,7 +565,7 @@ void wmma_mma(uint *mc, __local const uint *ma, __local const uint *mb) {
"r"(mb[SGEMM_NLN*WRAP_SIZE*4]), "r"(mb[SGEMM_NLN*WRAP_SIZE*5]),
"r"(mb[SGEMM_NLN*WRAP_SIZE*6]), "r"(mb[SGEMM_NLN*WRAP_SIZE*7])); }
void wmma_store(__global float *dest, const float *src) {
void wmma_store(__global void *dest, const uint *src) {
asm("{ wmma.store.d.sync.aligned.row" SGEMM_TDM ".global.f32\n"
" [%8], {%0, %1, %2, %3, %4, %5, %6, %7}, %9; }"
:: "r"(src[0]), "r"(src[1]), "r"(src[2]), "r"(src[3]),
Expand Down Expand Up @@ -642,6 +642,7 @@ void compute_matM(__global const uint *gA, __global const uint *gB,
for (uint upn = 0; upn < SGEMM_NPN; ++upn)
wmma_store(gC + upm*SGEMM_NTM*NN + upn*SGEMM_NTN, &pD[upm][upn][0]); }
#else
__kernel __attribute__((reqd_work_group_size(SGEMM_NLN*WRAP_SIZE,
Expand Down Expand Up @@ -699,7 +700,8 @@ void compute_matM(__global const uint *gA, __global const uint *gB,
gC += ulm*SGEMM_NTM*NN + uln*SGEMM_NTN;
for (uint upm = 0; upm < SGEMM_NPM; ++upm)
for (uint upn = 0; upn < SGEMM_NPN; ++upn)
wmma_store(gC + upm*SGEMM_NLTM*NN + upn*SGEMM_NLTN, &pD[upm][upn][0]); }
wmma_store(gC + upm*SGEMM_NLTM*NN + upn*SGEMM_NLTN, (&pD[upm][upn][0])); }
#endif
)";

Expand Down Expand Up @@ -1240,6 +1242,7 @@ static SgemmParam tune_compute_matM(bool use_half, bool use_wmma,
elapsed = measure_compute_matM(context, param, nbatch, nm0, nn0, nk0,
1U); }
catch (const ErrInt &e) {
cout << "e.what()=" << e.what() << std::endl;
if (! strstr(e.what(), msg_opencl_error)) throw;
elapsed = DBL_MAX; flag_error = true; }
catch (...) { throw; }
Expand Down
4 changes: 2 additions & 2 deletions src/common/param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#pragma once
namespace Ver {
constexpr unsigned char major = 3; // 2...komaochi, 3...Swish
constexpr unsigned char minor = 8; //
constexpr unsigned char minor = 9; //
// usi_engine is no use. MUST increase "minor" for kicking old engine by server. Only major and minor are sent to client.
constexpr unsigned short usi_engine = 41; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero
constexpr unsigned short usi_engine = 42; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero
}

#define AOBA_UNIQUE ".oeWK7ZhnLN"
Expand Down
29 changes: 22 additions & 7 deletions src/playshogi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ playshogiは2つのusiプログラム同士を対戦させます。
条件を満たす手を指した瞬間にplayshogiが判定します)。27点法
3. AobaZeroを使う場合、同時に複数の対戦を走らせ、プロセス間バッチを組むことで高速化できます。
4. 棋譜は標準出力に出ます。
5. 磯崎氏が作成された24手目までの互角定跡集を使って対戦できます
5. 磯崎氏が作成された24手目までの互角局面集を使って対戦できます
http://yaneuraou.yaneu.com/2016/08/24/%E8%87%AA%E5%B7%B1%E5%AF%BE%E5%B1%80%E7%94%A8%E3%81%AB%E4%BA%92%E8%A7%92%E3%81%AE%E5%B1%80%E9%9D%A2%E9%9B%86%E3%82%92%E5%85%AC%E9%96%8B%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F/
records2016_10818.sfen
をカレントディレクトリに置いて下さい。
定跡は起動ごとにランダムに選ばれます。

局面数は起動ごとにランダムに選ばれます。


例:
Expand All @@ -20,6 +19,9 @@ bin/playshogi -rsbm 800 -0 "./bin/aobaz -p 100 -w ./weight/w1198.txt" -1 "./bin/
AobaZero(1手800playout)とKristallweizen(1手200kノード、1スレッド、定跡なし)を対戦させる場合。プロセス間バッチ利用。HALF利用。weightの指定はplayshogi、aobaz、同じものを指定してください(内部で時々GPUの計算とCPUの計算の一致を確認するため)。
bin/playshogi -rsbm 600 -B 7 -P 25 -U 0 -H 1 -c /bin/bash -W ./weight/w1198.txt -0 "./bin/aobaz -p 800 -e 0 -w ./weight/w1198.txt" -1 "~/Kristallweizen/yane483_nnue_avx2 usi , setoption name BookMoves value 0 , setoption Threads value 1 , setoption USI_Hash value 16 , setoption NodesLimit value 200000 , isready" >> w1198_p800_vs_200k.csa

AobaZero(1手800playout)と水匠5(1手300kノード、1スレッド、定跡なし)を対戦させる場合。
bin/playshogi -rsbm 800 -P 18 -B 7 -U 0 -H 1 -c /bin/bash -W ./w4365.txt -0 "./aobazero/bin/aobaz -p 800 -e 0 -w ./w4365.txt" -1 "cd ../suisho5; ./yane750sse42 , isready , setoption name BookMoves value 0 , setoption Threads value 1 , setoption NodesLimit value 300000" >> w4365_s5_750_300k.csa

GPU 0 と GPU 1 を使ってw485とw450を800局対戦。定跡集は使わず。ランダム性としてノイズの追加と最初の30手は確率分布で選択。
bin/playshogi -rsm 800 -P 25 -U 0:1 -B 7:7 -H 1:1 -W w0485.txt:w0450.txt -0 "bin/aobaz -e 0 -p 800 -n -m 30 -w w0485.txt" -1 "bin/aobaz -e 1 -n -m 30 -p 800 -w w0450.txt"

Expand All @@ -29,11 +31,24 @@ bin/playshogi -rsm 800 -P 25 -B 7 -U 0 -H 1 -c /bin/bash -W w1650.txt -0 "bin/ao
2枚落ち。先手が常に下手。"-d 1" は香落ち、以下、角(2)、飛(3)、2枚(4)、4枚(5)、6枚(6)
bin/playshogi -frsm 800 -d 4 -0 "bin/aobaz -p 400 -msafe 30 -w w1525.txt" -1 "bin/aobaz -p 10 -msafe 30 -w w1525.txt" >> 2mai_p400_vs_p10.csa

dlshogiと1手100playoutで。dlshogiはplayoutが指定可能なように改造したもの
bin/playshogi -brsm 400 -i usi0.txt:usi0.txt -c /bin/bash -P 7 -U 0 -B 3 -H 1 -W w4195.txt -0 "./aobaz -p 100 -e 0 -w w4195.txt" -1 "./dlshogi_dr2_exhi/usi/bin/usi_dr2e_po 100" >> w4195_b1t1_p100_vs_dlshogi_dr2_b1t1_100p.csa
$ cat usi0.txt
dlshogiと1手100playoutで。
bin/playshogi -brsm 800 -i usi_dummy.txt:usi_dr2_mb1_p100.txt -c /bin/bash -P 7 -U 0 -B 3 -H 1 -W w4357.txt -0 "./aobaz -p 100 -e 0 -w w4357.txt" -1 "dlshogi_dr2_exhi/usi/bin/usi" >> w4357_vs_dlshogi_dr2_100p.csa
$ cat usi_dr2_mb1_p100.txt
setoption name DNN_Model value /home/yss/shogi/dlshogi_dr2_exhi/model/model-dr2_exhi.onnx
setoption name DNN_Batch_Size value 1
setoption name UCT_Threads value 1
setoption name Const_Playout value 100

"-i" で usi コマンドを送れますが、usi と isready の間の setoption のみを指定します。
指定する場合は必ず2つ必要です。送る必要がない場合は 改行1行だけの usi_dummy.txt を指定します。

usi
...
usiok

ここで指定する setoption を複数行で指定

isready



※ 注意
Expand Down
4 changes: 3 additions & 1 deletion src/usi-engine/bona/shogi.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ extern unsigned char ailast_one[512];
//#define BNZ_VER "38" // 20221110 test get_best_move_alphabeta_usi().
//#define BNZ_VER "39" // 20221221 raw value and policy are recorded in *.csa. Dynamic Variance-Scaled cPUCT. NN is not called for one reply king escape position.
//#define BNZ_VER "40" // 20230519 dfpn is called from all threads. make_book, kldinterval.
#define BNZ_VER "41" // 20231207 kldgain 0.0000004, kldinterval 400, -p 12800, ave playouts is 3180/move.
//#define BNZ_VER "41" // 20231207 kldgain 0.0000004, kldinterval 400, -p 12800, ave playouts is 3180/move.
#define BNZ_VER "42" // 20240214 nDrawMove 0 -> 513 default, MAX_DRAW_MOVES = 513

#define BNZ_NAME "AobaZero"

//#define BNZ_VER "16" // 20210528 komaochi, mate3
Expand Down
1 change: 1 addition & 0 deletions src/usi-engine/bona/yss_dcnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const int B_SIZE = 9;
const int DCNN_CHANNELS = 362;
const int LABEL_CHANNELS = 139; // 11259専用の値

const int MAX_DRAW_MOVES = 513; // 513手目が指せれば引き分け

const int SHOGI_MOVES_MAX = 593;
const float ILLEGAL_MOVE = -1000;
Expand Down
7 changes: 4 additions & 3 deletions src/usi-engine/bona/yss_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,11 @@ void set_dcnn_channels(tree_t * restrict ptree, int sideToMove, int ply, float *
set_dcnn_data( data, base, y,x);
}
float div = 1.0f;
if ( STANDARDIZATION ) div = 512.0f;
// 513手目が指せれば引き分け。floodgateは256手目が指せれば引き分け。選手権は321手目が指せれば引き分け。
if ( STANDARDIZATION ) div = MAX_DRAW_MOVES-1;
// 513手目が指せれば引き分け。floodgateは256手目(513手目、2024年1月7日から)が指せれば引き分け。選手権は321手目が指せれば引き分け。
int tt = t + sfen_current_move_number;
if ( nDrawMove ) {
if ( tt > div ) tt = div;
if ( nDrawMove && nDrawMove < MAX_DRAW_MOVES ) {
int draw = nDrawMove; // 256, 321
int w = 160; // 何手前から増加させるか。256手引き分けでw=60なら196手から増加
if ( draw - w < 0 ) w = draw;
Expand Down
2 changes: 1 addition & 1 deletion src/usi-engine/bona/ysszero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool fRawValuePolicy = true;

int nLimitUctLoop = 100;
double dLimitSec = 0;
int nDrawMove = 0; // 引き分けになる手数。0でなし。floodgateは256, 選手権は321
int nDrawMove = MAX_DRAW_MOVES; // 引き分けになる手数。0でなし。floodgateは256, 選手権は321。学習中も探索内では引き分けに

const float FIXED_RESIGN_WINRATE = 0.10; // 自己対戦でこの勝率以下なら投了。0で投了しない。0.10 で勝率10%。 0 <= x <= +1.0
float resign_winrate = 0;
Expand Down

0 comments on commit 577b4c1

Please sign in to comment.