FLImaging 6.5.16.1
ComputationalGraphLogSoftmax.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "ComputationalGraph.h"
6
7namespace FLImaging
8{
9 namespace AI
10 {
11 #ifdef CUDNN_MODE
12 template<typename T>
13 class CCuda_ComputationalGraphSoftmax_CudnnWithLogSoftmax;
14 #endif
15
16 template <typename T>
17 class FL_EXPORT CComputationalGraphLogSoftmax : public CComputationalGraph<T>
18 {
19
20 private:
21 CComputationalGraphLogSoftmax();
22
23 protected:
24 CComputationalGraphLogSoftmax(const CComputationalGraphLogSoftmax<T>& cg);
25
26 public:
27 CComputationalGraphLogSoftmax(const CComputationalBase<T>& cbOperand1, int64_t i64Axis = -1);
28 virtual ~CComputationalGraphLogSoftmax();
29
30 virtual CTensor<T>& Forward() override;
31 virtual CTensor<T>* Backward() override;
32 virtual CComputationalBase<T>* Clone() const override;
33
34 virtual const std::vector<int64_t>& GetEstimatedShape(bool bRecursive = true) const override;
35 virtual const CResult PrintNodeParamInfo() const override;
36
37 virtual const CResult GetBinaryData(Base::CFLData& fldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
38 virtual const CResult GetBinaryData(Base::CFLData* pFldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
39
40 virtual const CResult SetBinaryData(const Base::CFLData& fldBinary, int64_t* pI64Offset = nullptr) override;
41 virtual const CResult SetBinaryData(const Base::CFLData* pFldBinary, int64_t* pI64Offset = nullptr) override;
42
43 DeclareGetClassType();
44 SupportToDuplicateObjectWithoutCreateNewObject(CComputationalGraphLogSoftmax, *this);
45
46 protected:
47 virtual const CResult LogSoftmax(const CTensor<T>* pTsrOperand, CTensor<T>* pTsrResult);
48 virtual const CResult LogSoftmax_Cuda(const CTensor<T>* pTsrOperand, CTensor<T>* pTsrResult);
49 virtual const CResult Dervative(bool bAddGradient = false);
50 virtual const CResult Dervative_Cuda(bool bAddGradient = false);
51
52 private:
53 CTensor<T>* m_pTsrSoftmax;
54 int64_t m_i64Axis;
55
56 T m_tSmoothingVal;
57 public:
58 DeclareGetSignletonObject(CComputationalGraphLogSoftmax);
59 };
60
61 #define CCGFLogSoftmax(...) (*(new CComputationalGraphLogSoftmax<float>(__VA_ARGS__)))
62 #define CCGDLogSoftmax(...) (*(new CComputationalGraphLogSoftmax<double>(__VA_ARGS__)))
63
64 #define CCGTLogSoftmax(T, ...) (*(new CComputationalGraphLogSoftmax<T>(__VA_ARGS__)))
65 }
66}
67
68#endif