Skip to content

Commit cbe1f24

Browse files
committed
[NeoMathEngine] Refactored StackAllocators (#1064)
Signed-off-by: Kirill Golikov <[email protected]>
1 parent 3430a34 commit cbe1f24

16 files changed

+405
-610
lines changed

NeoMathEngine/include/NeoMathEngine/MemoryHandle.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright © 2017-2020 ABBYY Production LLC
1+
/* Copyright © 2017-2024 ABBYY
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -28,30 +28,17 @@ class CMemoryHandleInternal;
2828
class NEOMATHENGINE_API CMemoryHandle {
2929
public:
3030
CMemoryHandle() : mathEngine( 0 ), object( 0 ), offset( 0 ) {}
31-
CMemoryHandle( const CMemoryHandle& other ) : mathEngine( other.mathEngine ), object( other.object ), offset( other.offset ) {}
32-
33-
CMemoryHandle& operator=( const CMemoryHandle& other )
34-
{
35-
mathEngine = other.mathEngine;
36-
object = other.object;
37-
offset = other.offset;
38-
return *this;
39-
}
31+
CMemoryHandle( CMemoryHandle&& other ) = default;
32+
CMemoryHandle( const CMemoryHandle& other ) = default;
4033

34+
CMemoryHandle& operator=( CMemoryHandle&& other ) = default;
35+
CMemoryHandle& operator=( const CMemoryHandle& other ) = default;
36+
37+
bool operator!=( const CMemoryHandle& other ) const { return !operator==( other ); }
4138
bool operator==( const CMemoryHandle& other ) const
42-
{
43-
return mathEngine == other.mathEngine && object == other.object && offset == other.offset;
44-
}
39+
{ return mathEngine == other.mathEngine && object == other.object && offset == other.offset; }
4540

46-
bool operator!=( const CMemoryHandle& other ) const
47-
{
48-
return !operator==( other );
49-
}
50-
51-
bool IsNull() const
52-
{
53-
return mathEngine == 0 && object == 0 && offset == 0;
54-
}
41+
bool IsNull() const { return mathEngine == 0 && object == 0 && offset == 0; }
5542

5643
IMathEngine* GetMathEngine() const { return mathEngine; }
5744

@@ -62,8 +49,9 @@ class NEOMATHENGINE_API CMemoryHandle {
6249

6350
friend class CMemoryHandleInternal;
6451

65-
explicit CMemoryHandle( IMathEngine* _mathEngine, const void* _object, ptrdiff_t _offset ) : mathEngine( _mathEngine ), object( _object ), offset( _offset ) {}
66-
52+
CMemoryHandle( IMathEngine* _mathEngine, const void* _object, ptrdiff_t _offset ) :
53+
mathEngine( _mathEngine ), object( _object ), offset( _offset )
54+
{}
6755
CMemoryHandle CopyMemoryHandle( ptrdiff_t shift ) const { return CMemoryHandle( mathEngine, object, offset + shift ); }
6856
};
6957

NeoMathEngine/src/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ set(CPU_COMMON_SOURCES
2727
CPU/CpuMathEngineVectorMath.cpp
2828
CrtAllocatedObject.cpp
2929
DllLoader.cpp
30-
MathEngineDeviceStackAllocator.cpp
3130
MathEngineDnnDropout.cpp
3231
MathEngine.cpp
33-
MathEngineHostStackAllocator.cpp
32+
MathEngineStackAllocator.cpp
3433
MemoryEngine.cpp
3534
MemoryPool.cpp
3635
ThreadPool.cpp
@@ -44,13 +43,12 @@ target_sources(${PROJECT_NAME}
4443
common.h
4544
MathEngineAllocator.h
4645
MathEngineCommon.h
47-
MathEngineDeviceStackAllocator.h
4846
MathEngineDll.h
4947
MathEngineDnnConv.h
5048
MathEngineDnnDropout.h
5149
MathEngineDnnLrn.h
5250
MathEngineDnnPoolings.h
53-
MathEngineHostStackAllocator.h
51+
MathEngineStackAllocator.h
5452
MemoryEngine.h
5553
MemoryHandleInternal.h
5654
MemoryPool.h
@@ -104,7 +102,7 @@ set_target_properties( ${PROJECT_NAME} PROPERTIES
104102
UNITY_BUILD_MODE GROUP
105103
)
106104
set_property(SOURCE ${CPU_COMMON_SOURCES} PROPERTY UNITY_GROUP 1)
107-
set_property(SOURCE MathEngineDeviceStackAllocator.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
105+
set_property(SOURCE MathEngineStackAllocator.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
108106

109107
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
110108

NeoMathEngine/src/CPU/CpuMathEngine.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
#pragma hdrstop
1818

1919
#include <CpuMathEngine.h>
20-
#include <MathEngineDeviceStackAllocator.h>
21-
#include <MathEngineHostStackAllocator.h>
2220
#include <MemoryHandleInternal.h>
2321
#include <MathEngineCommon.h>
2422
#include <NeoMathEngine/SimdMathEngine.h>

NeoMathEngine/src/GPU/CUDA/CudaMathEngine.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ limitations under the License.
2626
#include <MathEngineAllocator.h>
2727
#include <MathEngineCommon.h>
2828
#include <MemoryHandleInternal.h>
29-
#include <MathEngineDeviceStackAllocator.h>
30-
#include <MathEngineHostStackAllocator.h>
3129
#include <cuda_runtime.h>
3230
#include <string>
3331
#include <vector>

NeoMathEngine/src/GPU/CUDA/CudaMathEngine.cu

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ limitations under the License.
2525
#include <CudaAssert.h>
2626
#include <MathEngineCommon.h>
2727
#include <MemoryHandleInternal.h>
28-
#include <MathEngineDeviceStackAllocator.h>
29-
#include <MathEngineHostStackAllocator.h>
3028
#include <math.h>
3129
#include <float.h>
3230
#include <cuda_runtime.h>

NeoMathEngine/src/GPU/Metal/MetalMathEngine.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@import std.vector;
2727

2828
#include <MemoryPool.h>
29-
#include <MathEngineDeviceStackAllocator.h>
3029

3130
@import Foundation;
3231
@import MetalKit;

NeoMathEngine/src/GPU/Vulkan/VulkanMathEngine.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ limitations under the License.
2424
#include <DllLoader.h>
2525
#include <VulkanMathEngine.h>
2626
#include <MathEngineCommon.h>
27-
#include <MathEngineDeviceStackAllocator.h>
28-
#include <MathEngineHostStackAllocator.h>
2927
#include <MemoryHandleInternal.h>
3028
#include <VulkanDll.h>
3129
#include <VulkanCommandQueue.h>

NeoMathEngine/src/MathEngineDeviceStackAllocator.cpp

Lines changed: 0 additions & 233 deletions
This file was deleted.

0 commit comments

Comments
 (0)