6 #include <arm_compute/runtime/CL/functions/CLActivationLayer.h> 12 #include <boost/test/unit_test.hpp> 17 using namespace armnn;
27 unsigned int numElements =
info.GetNumElements();
33 arm_compute::CLTensor& tensor = PolymorphicDowncast<ClImportTensorHandle*>(handle.get())->GetTensor();
36 const arm_compute::ActivationLayerInfo act_info(arm_compute::ActivationLayerInfo::ActivationFunction::RELU);
37 arm_compute::CLActivationLayer act_func;
38 act_func.configure(&tensor,
nullptr, act_info);
41 const size_t totalBytes = tensor.info()->total_size();
42 const size_t alignment =
43 arm_compute::CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE>();
44 size_t space = totalBytes + alignment + alignment;
45 auto testData = std::make_unique<uint8_t[]>(space);
46 void* alignedPtr = testData.get();
47 BOOST_CHECK(std::align(alignment, totalBytes, alignedPtr, space));
53 auto* typedPtr =
reinterpret_cast<float*
>(alignedPtr);
54 std::fill_n(typedPtr, numElements, -5.0f);
58 arm_compute::CLScheduler::get().sync();
61 for(
unsigned int i = 0; i < numElements; ++i)
63 BOOST_TEST(typedPtr[i] >= 0);
78 arm_compute::CLTensor& tensor = PolymorphicDowncast<ClImportTensorHandle*>(handle.get())->GetTensor();
81 const size_t totalBytes = tensor.info()->total_size();
82 const size_t alignment =
83 arm_compute::CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE>();
84 size_t space = totalBytes + alignment + alignment;
85 auto testData = std::make_unique<uint8_t[]>(space);
86 void* alignedPtr = testData.get();
87 BOOST_CHECK(std::align(alignment, totalBytes, alignedPtr, space));
97 static_cast<MemorySourceFlags>(invalidMemSource));
105 std::vector<float> inputData
107 1.0f, 2.0f, 3.0f, 4.0f
127 IConnectableLayer* activation = net->AddActivationLayer(descriptor,
"Activation");
136 size_t totalBytes = numElements *
sizeof(float);
150 std::string ignoredErrorMessage;
153 runtime->LoadNetwork(netId, std::move(optNet), ignoredErrorMessage, networkProperties);
156 const size_t alignment =
157 arm_compute::CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE>();
158 size_t space = totalBytes + alignment + alignment;
159 auto inputData = std::make_unique<uint8_t[]>(space);
160 void* alignedInputPtr = inputData.get();
161 BOOST_CHECK(std::align(alignment, totalBytes, alignedInputPtr, space));
164 auto* intputPtr =
reinterpret_cast<float*
>(alignedInputPtr);
165 std::fill_n(intputPtr, numElements, -5.0f);
167 auto outputData = std::make_unique<uint8_t[]>(space);
168 void* alignedOutputPtr = outputData.get();
169 BOOST_CHECK(std::align(alignment, totalBytes, alignedOutputPtr, space));
177 {0,
armnn::Tensor(runtime->GetOutputTensorInfo(netId, 0), alignedOutputPtr)}
180 runtime->GetProfiler(netId)->EnableProfiling(
true);
183 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
187 std::stringstream ss;
189 std::string dump = ss.str();
192 std::size_t found = dump.find(
"ActivationWorkload");
193 BOOST_TEST(found != std::string::npos);
196 found = dump.find(
"SyncMemGeneric");
197 BOOST_TEST(found != std::string::npos);
200 found = dump.find(
"CopyMemGeneric");
201 BOOST_TEST(found == std::string::npos);
205 auto* outputResult =
reinterpret_cast<float*
>(alignedOutputPtr);
206 BOOST_TEST(outputResult);
207 for(
unsigned int i = 0; i < numElements; ++i)
209 BOOST_TEST(outputResult[i] >= 0);
212 runtime->UnloadNetwork(netId);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
static ProfilerManager & GetInstance()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
void Print(std::ostream &outStream) const
Print stats for events in JSON Format to the given output stream.
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Copyright (c) 2021 ARM Limited and Contributors.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IProfiler * GetProfiler()
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
BOOST_FIXTURE_TEST_CASE(ClMallocImport, ClContextControlFixture)
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
GPU Execution: OpenCL: ArmCompute.
An ActivationDescriptor for the ActivationLayer.
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...
BOOST_AUTO_TEST_SUITE_END()
MemorySource
Define the Memory Source to reduce copies.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const override
static INetworkPtr Create(NetworkOptions networkOptions={})
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
unsigned int GetNumElements() const