Fix stupid issues with create() (kill me I'm an idiot)

This commit is contained in:
Mattia Giambirtone 2024-05-14 12:08:49 +02:00
parent 5b3c244206
commit 53406cb94f
Signed by: nocturn9x
GPG Key ID: B6025DD9B4458B69
3 changed files with 12 additions and 13 deletions

View File

@ -4,4 +4,4 @@
--passL:"-flto -lmimalloc"
--passC:"-flto -march=native -mtune=native"
-d:useMalloc
--mm:atomicArc
--mm:arc

View File

@ -145,9 +145,9 @@ proc newSearchManager*(position: Position, positions: seq[Position], transpositi
stopFlag: ptr Atomic[bool]
ponderFlag: ptr Atomic[bool]
if mainWorker:
searchFlag = create(Atomic[bool], sizeof(Atomic[bool]))
stopFlag = create(Atomic[bool], sizeof(Atomic[bool]))
ponderFlag = create(Atomic[bool], sizeof(Atomic[bool]))
searchFlag = create(Atomic[bool])
stopFlag = create(Atomic[bool])
ponderFlag = create(Atomic[bool])
# If we're not the main worker, we expect the shared atomic metadata to be filled in by the
# main worker
result = SearchManager(board: newChessboard(), transpositionTable: transpositions, stop: stopFlag,
@ -788,8 +788,8 @@ proc search*(self: var SearchManager, timeRemaining, increment: int64, maxDepth:
for i in 0..<numWorkers - 1:
# Copy the history and killers table, as those are meant to be thread-local
var
history = create(HistoryTable, sizeof(HistoryTable))
killers = create(KillersTable, sizeof(KillersTable))
history = create(HistoryTable)
killers = create(KillersTable)
# Copy in the data
for color in PieceColor.White..PieceColor.Black:
for i in Square(0)..Square(63):
@ -801,7 +801,7 @@ proc search*(self: var SearchManager, timeRemaining, increment: int64, maxDepth:
# Create a new search manager to send off to a worker thread. We store it
# on the heap because we need to access its state from elsewhere for collecting
# statistics
self.children.add(create(SearchManager, sizeof(SearchManager)))
self.children.add(create(SearchManager))
self.children[i][] = newSearchManager(self.board.position, self.board.positions, self.transpositionTable, history, killers, false)
# Fill in our shared atomic metadata
self.children[i].stop = self.stop
@ -816,8 +816,7 @@ proc search*(self: var SearchManager, timeRemaining, increment: int64, maxDepth:
# necessary, but it's good practice and will catch bugs in our
# "atomic stop" system
for i in 0..<numWorkers - 1:
if workers[i][].running:
joinThread(workers[i][])
joinThread(workers[i][])
# If we set the atomics any earlier than this, our
# search threads would never stop!
self.searching[].store(false)

View File

@ -355,11 +355,11 @@ proc startUCISession* =
# God forbid we try to use atomic ARC like it was intended. Raw pointers
# it is then... sigh
var
transpositionTable = create(TTable, sizeof(TTable))
historyTable = create(HistoryTable, sizeof(HistoryTable))
killerMoves = create(KillersTable, sizeof(KillersTable))
transpositionTable = create(TTable)
historyTable = create(HistoryTable)
killerMoves = create(KillersTable)
transpositionTable[] = newTranspositionTable(session.hashTableSize * 1024 * 1024)
session.searchState = create(SearchManager, sizeof(SearchManager))
session.searchState = create(SearchManager)
session.searchState[] = newSearchManager(session.position, session.history, transpositionTable, historyTable, killerMoves)
# This is only ever written to from the main thread and read from
# the worker starting the search, so it doesn't need to be wrapped