mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 02:47:45 +00:00
485d517c68
Use TT memory functions to allocate memory for the NNUE weights. This should provide a small speed-up on systems where large pages are not automatically used, including Windows and some Linux distributions. Further, since we now have a wrapper for std::aligned_alloc(), we can simplify the TT memory management a bit: - We no longer need to store separate pointers to the hash table and its underlying memory allocation. - We also get to merge the Linux-specific and default implementations of aligned_ttmem_alloc(). Finally, we'll enable the VirtualAlloc code path with large page support also for Win32. STC: https://tests.stockfishchess.org/tests/view/5f66595823a84a47b9036fba LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 14896 W: 1854 L: 1686 D: 11356 Ptnml(0-2): 65, 1224, 4742, 1312, 105 closes https://github.com/official-stockfish/Stockfish/pull/3081 No functional change.
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
/*
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
// header used in NNUE evaluation function
|
|
|
|
#ifndef NNUE_EVALUATE_NNUE_H_INCLUDED
|
|
#define NNUE_EVALUATE_NNUE_H_INCLUDED
|
|
|
|
#include "nnue_feature_transformer.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace Eval::NNUE {
|
|
|
|
// Hash value of evaluation function structure
|
|
constexpr std::uint32_t kHashValue =
|
|
FeatureTransformer::GetHashValue() ^ Network::GetHashValue();
|
|
|
|
// Deleter for automating release of memory area
|
|
template <typename T>
|
|
struct AlignedDeleter {
|
|
void operator()(T* ptr) const {
|
|
ptr->~T();
|
|
std_aligned_free(ptr);
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
struct TtmemDeleter {
|
|
void operator()(T* ptr) const {
|
|
ptr->~T();
|
|
aligned_large_pages_free(ptr);
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
using AlignedPtr = std::unique_ptr<T, AlignedDeleter<T>>;
|
|
|
|
template <typename T>
|
|
using LargePagePtr = std::unique_ptr<T, TtmemDeleter<T>>;
|
|
|
|
} // namespace Eval::NNUE
|
|
|
|
#endif // #ifndef NNUE_EVALUATE_NNUE_H_INCLUDED
|