mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 01:29:36 +00:00
Use std::aligned_alloc
This commit is contained in:
parent
4cceeb7380
commit
675672cfc1
4 changed files with 2 additions and 21 deletions
16
src/misc.cpp
16
src/misc.cpp
|
@ -525,19 +525,3 @@ void bindThisThread(size_t idx) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace WinProcGroup
|
} // namespace WinProcGroup
|
||||||
|
|
||||||
void* aligned_malloc(size_t size, size_t align)
|
|
||||||
{
|
|
||||||
void* p = _mm_malloc(size, align);
|
|
||||||
if (p == nullptr)
|
|
||||||
{
|
|
||||||
std::cout << "info string can't allocate memory. sise = " << size << std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void aligned_free(void* ptr)
|
|
||||||
{
|
|
||||||
_mm_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
|
@ -134,7 +134,4 @@ namespace WinProcGroup {
|
||||||
void bindThisThread(size_t idx);
|
void bindThisThread(size_t idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void* aligned_malloc(size_t size, size_t align);
|
|
||||||
extern void aligned_free(void* ptr);
|
|
||||||
|
|
||||||
#endif // #ifndef MISC_H_INCLUDED
|
#endif // #ifndef MISC_H_INCLUDED
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Eval::NNUE {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Initialize(AlignedPtr<T>& pointer) {
|
void Initialize(AlignedPtr<T>& pointer) {
|
||||||
|
|
||||||
pointer.reset(reinterpret_cast<T*>(aligned_malloc(sizeof(T), alignof(T))));
|
pointer.reset(reinterpret_cast<T*>(std::aligned_alloc(alignof(T), sizeof(T))));
|
||||||
std::memset(pointer.get(), 0, sizeof(T));
|
std::memset(pointer.get(), 0, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Eval::NNUE {
|
||||||
struct AlignedDeleter {
|
struct AlignedDeleter {
|
||||||
void operator()(T* ptr) const {
|
void operator()(T* ptr) const {
|
||||||
ptr->~T();
|
ptr->~T();
|
||||||
aligned_free(ptr);
|
std::free(ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue