48 cl_mem import_malloc_memory_helper(
void *ptr,
size_t size)
50 const cl_import_properties_arm import_properties[] =
53 CL_IMPORT_TYPE_HOST_ARM,
57 cl_int err = CL_SUCCESS;
77 auto buf = cl::Buffer(
CLScheduler::get().context(), CL_MEM_READ_WRITE, total_size);
88 t2.allocator()->set_associated_memory_group(&mg);
95 t3.allocator()->init(info_neg);
105 t4.allocator()->free();
131 act_func.
configure(&tensor,
nullptr, act_info);
137 size_t space = total_size_in_bytes + alignment;
138 auto raw_data = std::make_unique<uint8_t[]>(space);
140 void *aligned_ptr = raw_data.get();
141 std::align(alignment, total_size_in_bytes, aligned_ptr, space);
143 cl::Buffer wrapped_buffer(import_malloc_memory_helper(aligned_ptr, total_size_in_bytes));
148 std::uniform_real_distribution<float>
distribution(-5.f, 5.f);
149 std::mt19937 gen(
library->seed());
150 auto *typed_ptr =
reinterpret_cast<float *
>(aligned_ptr);
151 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
161 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
172 #if !defined(BARE_METAL) 194 act_func.
configure(&tensor,
nullptr, act_info);
201 std::ofstream output_file(
"test_mmap_import.bin", std::ios::binary | std::ios::out);
202 output_file.seekp(total_size_in_bytes - 1);
203 output_file.write(
"", 1);
209 unsigned char *data = mmapped_file.
data();
211 cl::Buffer wrapped_buffer(import_malloc_memory_helper(data, total_size_in_bytes));
216 std::uniform_real_distribution<float>
distribution(-5.f, 5.f);
217 std::mt19937 gen(
library->seed());
218 auto *typed_ptr =
reinterpret_cast<float *
>(data);
219 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
229 for(
unsigned int i = 0; i < total_size_in_elems; ++i)
239 #endif // !defined(BARE_METAL) 246 const std::vector<float>
scale = { 0.25f, 1.4f, 3.2f, 2.3f, 4.7f };
270 auto cl_scale_buffer = quantization.scale->cl_buffer();
271 void *mapped_ptr =
CLScheduler::get().
queue().enqueueMapBuffer(cl_scale_buffer, CL_TRUE, CL_MAP_READ, 0, scale.size());
272 auto cl_scale_ptr =
static_cast<float *
>(mapped_ptr);
273 for(
unsigned int i = 0; i < scale.size(); ++i)
const std::vector< int32_t > & offset() const
Offset vector accessor.
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
bool is_resizable() const override
Flag indicating whether the size of the tensor can be changed.
static CLScheduler & get()
Access the scheduler singleton.
QuantizationInfo quantization_info() const override
Get the quantization settings (scale and offset) of the tensor.
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
Memory mapped file class.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void run() override
Run the kernels contained in the function.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Basic function to run opencl::kernels::ClActivationKernel.
Activation Layer Information class.
OpenCL quantization data.
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
Copyright (c) 2017-2021 Arm Limited.
Status import_memory(cl::Buffer buffer)
Import an existing memory as a tensor's backing memory.
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
Quantization information.
DatasetMode
Possible dataset modes.
std::unique_ptr< AssetsLibrary > library
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
CLQuantization quantization() const override
Interface to be implemented by the child class to return the wrapped quantization info data...
size_t total_size() const override
Returns the total size of the tensor in bytes.
size_t total_size() const
Collapses all dimensions to a single linear total size.
bool is_mapped() const
Checks if file mapped.
const std::vector< float > & scale() const
Scale vector accessor.
TEST_SUITE(U8_to_S8) FIXTURE_DATA_TEST_CASE(RunSmall
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
unsigned char * data()
Mapped data accessor.
void sync()
Blocks until all commands in the associated command queue have finished.
quantized, symmetric per channel fixed-point 8-bit number
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
bool device_supports_extension(const cl::Device &device, const char *extension_name)
Helper function to check whether a given extension is supported.
bool empty() const
Indicates whether this QuantizationInfo has valid settings or not.
void free() override
Free allocated OpenCL memory.
void configure(ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
Set the input and output tensor.
Store the tensor's metadata.
cl_mem clImportMemoryARM(cl_context context, cl_mem_flags flags, const cl_import_properties_arm *properties, void *memory, size_t size, cl_int *errcode_ret)
TEST_CASE(FusedActivation, framework::DatasetMode::ALL)
Validate fused activation expecting the following behaviours:
#define ARM_COMPUTE_ASSERT(cond)
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
DataType
Available data types.
const cl::Device & get_device()
Gets the CL device for which the programs are created.
Basic implementation of the OpenCL tensor interface.