-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Disservin/split-glue-file
Split Glue File & Prepare for Sf 17
- Loading branch information
Showing
6 changed files
with
193 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include <emscripten.h> | ||
#include <emscripten/bind.h> | ||
#include <queue> | ||
|
||
struct Command : public std::streambuf { | ||
enum { UCI, NNUE } type; | ||
std::string uci; | ||
std::shared_ptr<void> ptr = nullptr; | ||
int index; | ||
|
||
Command(const char* text) : type(UCI), uci(text) { std::free((void*)text); } | ||
Command(char* buf, size_t sz, int index) | ||
: type(NNUE), ptr((void*)buf, std::free), index(index) { | ||
setg(buf, buf, buf + sz); | ||
} | ||
|
||
using std::streambuf::seekoff; | ||
using std::streambuf::seekpos; | ||
}; | ||
|
||
struct { | ||
std::mutex m; | ||
std::queue<Command> q; | ||
std::condition_variable cv; | ||
|
||
void push(Command el) { | ||
std::unique_lock<std::mutex> lock(m); | ||
q.push(el); | ||
lock.unlock(); | ||
cv.notify_one(); | ||
} | ||
|
||
Command pop() { | ||
std::unique_lock<std::mutex> lock(m); | ||
while (q.empty()) cv.wait(lock); | ||
Command el = std::move(q.front()); | ||
q.pop(); | ||
return el; | ||
} | ||
} inQ; | ||
|
||
const char* getRecommendedNnueName(int index); | ||
|
||
EMSCRIPTEN_KEEPALIVE std::string js_getline(); | ||
|
||
extern "C" { | ||
EMSCRIPTEN_KEEPALIVE void uci(const char* utf8) { inQ.push(Command(utf8)); } | ||
|
||
EMSCRIPTEN_KEEPALIVE void setNnueBuffer(char* buf, size_t sz, int index) { | ||
inQ.push(Command(buf, sz, index)); | ||
} | ||
|
||
EMSCRIPTEN_KEEPALIVE const char* getRecommendedNnue(int index) { | ||
return getRecommendedNnueName(index); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "glue.hpp" | ||
|
||
#include "evaluate.h" | ||
#include "syzygy/tbprobe.h" | ||
#include "uci.h" | ||
|
||
#define GET_USE_NNUE(x) "" | ||
#define EvalFileDefaultNameBig "" | ||
#define EvalFileDefaultNameSmall "" | ||
|
||
EMSCRIPTEN_KEEPALIVE std::string js_getline() { | ||
auto cmd = inQ.pop(); | ||
if (cmd.type == cmd.UCI) return cmd.uci; | ||
|
||
return ""; | ||
} | ||
|
||
const char* getRecommendedNnueName(int index) { | ||
return index == 1 ? EvalFileDefaultNameSmall : EvalFileDefaultNameBig; | ||
} | ||
|
||
// stubs for tbprobe.cpp (so we don't need -sALLOW_UNIMPLEMENTED_SYSCALLS) | ||
|
||
namespace Tablebases { | ||
int MaxCardinality = 0; | ||
void init(const std::string& paths) {} | ||
WDLScore probe_wdl(Position& pos, ProbeState* result) { return WDLDraw; } | ||
int probe_dtz(Position& pos, ProbeState* result) { return 0; } | ||
|
||
bool root_probe(Position& pos, Search::RootMoves& rootMoves) { return false; } | ||
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves) { return false; } | ||
} // namespace Tablebases | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "glue.hpp" | ||
|
||
#include "evaluate.h" | ||
#include "syzygy/tbprobe.h" | ||
#include "uci.h" | ||
|
||
# include "nnue/evaluate_nnue.h" | ||
# include "nnue/nnue_architecture.h" | ||
|
||
#define GET_USE_NNUE(x) Stockfish::Options.count("Use NNUE") > 0 ? "setoption name Use NNUE value " + std::string(x ? "true" : "false") : "" | ||
#define EvalFileDefaultNameBig EvalFileDefaultName | ||
#define EvalFileDefaultNameSmall EvalFileDefaultName | ||
|
||
EMSCRIPTEN_KEEPALIVE std::string js_getline() { | ||
auto cmd = inQ.pop(); | ||
if (cmd.type == cmd.UCI) | ||
return cmd.uci; | ||
else if (cmd.type == cmd.NNUE) { | ||
if (!cmd.ptr) return GET_USE_NNUE(false); | ||
std::istream in(&cmd); | ||
auto success = | ||
Stockfish::Eval::NNUE::load_eval("", in) ? std::make_optional(0) : std::nullopt; | ||
if (!success.has_value()) std::cerr << "BAD_NNUE " << cmd.index << std::endl; | ||
return GET_USE_NNUE(success.has_value()); | ||
} | ||
return ""; | ||
} | ||
|
||
const char* getRecommendedNnueName(int index) { | ||
return index == 1 ? EvalFileDefaultNameSmall : EvalFileDefaultNameBig; | ||
} | ||
|
||
// stubs for tbprobe.cpp (so we don't need -sALLOW_UNIMPLEMENTED_SYSCALLS) | ||
namespace Stockfish::Tablebases { | ||
|
||
int MaxCardinality = 0; | ||
void init(const std::string& paths) {} | ||
WDLScore probe_wdl(Position& pos, ProbeState* result) { return WDLDraw; } | ||
int probe_dtz(Position& pos, ProbeState* result) { return 0; } | ||
|
||
bool root_probe(Position& pos, Search::RootMoves& rootMoves) { return false; } | ||
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves) { return false; } | ||
} // namespace Stockfish::Tablebases | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "glue.hpp" | ||
|
||
#include "evaluate.h" | ||
#include "syzygy/tbprobe.h" | ||
#include "uci.h" | ||
|
||
# include "nnue/evaluate_nnue.h" | ||
# include "nnue/nnue_architecture.h" | ||
|
||
#define GET_USE_NNUE(x) "" | ||
|
||
EMSCRIPTEN_KEEPALIVE std::string js_getline() { | ||
auto cmd = inQ.pop(); | ||
if (cmd.type == cmd.UCI) | ||
return cmd.uci; | ||
else if (cmd.type == cmd.NNUE) { | ||
if (!cmd.ptr) return GET_USE_NNUE(false); | ||
std::istream in(&cmd); | ||
auto success = | ||
Stockfish::Eval::NNUE::load_eval(in, Stockfish::Eval::NNUE::NetSize(cmd.index)); | ||
if (!success.has_value()) std::cerr << "BAD_NNUE " << cmd.index << std::endl; | ||
return GET_USE_NNUE(success.has_value()); | ||
} | ||
return ""; | ||
} | ||
|
||
const char* getRecommendedNnueName(int index) { | ||
return index == 1 ? EvalFileDefaultNameSmall : EvalFileDefaultNameBig; | ||
} | ||
|
||
// stubs for tbprobe.cpp (so we don't need -sALLOW_UNIMPLEMENTED_SYSCALLS) | ||
namespace Stockfish::Tablebases { | ||
|
||
int MaxCardinality = 0; | ||
void init(const std::string& paths) {} | ||
WDLScore probe_wdl(Position& pos, ProbeState* result) { return WDLDraw; } | ||
int probe_dtz(Position& pos, ProbeState* result) { return 0; } | ||
bool root_probe(Position& pos, Search::RootMoves& rootMoves, bool rule50) { return false; } | ||
bool root_probe_wdl(Position& pos, Search::RootMoves& rootMoves, bool rule50) { return false; } | ||
Config rank_root_moves(const OptionsMap& options, Position& pos, Search::RootMoves& rootMoves) { | ||
return Config(); | ||
} | ||
} // namespace Stockfish::Tablebases | ||
|