FLImaging 6.5.16.1
ComputationalGraphConv2D.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "ComputationalGraph.h"
6#include "Tensor.h"
7#include "BackendConv2D.h"
8
9#include <vector>
10
11namespace FLImaging
12{
13 namespace AI
14 {
15 template <typename T>
16 class FL_EXPORT CComputationalGraphConv2D : public CComputationalGraph<T>
17 {
18 private:
19 CComputationalGraphConv2D();
20
21 protected:
22 CComputationalGraphConv2D(const CComputationalGraphConv2D<T>& cg);
23
24 public:
25 // Operand1
26 // 4th dim : Batch size
27 // 3rd dim : Channels
28 // 2nd dim : Height
29 // 1st dim : Width
30
31 // Kernel
32 // 4th dim : Num of kernels
33 // 3rd dim : Channels
34 // 2nd dim : Height
35 // 1st dim : Width
36
37 // Bias
38 // 1st dim : Num of kernels
39 CComputationalGraphConv2D(const CComputationalBase<T>& cbOperand1, const CTensor<T>& tsrKernel, int64_t i64StrideX = 1, int64_t i64StrideY = 1, int64_t i64PaddingX = 0, int64_t i64PaddingY = 0, int64_t i64DilationX = 1, int64_t i64DilationY = 1, int64_t i64GroupCount = 1);
40 virtual ~CComputationalGraphConv2D();
41
42 virtual CTensor<T>& Forward() override;
43 virtual CTensor<T>* Backward() override;
44 virtual CComputationalBase<T>* Clone() const override;
45
46 virtual const std::vector<int64_t>& GetEstimatedShape(bool bRecursive = true) const override;
47 virtual const CResult PrintNodeParamInfo() const override;
48
49 virtual const CResult GetBinaryData(Base::CFLData& fldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
50 virtual const CResult GetBinaryData(Base::CFLData* pFldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
51
52 virtual const CResult SetBinaryData(const Base::CFLData& fldBinary, int64_t* pI64Offset = nullptr) override;
53 virtual const CResult SetBinaryData(const Base::CFLData* pFldBinary, int64_t* pI64Offset = nullptr) override;
54
55 virtual int64_t GetRequiredTemporaryMemory(bool bTraining = false, bool bRecursively = true, int64_t i64BatchSize = 1, int64_t i64MemoryIndex = 0) const override;
56 virtual int64_t GetRequiredDedicatedMemory(bool bTraining = false, bool bRecursively = true, int64_t i64BatchSize = 1) const override;
57
58
59 DeclareGetClassType();
60 SupportToDuplicateObjectWithoutCreateNewObject(CComputationalGraphConv2D, *this);
61
62 protected:
63 int64_t m_i64StrideX;
64 int64_t m_i64StrideY;
65 int64_t m_i64PaddingX;
66 int64_t m_i64PaddingY;
67 int64_t m_i64DilationX;
68 int64_t m_i64DilationY;
69 int64_t m_i64GroupCount;
70
71 CTensor<T> m_tsrKernelBuffer;
72 CBackendConv2D<T> m_backendConv2D;
73
74 public:
75 DeclareGetSignletonObject(CComputationalGraphConv2D);
76 };
77
78 #define CCGFConv2D(...) (*(new CComputationalGraphConv2D<float>(__VA_ARGS__)))
79 #define CCGDConv2D(...) (*(new CComputationalGraphConv2D<double>(__VA_ARGS__)))
80
81 #define CCGTConv2D(T, ...) (*(new CComputationalGraphConv2D<T>(__VA_ARGS__)))
82 }
83}
84
85#endif