1/*******************************************************************************
2* Copyright 2020 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef TEST_MALLOC_HPP
18#define TEST_MALLOC_HPP
19
20#ifdef DNNL_ENABLE_MEM_DEBUG
21#include "src/common/internal_defs.hpp"
22
23namespace dnnl {
24namespace impl {
25// Declare the dnnl::impl::malloc symbol as exported (dynamic linking) or
26// strong (static linking) in order to redirect calls inside the library to
27// the custom one.
28void DNNL_STRONG *malloc(size_t size, int alignment);
29} // namespace impl
30} // namespace dnnl
31
32#if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL
33#include <CL/cl.h>
34namespace dnnl {
35namespace impl {
36namespace gpu {
37namespace ocl {
38// Declare the dnnl::impl::gpu::ocl::clCreateBuffer_wrapper symbol as exported
39// (dynamic linking) or strong (static linking) in order to redirect calls
40// inside the library to the custom one.
41cl_mem DNNL_STRONG clCreateBuffer_wrapper(cl_context context,
42 cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret);
43} // namespace ocl
44} // namespace gpu
45} // namespace impl
46} // namespace dnnl
47#endif
48
49void reset_failed_malloc_counter();
50void increment_failed_malloc_counter();
51bool test_out_of_memory();
52#else
53static inline void reset_failed_malloc_counter() {}
54static inline void increment_failed_malloc_counter() {}
55static inline bool test_out_of_memory() {
56 return false;
57}
58#endif
59
60#endif
61