Skip to content

Commit

Permalink
Remove superfluous buffer
Browse files Browse the repository at this point in the history
It is cleared anyway, so it can just as well be put on the stack.
  • Loading branch information
Sebastian Heuchler committed May 16, 2023
1 parent 9793a2b commit 71ef9cb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
10 changes: 4 additions & 6 deletions cpp/search/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,7 @@ bool Search::runSinglePlayout(SearchThread& thread, double upperBoundVisitsLeft)
//Store this value, used for futile-visit pruning this thread's root children selections.
thread.upperBoundVisitsLeft = upperBoundVisitsLeft;

bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE];
bool finishedPlayout = playoutDescend(thread,*rootNode,posesWithChildBuf,true);
bool finishedPlayout = playoutDescend(thread,*rootNode,true);

//Restore thread state back to the root state
thread.pla = rootPla;
Expand All @@ -1096,7 +1095,6 @@ bool Search::runSinglePlayout(SearchThread& thread, double upperBoundVisitsLeft)

bool Search::playoutDescend(
SearchThread& thread, SearchNode& node,
bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE],
bool isRoot
) {
//Hit terminal node, finish
Expand Down Expand Up @@ -1170,7 +1168,7 @@ bool Search::playoutDescend(

SearchNode* child = NULL;
while(true) {
selectBestChildToDescend(thread,node,nodeState,numChildrenFound,bestChildIdx,bestChildMoveLoc,posesWithChildBuf,isRoot);
selectBestChildToDescend(thread,node,nodeState,numChildrenFound,bestChildIdx,bestChildMoveLoc,isRoot);

//The absurdly rare case that the move chosen is not legal
//(this should only happen either on a bug or where the nnHash doesn't have full legality information or when there's an actual hash collision).
Expand Down Expand Up @@ -1199,7 +1197,7 @@ bool Search::playoutDescend(

//As isReInit is true, we don't return, just keep going, since we didn't count this as a true visit in the node stats
nodeState = node.state.load(std::memory_order_acquire);
selectBestChildToDescend(thread,node,nodeState,numChildrenFound,bestChildIdx,bestChildMoveLoc,posesWithChildBuf,isRoot);
selectBestChildToDescend(thread,node,nodeState,numChildrenFound,bestChildIdx,bestChildMoveLoc,isRoot);

if(bestChildIdx >= 0) {
//New child
Expand Down Expand Up @@ -1340,7 +1338,7 @@ bool Search::playoutDescend(
}

//Recurse!
bool finishedPlayout = playoutDescend(thread,*child,posesWithChildBuf,false);
bool finishedPlayout = playoutDescend(thread,*child,false);
//Update this node stats
if(finishedPlayout) {
nodeState = node.state.load(std::memory_order_acquire);
Expand Down
2 changes: 0 additions & 2 deletions cpp/search/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ struct Search {
void selectBestChildToDescend(
SearchThread& thread, const SearchNode& node, int nodeState,
int& numChildrenFound, int& bestChildIdx, Loc& bestChildMoveLoc,
bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE],
bool isRoot
) const;

Expand Down Expand Up @@ -611,7 +610,6 @@ struct Search {

bool playoutDescend(
SearchThread& thread, SearchNode& node,
bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE],
bool isRoot
);

Expand Down
3 changes: 1 addition & 2 deletions cpp/search/searchexplorehelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ double Search::getFpuValueForChildrenAssumeVisited(
void Search::selectBestChildToDescend(
SearchThread& thread, const SearchNode& node, int nodeState,
int& numChildrenFound, int& bestChildIdx, Loc& bestChildMoveLoc,
bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE],
bool isRoot) const
{
assert(thread.pla == node.nextPla);
Expand Down Expand Up @@ -353,7 +352,7 @@ void Search::selectBestChildToDescend(
parentUtility, parentWeightPerVisit, parentUtilityStdevFactor
);

std::fill(posesWithChildBuf,posesWithChildBuf+NNPos::MAX_NN_POLICY_SIZE,false);
bool posesWithChildBuf[NNPos::MAX_NN_POLICY_SIZE] = { false, };
bool antiMirror = searchParams.antiMirror && mirroringPla != C_EMPTY && isMirroringSinceSearchStart(thread.history,0);

double exploreScaling = getExploreScaling(totalChildWeight, parentUtilityStdevFactor);
Expand Down

0 comments on commit 71ef9cb

Please sign in to comment.