MCPcopy Create free account
hub / github.com/apache/singa / ComputeCrossEntropy

Function ComputeCrossEntropy

src/core/tensor/tensor.cc:1723–1739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1721}
1722
1723void ComputeCrossEntropy(const Tensor &p, const Tensor &t, Tensor *loss) {
1724 CHECK_LE(p.nDim(), 2u);
1725 CHECK_LE(t.nDim(), 2u);
1726 size_t batchsize = 1;
1727 if (p.nDim() == 2u) batchsize = p.shape(0);
1728 size_t dim = p.Size() / batchsize;
1729 TYPE_LANG_SWITCH(p.data_type(), DType, p.device()->lang(), Lang, {
1730 Tensor &lossRef = *loss;
1731 p.device()->Exec(
1732 [batchsize, dim, t, p, lossRef](Context *ctx) mutable {
1733 bool int_target = t.Size() == batchsize;
1734 ComputeCrossEntropy<DType, Lang>(int_target, batchsize, dim, p, t,
1735 &lossRef, ctx);
1736 },
1737 {p.block(), t.block()}, {loss->block()}, "ComputeCrossEntropy");
1738 });
1739}
1740
1741void SoftmaxCrossEntropyBwd(const Tensor &t, Tensor *p) {
1742 CHECK_LE(p->nDim(), 2u);

Callers 3

CrossEntropyFwdFunction · 0.70
Cuda>Method · 0.70
ForwardMethod · 0.50

Calls 8

nDimMethod · 0.80
shapeMethod · 0.80
data_typeMethod · 0.80
langMethod · 0.80
deviceMethod · 0.80
ExecMethod · 0.80
SizeMethod · 0.45
blockMethod · 0.45

Tested by

no test coverage detected