FLImaging 7.3.20.1
BackendSoftmaxWithCrossEntropy.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "BackendBase.h"
6
7namespace FLImaging
8{
9 namespace AI
10 {
11 #ifdef CUDNN_MODE
12 template<typename T>
13 class CCuda_ComputationalGraphSoftmax_CudnnWithCrossEntropy;
14 #endif
15
16 template <typename T>
17 class FL_EXPORT CTensor;
18
19 template <typename T>
20 class FL_EXPORT CBackendSoftmaxWithCrossEntropy : public CBackendBase<T>
21 {
22 public:
23 CBackendSoftmaxWithCrossEntropy();
24 CBackendSoftmaxWithCrossEntropy(const CBackendSoftmaxWithCrossEntropy<T>& bl);
25 virtual ~CBackendSoftmaxWithCrossEntropy();
26
27 virtual const CResult SoftmaxWithCrossEntropy_Forward(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, CTensor<T>& tsrSoftmaxBuffer, CTensor<T>& pTsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull = nullptr, EReductionType eReductionType = EReductionType_Mean, T tLabelSmoothingValue = 0, int64_t i64IgnoreIndex = -1);
28 virtual const CResult SoftmaxWithCrossEntropy_Backward(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, const CTensor<T>* pTsrDy, CTensor<T>* pTsrDx, const CTensor<T>& tsrSoftmaxBuffer, const CTensor<T>& pTsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull = nullptr, EReductionType eReductionType = EReductionType_Mean, T tLabelSmoothingValue = 0, int64_t i64IgnoreIndex = -1);
29
30 protected:
31 virtual const CResult SoftmaxWithCrossEntropy(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, CTensor<T>& tsrSoftmaxBuffer, CTensor<T>& tsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull, EReductionType eReductionType, T tLabelSmoothingValue, int64_t i64IgnoreIndex, T tDominatorValue);
32 virtual const CResult SoftmaxWithCrossEntropy_ReductionNone(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, CTensor<T>& tsrSoftmaxBuffer, CTensor<T>& tsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull, T tLabelSmoothingValue, int64_t i64IgnoreIndex);
33
34 virtual const CResult SoftmaxWithCrossEntropy_Backward_ReductionNone(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, const CTensor<T>* pTsrDy, CTensor<T>* pTsrDx, const CTensor<T>& tsrSoftmaxBuffer, const CTensor<T>& pTsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull = nullptr, T tLabelSmoothingValue = 0, int64_t i64IgnoreIndex = -1);
35
36 virtual const CResult OneHotEncoding(const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, int64_t i64Ch, int64_t i64IgnoreIndex);
37 virtual const CResult LabelSmoothing(const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, const T tSmoothingVal);
38 virtual T CalculateDominatorValue(const CTensor<T>* pTsrOperand, const CTensor<T>* pTsrTarget, const CTensor<T>* pTsrWeightOrNull, EReductionType eReducntionType, int64_t i64IgnoreIndex);
39 virtual const CResult ApplyIgnoreIndex(const CTensor<T>* pTsrTargetLongType, CTensor<T>* pTsrTargetOneHotEncoded, int64_t i64IgnoreIndex);
40
41 DeclareGetClassType();
42 SupportToDuplicateObjectWithoutCreateNewObject(CBackendSoftmaxWithCrossEntropy<T>, *this);
43 protected:
44 #ifdef CUDNN_MODE
45 CCuda_ComputationalGraphSoftmax_CudnnWithCrossEntropy<T>* m_pCudnn;
46 #endif
47
48 };
49 }
50}
51
52#endif
Definition AlgorithmAIBase.h:18