Compute Library
 19.08
GCDropoutLayerKernel Class Reference

Interface for the dropout layer kernel. More...

#include <GCDropoutLayerKernel.h>

Collaboration diagram for GCDropoutLayerKernel:
[legend]

Public Member Functions

 GCDropoutLayerKernel ()
 Default constructor. More...
 
 GCDropoutLayerKernel (const GCDropoutLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCDropoutLayerKerneloperator= (const GCDropoutLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCDropoutLayerKernel (GCDropoutLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
GCDropoutLayerKerneloperator= (GCDropoutLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const IGCTensor *input, IGCTensor *mask, IGCTensor *output, float ratio, bool forward)
 Set the input and output of the kernel. More...
 
void run (const Window &window) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
- Public Member Functions inherited from IGCKernel
 IGCKernel ()
 Constructor. More...
 
GCKernelkernel ()
 Returns a reference to the GLES kernel of this object. More...
 
void add_1D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_3D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
unsigned int num_arguments_per_1D_tensor () const
 Returns the number of arguments enqueued per 1D tensor object. More...
 
unsigned int num_arguments_per_2D_tensor () const
 Returns the number of arguments enqueued per 2D tensor object. More...
 
unsigned int num_arguments_per_3D_tensor () const
 Returns the number of arguments enqueued per 3D tensor object. More...
 
void set_lws_hint (gles::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Interface for the dropout layer kernel.

Dropout is used to improve over-fit on neural networks.

Definition at line 39 of file GCDropoutLayerKernel.h.

Constructor & Destructor Documentation

◆ GCDropoutLayerKernel() [1/3]

Default constructor.

Definition at line 43 of file GCDropoutLayerKernel.cpp.

44  : _input(nullptr), _mask(nullptr), _output(nullptr), _num_elems_processed_per_iteration(0)
45 {
46 }

◆ GCDropoutLayerKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ GCDropoutLayerKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const IGCTensor input,
IGCTensor mask,
IGCTensor output,
float  ratio,
bool  forward 
)

Set the input and output of the kernel.

Parameters
[in]inputThe input tensor for this op. Data types supported: F16/F32
[out]maskThe mask tensor. Data types supported: Same as input
[out]outputThe output tensor. Data types supported: Same as input
[in]ratioDropout ratio
[in]forwardForward or backward propagation

Definition at line 48 of file GCDropoutLayerKernel.cpp.

49 {
52 
53  _input = input;
54  _mask = mask;
55  _output = output;
56 
57  std::set<std::string> build_opts;
58  std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
59  std::string fporbp = forward ? "FORWARD" : "BACKWARD";
60  std::random_device rd;
61  std::mt19937 mt(rd());
62  std::uniform_real_distribution<float> dist(0.f, 1.f);
63 
64  build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(1));
65  build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1));
66  build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1));
67  build_opts.emplace("#define RATIO " + support::cpp11::to_string(ratio));
68  build_opts.emplace("#define SCALE " + support::cpp11::to_string(1. / (1. - ratio)));
69  build_opts.emplace("#define SEED " + support::cpp11::to_string(dist(mt)));
70  build_opts.emplace("#define " + dt_name);
71  build_opts.emplace("#define " + fporbp);
72 
73  _num_elems_processed_per_iteration = 4 / input->info()->element_size();
74 
75  // Create kernel
76  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("dropout", build_opts));
77 
78  // Configure kernel window
79  Window win = calculate_max_window(*input->info(), Steps(_num_elems_processed_per_iteration));
80 
81  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
82 
83  IGCKernel::configure(win);
84 }
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::element_size(), arm_compute::F16, arm_compute::F32, arm_compute::test::validation::forward, GCKernelLibrary::get(), ITensor::info(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and arm_compute::support::cpp11::to_string().

Referenced by GCDropoutLayer::configure().

◆ operator=() [1/2]

GCDropoutLayerKernel& operator= ( const GCDropoutLayerKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

GCDropoutLayerKernel& operator= ( GCDropoutLayerKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window)
overridevirtual

Enqueue the OpenGL ES shader to process the given window.

Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).

Implements IGCKernel.

Definition at line 86 of file GCDropoutLayerKernel.cpp.

87 {
90 
91  _kernel.use();
92 
94 
95  do
96  {
97  unsigned int idx = 0;
98 
99  add_3D_tensor_argument(idx, _input, 1, slice);
100  add_3D_tensor_argument(idx, _mask, 2, slice);
101  add_3D_tensor_argument(idx, _output, 3, slice);
102 
103  _kernel.update_shader_params();
104  enqueue(*this, slice);
105  }
107 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: IGCKernel.cpp:132
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:39
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References IGCKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_3D(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().


The documentation for this class was generated from the following files: