aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2020-10-02 21:00:00 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2020-10-08 13:18:49 +0000
commitff4fca0d2ae523557a7b31db2014b48391f1d8c3 (patch)
tree54bfdac49c003eee29118a490c23b331e84df98c
parent272e425d12a6f790f1807bd7ca6fe97aa6e47c93 (diff)
downloadComputeLibrary-ff4fca0d2ae523557a7b31db2014b48391f1d8c3.tar.gz
COMPMID-3684: Use case data type decoupling
Decouples data types for NEFloorKernel Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Change-Id: I6756300540bc5ef32a9990246eed8619a76855f2 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4084 Reviewed-by: Giorgio Arena <giorgio.arena@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--Android.bp2
-rw-r--r--SConscript5
-rw-r--r--SConstruct8
-rw-r--r--src/core/NEON/kernels/NEFloorKernel.cpp113
-rw-r--r--src/core/NEON/kernels/floor/impl/fp16_neon_floor.cpp63
-rw-r--r--src/core/NEON/kernels/floor/impl/fp32_neon_floor.cpp60
-rw-r--r--src/core/NEON/kernels/floor/impl/list.h41
-rw-r--r--src/core/common/Registrars.h39
-rw-r--r--src/core/common/StdTypes.h43
-rw-r--r--src/core/common/Validate.h41
10 files changed, 354 insertions, 61 deletions
diff --git a/Android.bp b/Android.bp
index 490f58f6ee..5d9b305e34 100644
--- a/Android.bp
+++ b/Android.bp
@@ -404,6 +404,8 @@ cc_library_static {
"src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp",
"src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp",
"src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp",
+ "src/core/NEON/kernels/floor/impl/fp16_neon_floor.cpp",
+ "src/core/NEON/kernels/floor/impl/fp32_neon_floor.cpp",
"src/core/PyramidInfo.cpp",
"src/core/Rounding.cpp",
"src/core/Size2D.cpp",
diff --git a/SConscript b/SConscript
index 49f2976220..b915557057 100644
--- a/SConscript
+++ b/SConscript
@@ -245,6 +245,11 @@ if env['neon']:
if "sve" in env['arch']:
core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
+ if any(i in env['data_type_support'] for i in ['all', 'fp16']):
+ core_files += Glob('src/core/NEON/kernels/*/impl/fp16_*.cpp')
+ if any(i in env['data_type_support'] for i in ['all', 'fp32']):
+ core_files += Glob('src/core/NEON/kernels/*/impl/fp32_*.cpp')
+
runtime_files += Glob('src/runtime/NEON/*.cpp')
runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
diff --git a/SConstruct b/SConstruct
index ab55daaaa3..985f34c6cd 100644
--- a/SConstruct
+++ b/SConstruct
@@ -65,6 +65,7 @@ vars.AddVariables(
#FIXME Remove before release (And remove all references to INTERNAL_ONLY)
BoolVariable("internal_only", "Enable ARM internal only tests", False),
ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]),
+ ListVariable("data_type_support", "Enable a list of data types to support", "all", ["fp16", "fp32"]),
("toolchain_prefix", "Override the toolchain prefix", ""),
("compiler_prefix", "Override the compiler prefix", ""),
("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
@@ -282,6 +283,12 @@ if not GetOption("help"):
if compiler_ver == '4.8.3':
env.Append(CXXFLAGS = ['-Wno-array-bounds'])
+if env['data_type_support']:
+ if any(i in env['data_type_support'] for i in ['all', 'fp16']):
+ env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
+ if any(i in env['data_type_support'] for i in ['all', 'fp32']):
+ env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
+
if env['standalone']:
env.Append(CXXFLAGS = ['-fPIC'])
env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
@@ -343,7 +350,6 @@ for dirname in os.listdir("./include"):
Export('version_at_least')
-
if env['gles_compute'] and env['os'] != 'android':
env.Append(CPPPATH = ['#/include/linux'])
diff --git a/src/core/NEON/kernels/NEFloorKernel.cpp b/src/core/NEON/kernels/NEFloorKernel.cpp
index e134097f7a..301dc7a422 100644
--- a/src/core/NEON/kernels/NEFloorKernel.cpp
+++ b/src/core/NEON/kernels/NEFloorKernel.cpp
@@ -26,23 +26,63 @@
#include "arm_compute/core/CPP/Validate.h"
#include "arm_compute/core/Coordinates.h"
#include "arm_compute/core/Helpers.h"
-#include "arm_compute/core/IAccessWindow.h"
#include "arm_compute/core/ITensor.h"
#include "arm_compute/core/NEON/INEKernel.h"
#include "arm_compute/core/Validate.h"
-#include "src/core/NEON/NEMath.h"
-#include <arm_neon.h>
+#include "src/core/NEON/kernels/floor/impl/list.h"
+#include "src/core/common/Registrars.h"
namespace arm_compute
{
namespace
{
+struct FloorSelectorData
+{
+ DataType dt;
+};
+using FloorSelectorPtr = std::add_pointer<bool(const FloorSelectorData &data)>::type;
+using FloorUKernelPtr = std::add_pointer<void(const void *, void *, int)>::type;
+
+struct FloorKernel
+{
+ const char *name;
+ const FloorSelectorPtr is_selected;
+ FloorUKernelPtr ukernel;
+};
+
+static const FloorKernel available_kernels[] =
+{
+ {
+ "fp16_neon_floor",
+ [](const FloorSelectorData & data) { return data.dt == DataType::F16; },
+ REGISTER_FP16_NEON(arm_compute::cpu::fp16_neon_floor)
+ },
+ {
+ "f32_neon_floor",
+ [](const FloorSelectorData & data) { return data.dt == DataType::F32; },
+ REGISTER_FP32_NEON(arm_compute::cpu::fp32_neon_floor)
+ },
+};
+
+const FloorKernel *get_implementation(const FloorSelectorData &data)
+{
+ for(const auto &uk : available_kernels)
+ {
+ if(uk.is_selected(data))
+ {
+ return &uk;
+ }
+ }
+ return nullptr;
+}
+
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
{
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
+
+ const auto *uk = get_implementation(FloorSelectorData{ input->data_type() });
+ ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
// Validate in case of configured output
if(output->total_size() > 0)
@@ -90,66 +130,19 @@ void NEFloorKernel::run(const Window &window, const ThreadInfo &info)
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
- const DataType data_type = _input->info()->data_type();
-
- const auto window_start_x = static_cast<int>(window.x().start());
- const auto window_end_x = static_cast<int>(window.x().end());
- const int window_step_x = 16 / _input->info()->element_size();
-
Window win{ window };
win.set(Window::DimX, Window::Dimension(0, 1, 1));
+
+ const auto len = static_cast<int>(window.x().end()) - static_cast<int>(window.x().start());
+ const auto *uk = get_implementation(FloorSelectorData{ _input->info()->data_type() });
+
Iterator input(_input, win);
Iterator output(_output, win);
- if(data_type == DataType::F32)
+ execute_window_loop(win, [&](const Coordinates &)
{
- execute_window_loop(win, [&](const Coordinates &)
- {
- const auto input_ptr = reinterpret_cast<const float *>(input.ptr());
- const auto output_ptr = reinterpret_cast<float *>(output.ptr());
-
- int x = window_start_x;
- for(; x <= (window_end_x - window_step_x); x += window_step_x)
- {
- const float32x4_t res = vfloorq_f32(vld1q_f32(input_ptr + x));
- vst1q_f32(output_ptr + x, res);
- }
-
- // Compute left-over elements
- for(; x < window_end_x; ++x)
- {
- *(output_ptr + x) = std::floor(*(input_ptr + x));
- }
- },
- input, output);
- }
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- else if(data_type == DataType::F16)
- {
- execute_window_loop(win, [&](const Coordinates &)
- {
- const auto input_ptr = reinterpret_cast<const float16_t *>(input.ptr());
- const auto output_ptr = reinterpret_cast<float16_t *>(output.ptr());
-
- int x = window_start_x;
- for(; x <= (window_end_x - window_step_x); x += window_step_x)
- {
- const float16x8_t res = vfloorq_f16(vld1q_f16(input_ptr + x));
- vst1q_f16(output_ptr + x, res);
- }
-
- // Compute left-over elements
- for(; x < window_end_x; ++x)
- {
- *(output_ptr + x) = std::floor(*(input_ptr + x));
- }
- },
- input, output);
- }
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- else
- {
- ARM_COMPUTE_ERROR("Invalid data type!");
- }
+ uk->ukernel(input.ptr(), output.ptr(), len);
+ },
+ input, output);
}
} // namespace arm_compute
diff --git a/src/core/NEON/kernels/floor/impl/fp16_neon_floor.cpp b/src/core/NEON/kernels/floor/impl/fp16_neon_floor.cpp
new file mode 100644
index 0000000000..3222fa926a
--- /dev/null
+++ b/src/core/NEON/kernels/floor/impl/fp16_neon_floor.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS)
+
+#include "src/core/NEON/NEMath.h"
+#include "src/core/common/StdTypes.h"
+#include "src/core/common/Validate.h"
+
+#include <arm_neon.h>
+#include <cmath>
+#include <cstddef>
+
+namespace arm_compute
+{
+namespace cpu
+{
+constexpr int step = 8;
+
+void fp16_neon_floor(const void *src, void *dst, int len)
+{
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(src);
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst);
+ ARM_COMPUTE_ASSERT(len >= 0);
+
+ auto psrc = static_cast<const f16 *>(src);
+ auto pdst = static_cast<f16 *>(dst);
+
+ for(; len >= step; len -= step)
+ {
+ vst1q_f16(pdst, vfloorq_f16(vld1q_f16(psrc)));
+ psrc += step;
+ pdst += step;
+ }
+
+ for(; len >= 0; --len)
+ {
+ *pdst++ = std::floor(*psrc++);
+ }
+}
+} // namespace cpu
+} // namespace arm_compute
+#endif /* defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS) */
diff --git a/src/core/NEON/kernels/floor/impl/fp32_neon_floor.cpp b/src/core/NEON/kernels/floor/impl/fp32_neon_floor.cpp
new file mode 100644
index 0000000000..dba61e1e8c
--- /dev/null
+++ b/src/core/NEON/kernels/floor/impl/fp32_neon_floor.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020 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 "src/core/NEON/NEMath.h"
+#include "src/core/common/StdTypes.h"
+#include "src/core/common/Validate.h"
+
+#include <arm_neon.h>
+#include <cmath>
+#include <cstddef>
+
+namespace arm_compute
+{
+namespace cpu
+{
+constexpr int step = 4;
+
+void fp32_neon_floor(const void *src, void *dst, int len)
+{
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(src);
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst);
+ ARM_COMPUTE_ASSERT(len >= 0);
+
+ auto psrc = static_cast<const f32 *>(src);
+ auto pdst = static_cast<f32 *>(dst);
+
+ for(; len >= step; len -= step)
+ {
+ vst1q_f32(pdst, vfloorq_f32(vld1q_f32(psrc)));
+ psrc += step;
+ pdst += step;
+ }
+
+ for(; len >= 0; --len)
+ {
+ *pdst++ = std::floor(*psrc++);
+ }
+}
+} // namespace cpu
+} // namespace arm_compute
diff --git a/src/core/NEON/kernels/floor/impl/list.h b/src/core/NEON/kernels/floor/impl/list.h
new file mode 100644
index 0000000000..0eb66e0090
--- /dev/null
+++ b/src/core/NEON/kernels/floor/impl/list.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+#ifndef SRC_CORE_NEON_KERNELS_FLOOR_LIST_H
+#define SRC_CORE_NEON_KERNELS_FLOOR_LIST_H
+
+namespace arm_compute
+{
+namespace cpu
+{
+#define DECLARE_FLOOR_KERNEL(func_name) \
+ void func_name(const void *src, void *dst, int len)
+
+DECLARE_FLOOR_KERNEL(fp16_neon_floor);
+DECLARE_FLOOR_KERNEL(fp32_neon_floor);
+
+#undef DECLARE_FLOOR_KERNEL
+} // namespace cpu
+} // namespace arm_compute
+
+#endif /* SRC_CORE_NEON_KERNELS_FLOOR_LIST_H */
diff --git a/src/core/common/Registrars.h b/src/core/common/Registrars.h
new file mode 100644
index 0000000000..421a5a1899
--- /dev/null
+++ b/src/core/common/Registrars.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+#ifndef SRC_CORE_COMMON_REGISTRARS_H
+#define SRC_CORE_COMMON_REGISTRARS_H
+
+#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS)
+#define REGISTER_FP16_NEON(func_name) &(func_name)
+#else /* defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS) */
+#define REGISTER_FP16_NEON(func_name) nullptr
+#endif /* defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(ENABLE_FP16_KERNELS) */
+
+#if defined(ENABLE_FP32_KERNELS)
+#define REGISTER_FP32_NEON(func_name) &(func_name)
+#else /* defined(ENABLE_FP32_KERNELS) */
+#define REGISTER_FP32_NEON(func_name) nullptr
+#endif /* defined(ENABLE_FP32_KERNELS) */
+
+#endif /* SRC_CORE_COMMON_REGISTRARS_H */
diff --git a/src/core/common/StdTypes.h b/src/core/common/StdTypes.h
new file mode 100644
index 0000000000..3fba6187a3
--- /dev/null
+++ b/src/core/common/StdTypes.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+#ifndef SRC_CORE_COMMON_STDTYPES_H
+#define SRC_CORE_COMMON_STDTYPES_H
+
+#include <cstdint>
+
+namespace arm_compute
+{
+using u8 = uint8_t;
+using s8 = int8_t;
+using u16 = uint16_t;
+using s16 = int16_t;
+using u32 = uint32_t;
+using s32 = int32_t;
+using f32 = float;
+#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+using f16 = __fp16;
+#endif /* defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) */
+} // namespace arm_compute
+
+#endif /* SRC_CORE_COMMON_STDTYPES_H */
diff --git a/src/core/common/Validate.h b/src/core/common/Validate.h
new file mode 100644
index 0000000000..fa24bf5fa7
--- /dev/null
+++ b/src/core/common/Validate.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#ifndef SRC_CORE_COMMON_VALIDATE_H
+#define SRC_CORE_COMMON_VALIDATE_H
+
+#if defined(ARM_COMPUTE_ASSERTS_ENABLED)
+
+#include <cassert>
+
+#define ARM_COMPUTE_ASSERT(cond) assert(cond)
+#define ARM_COMPUTE_ASSERT_NOT_NULLPTR(ptr) assert((ptr) != nullptr)
+
+#else /* defined(ARM_COMPUTE_ASSERTS_ENABLED) */
+
+#define ARM_COMPUTE_ASSERT(cond)
+#define ARM_COMPUTE_ASSERT_NOT_NULLPTR(ptr)
+
+#endif /* defined(ARM_COMPUTE_ASSERTS_ENABLED) */
+#endif /* SRC_CORE_COMMON_VALIDATE_H */