• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 Huawei Technologies Co., Ltd
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 #ifndef MINDSPORE_INCLUDE_JS_API_MSTENSOR_NAPI_H
17 #define MINDSPORE_INCLUDE_JS_API_MSTENSOR_NAPI_H
18 
19 #include "include/api/types.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 
23 namespace mindspore {
24 class MSTensorNapi {
25  public:
26   static napi_value NewInstance(napi_env env, mindspore::MSTensor tensor);
27   MSTensorNapi();
28   ~MSTensorNapi();
29  private:
30   static napi_value Constructor(napi_env env, napi_callback_info info);
31   static void Finalize(napi_env env, void *nativeObject, void *finalize);
32   static napi_value GetConstructor(napi_env env);
33 
34   static napi_value GetName(napi_env env, napi_callback_info info);
35   static napi_value GetShape(napi_env env, napi_callback_info info);
36   static napi_value GetElementNum(napi_env env, napi_callback_info info);
37   static napi_value GetDtype(napi_env env, napi_callback_info info);
38   static napi_value GetFormat(napi_env env, napi_callback_info info);
39   static napi_value GetDataSize(napi_env env, napi_callback_info info);
40   static napi_value GetDataBuffer(napi_env env, napi_callback_info info);
41   static napi_value SetData(napi_env env, napi_callback_info info);
42 
43   static thread_local napi_ref constructor_;
44   napi_env env_ = nullptr;
45 
46   std::unique_ptr<MSTensor> nativeMSTensor_ = nullptr;
47 };
48 }  // namespace mindspore
49 #endif  // MINDSPORE_INCLUDE_JS_API_MSTENSOR_NAPI_H