MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / exec_unary

Function exec_unary

dnn/src/cambricon/elemwise/opr_impl.cpp:31–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 static_cast<int>(dtype_src0), static_cast<int>(dtype_dest));
30}
31void exec_unary(
32 HandleImpl* handle, const TensorND& src, _megdnn_tensor_out dst,
33 const param::Elemwise::Mode& mode, const WorkspaceBundle& wk_bundle) {
34 auto cnnl_handler = handle->cnnl_handle();
35 auto dtype_dest = dst.layout.dtype.enumv();
36 CnnlTensorDescriptor input_desc, output_desc;
37 input_desc.set(src.layout);
38 output_desc.set(dst.layout);
39 switch (mode) {
40 case Mode::RELU: { // float or half
41 megdnn_assert(
42 check_dtype_float_ieee(dtype_dest),
43 "Cambricon unsupport elemwise mode:%d with dtype:%d",
44 static_cast<int>(mode), static_cast<int>(dtype_dest));
45 CnnlActivationDescriptor relu_desc;
46 relu_desc.set(
47 cnnlActivationMode_t::CNNL_ACTIVATION_RELU,
48 cnnlActivationPreference_t::CNNL_ACTIVATION_HIGH_PRECISION,
49 cnnlNanPropagation_t::CNNL_NOT_PROPAGATE_NAN, 1.0);
50 cnnl_check(cnnlActivationForward(
51 cnnl_handler, relu_desc.desc(), nullptr, input_desc.desc(),
52 src.raw_ptr(), nullptr, output_desc.desc(), dst.raw_ptr()));
53 break;
54 }
55 case Mode::EXP: { // float or half
56 megdnn_assert(
57 check_dtype_float_ieee(dtype_dest),
58 "Cambricon unsupport elemwise mode:%d with dtype:%d",
59 static_cast<int>(mode), static_cast<int>(dtype_dest));
60 cnnl_check(cnnlExp_v2(
61 cnnl_handler,
62 cnnlComputationPreference_t::CNNL_COMPUTATION_HIGH_PRECISION,
63 input_desc.desc(), src.raw_ptr(), output_desc.desc(),
64 dst.raw_ptr()));
65 break;
66 }
67 case Mode::LOG: { // float or half
68 megdnn_assert(
69 check_dtype_float_ieee(dtype_dest),
70 "Cambricon unsupport elemwise mode:%d with dtype:%d",
71 static_cast<int>(mode), static_cast<int>(dtype_dest));
72 cnnl_check(cnnlLog_v2(
73 cnnl_handler,
74 cnnlComputationPreference_t::CNNL_COMPUTATION_HIGH_PRECISION,
75 cnnlLogBase_t::CNNL_LOG_E, input_desc.desc(), src.raw_ptr(),
76 output_desc.desc(), dst.raw_ptr()));
77 break;
78 }
79 case Mode::NEGATE: { // int32, float or half
80 megdnn_assert(
81 check_dtype_float_ieee(dtype_dest) ||
82 dtype_dest == megdnn::DTypeEnum::Int32,
83 "Cambricon unsupport elemwise mode:%d with dtype:%d",
84 static_cast<int>(mode), static_cast<int>(dtype_dest));
85 cnnl_check(cnnlNegTensor(
86 cnnl_handler, input_desc.desc(), src.raw_ptr(), output_desc.desc(),
87 dst.raw_ptr()));
88 break;

Callers 2

execMethod · 0.85
execMethod · 0.85

Calls 6

cnnl_handleMethod · 0.80
enumvMethod · 0.45
setMethod · 0.45
descMethod · 0.45
raw_ptrMethod · 0.45
get_workspaceMethod · 0.45

Tested by

no test coverage detected