| 4 | #include "conv.h" |
| 5 | |
| 6 | OIDN_NAMESPACE_BEGIN |
| 7 | |
| 8 | Conv::Conv(const ConvDesc& desc) |
| 9 | : ConvDesc(desc) |
| 10 | { |
| 11 | if (srcDesc.getRank() != 3) |
| 12 | throw std::invalid_argument("invalid convolution source shape"); |
| 13 | if (weightDesc.getRank() != 4 || |
| 14 | weightDesc.getI() != srcDesc.getC() || |
| 15 | weightDesc.getPaddedI() != srcDesc.getPaddedC()) |
| 16 | throw std::invalid_argument("invalid convolution weight shape"); |
| 17 | |
| 18 | TensorDims dstDims; |
| 19 | switch (fusion) |
| 20 | { |
| 21 | case Fusion::None: |
| 22 | dstDims = {weightDesc.getO(), srcDesc.getH(), srcDesc.getW()}; |
| 23 | break; |
| 24 | |
| 25 | case Fusion::UpsampleSrc0: |
| 26 | dstDims = {weightDesc.getO(), srcDesc.getH() * 2, srcDesc.getW() * 2}; |
| 27 | break; |
| 28 | |
| 29 | case Fusion::PoolDst: |
| 30 | if (srcDesc.getH() % 2 != 0 || srcDesc.getW() % 2 != 0) |
| 31 | throw std::invalid_argument("invalid pooling source shape"); |
| 32 | dstDims = {weightDesc.getO(), srcDesc.getH() / 2, srcDesc.getW() / 2}; |
| 33 | break; |
| 34 | |
| 35 | default: |
| 36 | throw std::invalid_argument("unsupported convolution fusion"); |
| 37 | } |
| 38 | |
| 39 | TensorDims dstPaddedDims = dstDims; |
| 40 | dstPaddedDims[0] = weightDesc.getPaddedO(); |
| 41 | |
| 42 | dstDesc = {dstDims, dstPaddedDims, srcDesc.layout, srcDesc.dataType}; |
| 43 | |
| 44 | if (!((biasDesc.getRank() == 1 && biasDesc.getX() == weightDesc.getO() |
| 45 | && biasDesc.getPaddedX() == weightDesc.getPaddedO()) || |
| 46 | (biasDesc.getRank() == 3 && biasDesc.dims == dstDesc.dims |
| 47 | && biasDesc.paddedDims == dstDesc.paddedDims))) |
| 48 | throw std::invalid_argument("invalid convolution bias shape"); |
| 49 | } |
| 50 | |
| 51 | void Conv::setSrc(const Ref<Tensor>& src) |
| 52 | { |
nothing calls this directly
no test coverage detected