53 cl_mem import_malloc_memory_helper(
void *ptr,
size_t size)
55 const cl_import_properties_arm import_properties[] =
58 CL_IMPORT_TYPE_HOST_ARM,
62 cl_int err = CL_SUCCESS;
69 class DummyAllocator final :
public IAllocator
72 DummyAllocator() =
default;
74 void *allocate(
size_t size,
size_t alignment)
override
77 return _backend_allocator.allocate(size, alignment);
79 void free(
void *ptr)
override
81 return _backend_allocator.free(ptr);
83 std::unique_ptr<IMemoryRegion> make_region(
size_t size,
size_t alignment)
override
87 return _backend_allocator.make_region(size, alignment);
89 int get_n_calls()
const
96 CLBufferAllocator _backend_allocator{};
99 void run_conv2d(std::shared_ptr<IMemoryManager> mm, IAllocator &mm_allocator)
109 CLGEMMConvolutionLayer conv(mm);
110 conv.configure(&
src, &weights, &
bias, &
dst, PadStrideInfo(1U, 1U, 1U, 1U));
113 src.allocator()->allocate();
114 weights.allocator()->allocate();
115 bias.allocator()->allocate();
116 dst.allocator()->allocate();
121 mm->populate(mm_allocator, 1 );
137 DummyAllocator global_tensor_alloc;
141 run_conv2d(
nullptr , global_tensor_alloc);
153 auto lifetime_mgr = std::make_shared<BlobLifetimeManager>();
154 auto pool_mgr = std::make_shared<PoolManager>();
155 auto mm = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
157 DummyAllocator global_tensor_alloc;
161 run_conv2d(mm, global_tensor_alloc);
177 const size_t total_size =
info.total_size();
235 const size_t total_size_in_elems =
tensor.info()->tensor_shape().total_size();
236 const size_t total_size_in_bytes =
tensor.info()->total_size();
238 size_t space = total_size_in_bytes + alignment;
239 auto raw_data = std::make_unique<uint8_t[]>(space);
241 void *aligned_ptr = raw_data.get();
242 std::align(alignment, total_size_in_bytes, aligned_ptr, space);
244 cl::Buffer wrapped_buffer(import_malloc_memory_helper(aligned_ptr, total_size_in_bytes));
249 std::uniform_real_distribution<float>
distribution(-5.f, 5.f);
250 std::mt19937 gen(
library->seed());
251 auto *typed_ptr =
reinterpret_cast<float *
>(aligned_ptr);
252 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
262 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
268 tensor.allocator()->free();
273 #if !defined(BARE_METAL)
298 const size_t total_size_in_elems =
tensor.info()->tensor_shape().total_size();
299 const size_t total_size_in_bytes =
tensor.info()->total_size();
302 std::ofstream output_file(
"test_mmap_import.bin", std::ios::binary | std::ios::out);
303 output_file.seekp(total_size_in_bytes - 1);
304 output_file.write(
"", 1);
310 unsigned char *data = mmapped_file.
data();
312 cl::Buffer wrapped_buffer(import_malloc_memory_helper(data, total_size_in_bytes));
317 std::uniform_real_distribution<float>
distribution(-5.f, 5.f);
318 std::mt19937 gen(
library->seed());
319 auto *typed_ptr =
reinterpret_cast<float *
>(data);
320 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
330 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
336 tensor.allocator()->free();
340 #endif // !defined(BARE_METAL)
347 const std::vector<float>
scale = { 0.25f, 1.4f, 3.2f, 2.3f, 4.7f };
366 tensor.allocator()->allocate();
373 auto cl_scale_ptr =
static_cast<float *
>(mapped_ptr);
374 for(
unsigned int i = 0; i <
scale.size(); ++i)