Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / StatelessRandomUniformLayer.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "StatelessRandomUniformLayer.h"
18
19 #include <cker/operation/StatelessRandomUniform.h>
20
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace ops
28 {
29
30 StatelessRandomUniformLayer::StatelessRandomUniformLayer()
31   : _shape(nullptr), _seed(nullptr), _output(nullptr)
32 {
33   // DO NOTHING
34 }
35
36 void StatelessRandomUniformLayer::configure(const IPortableTensor *shape,
37                                             const IPortableTensor *seed, IPortableTensor *output)
38 {
39   _shape = shape;
40   _seed = seed;
41   _output = output;
42 }
43
44 void StatelessRandomUniformLayer::StatelessRandomUniformFloat32()
45 {
46   nnfw::cker::StatelessRandomUniform(getShape(_shape), getBuffer<int32_t>(_shape), getShape(_seed),
47                                      getBuffer<int32_t>(_seed), getShape(_output),
48                                      getBuffer<float>(_output));
49 }
50
51 void StatelessRandomUniformLayer::run()
52 {
53   switch (_output->data_type())
54   {
55     // ToDo : It need to support INT8 and UINT8 also when will be applied quantization.
56     case OperandType::FLOAT32:
57       StatelessRandomUniformFloat32();
58       break;
59     default:
60       throw std::runtime_error{"StatelessRandomUniformLayer: unsupported data type"};
61   }
62 }
63
64 } // namespace ops
65 } // namespace cpu
66 } // namespace backend
67 } // namespace onert