forked from OpenPPL/ppl.nn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_pplnn.cc
More file actions
80 lines (67 loc) · 2.99 KB
/
lua_pplnn.cc
File metadata and controls
80 lines (67 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "ppl/nn/common/common.h"
#include "luacpp.h"
#include <memory>
using namespace std;
using namespace luacpp;
namespace ppl { namespace nn { namespace lua {
#ifdef PPLNN_USE_X86
void RegisterX86EngineOptions(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterX86Engine(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterX86EngineFactory(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
#endif
#ifdef PPLNN_USE_CUDA
void RegisterCudaEngineOptions(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterCudaEngine(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterCudaEngineFactory(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
#endif
void RegisterGetVersionString(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterTensorShape(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterTensor(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterRuntime(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterRuntimeBuilder(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
void RegisterOnnxRuntimeBuilderFactory(const shared_ptr<LuaState>&, const shared_ptr<LuaTable>&);
}}}
using namespace ppl::nn::lua;
extern "C" {
/* require("luappl.nn") */
int PPLNN_PUBLIC luaopen_luappl_nn(lua_State* l) {
// may be used by module functions outside this function scope
auto lstate = make_shared<LuaState>(l, false);
auto lmodule = make_shared<LuaTable>(lstate->CreateTable());
// NOTE register classes in order
#ifdef PPLNN_USE_CUDA
RegisterCudaEngineOptions(lstate, lmodule);
RegisterCudaEngine(lstate, lmodule);
RegisterCudaEngineFactory(lstate, lmodule);
#endif
#ifdef PPLNN_USE_X86
RegisterX86EngineOptions(lstate, lmodule);
RegisterX86Engine(lstate, lmodule);
RegisterX86EngineFactory(lstate, lmodule);
#endif
RegisterGetVersionString(lstate, lmodule);
RegisterTensorShape(lstate, lmodule);
RegisterTensor(lstate, lmodule);
RegisterRuntime(lstate, lmodule);
RegisterRuntimeBuilder(lstate, lmodule);
RegisterOnnxRuntimeBuilderFactory(lstate, lmodule);
lmodule->PushSelf();
return 1;
}
}