From 73023027d6250daaa1df49fdeb1d21e59a0bf7f5 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Tue, 4 Sep 2018 14:55:55 +0100 Subject: COMPMID-1539 Implement YOLOLayer on CL Change-Id: I332c0703e1399fca0c5b724529b54a28f49c88da Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/146842 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- src/core/CL/cl_kernels/activation_helpers.h | 99 +++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/core/CL/cl_kernels/activation_helpers.h (limited to 'src/core/CL/cl_kernels/activation_helpers.h') diff --git a/src/core/CL/cl_kernels/activation_helpers.h b/src/core/CL/cl_kernels/activation_helpers.h new file mode 100644 index 0000000000..dfab082381 --- /dev/null +++ b/src/core/CL/cl_kernels/activation_helpers.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "helpers.h" + +#if defined(TYPE) && defined(SELECT_TYPE) + +#define CONST_ONE 1.f +#define ABS_OP(a) fabs((a)) +#define ADD_OP(a, b) ((a) + (b)) +#define SUB_OP(a, b) ((a) - (b)) +#define MUL_OP(a, b) ((a) * (b)) +#define MLA_OP(a, b, c) ((b) * (c) + (a)) +#define DIV_OP(a, b) ((a) / (b)) +#define EXP_OP(a) exp((a)) +#define LOG_OP(a) log((a)) +#define SQRT_OP(a) sqrt((a)) +#define TANH_OP(a) tanh((a)) + +// Logistic Activation +inline TYPE logistic_op(TYPE x) +{ + return DIV_OP((TYPE)CONST_ONE, ADD_OP((TYPE)CONST_ONE, EXP_OP(-x))); +} +// Hyperbolic Tangent Activation +inline TYPE tanh_op(TYPE x) +{ + return MUL_OP((TYPE)A_VAL, TANH_OP(MUL_OP((TYPE)B_VAL, x))); +} +// RELU Tangent Activation +inline TYPE relu_op(TYPE x) +{ + return max((TYPE)0, x); +} +// Bounded RELU Activation +inline TYPE brelu_op(TYPE x) +{ + return min((TYPE)A_VAL, max((TYPE)0, x)); +} +// Lower Upper Bounded RELU Activation +inline TYPE lu_brelu_op(TYPE x) +{ + return min(max(x, (TYPE)B_VAL), (TYPE)A_VAL); +} +// Leaky RELU Activation +inline TYPE lrelu_op(TYPE x) +{ + return select(MUL_OP((TYPE)A_VAL, x), x, CONVERT(x > (TYPE)0, SELECT_TYPE)); +} +// Soft RELU Activation +inline TYPE srelu_op(TYPE x) +{ + return LOG_OP(ADD_OP((TYPE)CONST_ONE, EXP_OP(x))); +} +// Absolute Activation +inline TYPE abs_op(TYPE x) +{ + return ABS_OP(x); +} +// Square Activation +inline TYPE square_op(TYPE x) +{ + return MUL_OP(x, x); +} +// Square-root Activation +inline TYPE sqrt_op(TYPE x) +{ + return SQRT_OP(x); +} +// Linear Activation +inline TYPE linear_op(TYPE x) +{ + return MLA_OP((TYPE)B_VAL, (TYPE)A_VAL, x); +} + +#define ACTIVATION_OP2(op, x) op##_op(x) +#define ACTIVATION_OP(op, x) ACTIVATION_OP2(op, x) + +#endif // defined(TYPE) && defined(SELECT_TYPE) \ No newline at end of file -- cgit v1.2.1