[ML][Training] Updating code to native API changes
[platform/core/api/webapi-plugins.git] / src / ml / js / ml_manager.js
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 var MachineLearningManager = function () {
18     Object.defineProperties(this, {
19         single: {
20             enumerable: true,
21             writable: false,
22             value: new MachineLearningSingle()
23         },
24         pipeline: {
25             enumerable: true,
26             writable: false,
27             value: new MachineLearningPipeline()
28         },
29         trainer: {
30             enumerable: true,
31             writable: false,
32             value: new MachineLearningTrainer()
33         }
34     });
35 };
36
37 var NNFWType = {
38     ANY: 'ANY',
39     ARM_NN: 'ARM_NN',
40     CUSTOM_FILTER: 'CUSTOM_FILTER',
41     EDGE_TPU: 'EDGE_TPU',
42     MVNC: 'MVNC',
43     NNFW: 'NNFW',
44     OPEN_VINO: 'OPEN_VINO',
45     SNAP: 'SNAP',
46     SNPE: 'SNPE',
47     TENSORFLOW: 'TENSORFLOW',
48     TENSORFLOW_LITE: 'TENSORFLOW_LITE',
49     VIVANTE: 'VIVANTE',
50     PYTORCH: 'PYTORCH',
51     NNTR_INF: 'NNTR_INF',
52     VD_AIFW: 'VD_AIFW',
53     TRIX_ENGINE: 'TRIX_ENGINE'
54 };
55
56 var HWType = {
57     ANY: 'ANY',
58     AUTO: 'AUTO',
59     CPU: 'CPU',
60     CPU_NEON: 'CPU_NEON',
61     CPU_SIMD: 'CPU_SIMD',
62     GPU: 'GPU',
63     NPU: 'NPU',
64     NPU_EDGE_TPU: 'NPU_EDGE_TPU',
65     NPU_MOVIDIUS: 'NPU_MOVIDIUS',
66     NPU_SR: 'NPU_SR',
67     NPU_VIVANTE: 'NPU_VIVANTE',
68     NPU_SLSI: 'NPU_SLSI'
69 };
70
71 MachineLearningManager.prototype.checkNNFWAvailability = function () {
72     var args = validator_.validateArgs(arguments, [
73         {
74             name: 'nnfw',
75             type: types_.ENUM,
76             values: Object.values(NNFWType),
77             optional: false
78         },
79         {
80             name: 'hw',
81             type: types_.ENUM,
82             values: Object.values(HWType),
83             optional: false
84         },
85         {
86             name: 'customRequirement',
87             type: types_.STRING,
88             optional: true
89         }
90     ]);
91     var callArgs = {
92         nnfw: args.nnfw,
93         hw: args.hw,
94         customRequirement: args.customRequirement || null
95     };
96
97     var result = native_.callSync('MLCheckNNFWAvailability', callArgs);
98
99     if (native_.isFailure(result)) {
100         return false;
101     }
102     return native_.getResultObject(result);
103 };
104
105 exports = new MachineLearningManager();
106 exports.TensorsInfo = TensorsInfo;