Compute Library
 21.11
CpuDirectConv3d.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
27 #include "arm_compute/core/Utils.h"
30 #include "src/common/utils/Log.h"
31 
32 namespace arm_compute
33 {
34 namespace cpu
35 {
37 
38 CpuDirectConv3d::CpuDirectConv3d(std::shared_ptr<IMemoryManager> memory_manager)
39  : _memory_group(std::move(memory_manager)), _conv_kernel(), _activationlayer_function(), _accumulator(), _is_activationlayer_enabled(false), _dim_split(Window::DimZ)
40 {
41 }
42 
44 {
45  ARM_COMPUTE_LOG_PARAMS(src0, src1, src2, dst, conv_info);
47 
48  _conv_kernel = std::make_unique<kernels::CpuDirectConv3dKernel>();
49 
50  // Free accumulator
51  if(_accumulator.buffer() != nullptr)
52  {
53  _accumulator.allocator()->free();
54  }
55 
56  _dim_split = Window::DimY;
57 
58  _conv_kernel->configure(src0, src1, src2, dst, conv_info);
59 
60  //Configure Activation Layer
61  _is_activationlayer_enabled = conv_info.act_info.enabled();
62  if(_is_activationlayer_enabled)
63  {
64  _activationlayer_function = std::make_unique<CpuActivation>();
65  _activationlayer_function->configure(dst, dst, conv_info.act_info);
66  }
67 }
68 
70 {
71  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src0, src1, dst);
72 
73  // Validate Convolution kernel
75 
76  if(conv_info.act_info.enabled())
77  {
79  }
80 
81  return Status{};
82 }
83 
85 {
86  MemoryGroupResourceScope scope_mg(_memory_group);
87 
88  auto dst = tensors.get_tensor(TensorType::ACL_DST);
89 
90  NEScheduler::get().schedule_op(_conv_kernel.get(), _dim_split, _conv_kernel->window(), tensors);
91 
92  if(_is_activationlayer_enabled)
93  {
97  _activationlayer_function->run(pack);
98  }
99 }
100 } // namespace cpu
101 } // namespace arm_compute
CpuDirectConv3d(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Descriptor used by the 3d Convolution function.
void configure(ITensorInfo *src0, ITensorInfo *src1, const ITensorInfo *src2, ITensorInfo *dst, const Conv3dInfo conv_info)
Set the input, weights, biases and output tensor info.
bool enabled() const
Check if initialised.
Definition: Types.h:1559
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const Conv3dInfo &conv_info)
Static function to check if given info will lead to a valid configuration.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Copyright (c) 2017-2021 Arm Limited.
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
void free() override
Free allocated CPU memory.
Num samples, depth, height, width, channels.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Static function to check if given info will lead to a valid configuration.
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: Tensor.cpp:43
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_LOG_PARAMS(...)
ActivationLayerInfo act_info
Describe a multidimensional execution window.
Definition: Window.h:39
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const Conv3dInfo conv_info)
Static function to check if given info will lead to a valid configuration.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94