1 | /** |
2 | * Copyright (c) Glow Contributors. See CONTRIBUTORS file. |
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 GLOW_LLVMIRCODEGEN_LLVMCOMPILEDFUNCTION_H |
17 | #define GLOW_LLVMIRCODEGEN_LLVMCOMPILEDFUNCTION_H |
18 | |
19 | #include "glow/LLVMIRCodeGen/GlowJIT.h" |
20 | |
21 | #include "glow/Backend/BackendUtils.h" |
22 | #include "glow/Backend/CompiledFunction.h" |
23 | |
24 | namespace glow { |
25 | /// A Glow IR function compiled using LLVM. |
26 | class LLVMCompiledFunction : public CompiledFunction { |
27 | public: |
28 | LLVMCompiledFunction(std::unique_ptr<GlowJIT> JIT, |
29 | runtime::RuntimeBundle &&runtimeBundle); |
30 | |
31 | /// \name CompiledFunction interface |
32 | ///@{ |
33 | virtual Error execute(ExecutionContext *context) override; |
34 | |
35 | virtual void collectConstants(const Module *module) override; |
36 | |
37 | /// Read trace events out of this func and write them into /p bindings |
38 | virtual void translateTraceEvents(ExecutionContext *context) const override; |
39 | ///@} |
40 | // |
41 | |
42 | protected: |
43 | /// Load constant tensors from \p bindings into \p weightsAddress, as defined |
44 | /// by the RuntimeBundle (pre-run). |
45 | virtual void loadPlaceholders(PlaceholderBindings *bindings, |
46 | uint8_t *weightsAddress); |
47 | |
48 | /// Load weights from \p weightsAddress into applicable backing tensors in |
49 | /// \p bindings, as defined by the RuntimeBundle (post-run). |
50 | virtual void updatePlaceholders(PlaceholderBindings *bindings, |
51 | uint8_t *weightsAddress); |
52 | |
53 | /// The LLVM JIT engine. The jit must be initialized after the ctor |
54 | /// initializes the LLVM backends. |
55 | std::unique_ptr<GlowJIT> JIT_; |
56 | |
57 | /// The JIT can be accessed from multiple threads but is not thread safe, |
58 | /// JITLock_ protects it. |
59 | std::mutex JITLock_; |
60 | }; |
61 | } // end namespace glow |
62 | |
63 | #endif // GLOW_LLVMIRCODEGEN_LLVMCOMPILEDFUNCTION_H |
64 | |