Commit 260cb90d authored by Fenglei's avatar Fenglei Committed by Scott Cyphers

gpu_external_function and gpu constant memory refactor (#1189)

* refactor external function

* wokring version

* fix bug

* add emit_fucntions, emit_declare_constants, emit_declare_functions

* add std::

* add functions declaration

* fix bugs

* fix bugs

* separate temp memory allocation and release

* add invoke_constant_ptr function, clean up outputs for function

* fix bugs, compiled ok

* add ctx to emit_declare_constant

* cleanup code, code style

* remove using std, code style

* revert std changes

* change function names based Chris's comments

* add ResultCopyElimination to pass_manager

* clang format
parent 2c345798
...@@ -26,6 +26,12 @@ ...@@ -26,6 +26,12 @@
#include "ngraph/codegen/compiler.hpp" #include "ngraph/codegen/compiler.hpp"
#include "ngraph/codegen/execution_engine.hpp" #include "ngraph/codegen/execution_engine.hpp"
#include "ngraph/function.hpp" #include "ngraph/function.hpp"
#include "ngraph/pass/assign_layout.hpp"
#include "ngraph/pass/dump_sorted.hpp"
#include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/memory_layout.hpp"
#include "ngraph/pass/result_copy_elimination.hpp"
#include "ngraph/runtime/gpu/gpu_call_frame.hpp" #include "ngraph/runtime/gpu/gpu_call_frame.hpp"
#include "ngraph/runtime/gpu/gpu_primitive_emitter.hpp" #include "ngraph/runtime/gpu/gpu_primitive_emitter.hpp"
#include "ngraph/runtime/gpu/gpu_tensor_view_wrapper.hpp" #include "ngraph/runtime/gpu/gpu_tensor_view_wrapper.hpp"
...@@ -58,6 +64,7 @@ namespace ngraph ...@@ -58,6 +64,7 @@ namespace ngraph
GPU_ExternalFunction(const std::shared_ptr<ngraph::Function>& function, GPU_ExternalFunction(const std::shared_ptr<ngraph::Function>& function,
bool release_function = true); bool release_function = true);
~GPU_ExternalFunction(); ~GPU_ExternalFunction();
std::shared_ptr<ngraph::runtime::gpu::GPU_CallFrame> make_call_frame(); std::shared_ptr<ngraph::runtime::gpu::GPU_CallFrame> make_call_frame();
std::unique_ptr<runtime::gpu::GPURuntimeContext>& ctx(); std::unique_ptr<runtime::gpu::GPURuntimeContext>& ctx();
const std::unique_ptr<GPUPrimitiveEmitter>& get_primitive_emitter() const const std::unique_ptr<GPUPrimitiveEmitter>& get_primitive_emitter() const
...@@ -71,39 +78,46 @@ namespace ngraph ...@@ -71,39 +78,46 @@ namespace ngraph
EntryPoint m_compiled_function; EntryPoint m_compiled_function;
private: private:
void emit_debug_function_entry(codegen::CodeWriter& writer, void collect_unique_functions();
Node* node, void emit_header();
const std::vector<GPU_TensorViewWrapper>& in, void emit_timer_functions();
const std::vector<GPU_TensorViewWrapper>& out); void emit_constant_declarations();
void emit_debug_function_exit(codegen::CodeWriter& writer, void emit_function_declarations();
Node* node, void emit_functions();
const std::vector<GPU_TensorViewWrapper>& in, void emit_debug_function_entry(Node* node);
const std::vector<GPU_TensorViewWrapper>& out); void emit_debug_function_exit(Node* node);
void handle_output_alias( void emit_temp_mem_pool_allocation(std::shared_ptr<Function> current_function);
codegen::CodeWriter& writer, void emit_temp_mem_pool_release();
const Node&,
const std::unordered_map<descriptor::TensorView*, std::vector<size_t>>&);
void release_function() { m_function = nullptr; } void release_function() { m_function = nullptr; }
void store_emitted_functions(const std::string& code);
std::string emit_op_as_function(const Node& node, const std::string& function_name); std::string emit_op_as_function(const Node& node, const std::string& function_name);
std::string strip_comments(const std::string& s) const; std::string strip_comments(const std::string& s) const;
bool is_functionally_identical(
const Node& n1, codegen::CodeWriter m_writer;
const Node& n2, pass::Manager m_pass_manager;
const std::unordered_map<const Node*, std::string>& node_cache) const;
std::unique_ptr<codegen::Compiler> m_compiler; std::unique_ptr<codegen::Compiler> m_compiler;
std::unique_ptr<codegen::ExecutionEngine> m_execution_engine; std::unique_ptr<codegen::ExecutionEngine> m_execution_engine;
bool m_emit_timing; std::unique_ptr<GPUPrimitiveEmitter> m_primitive_emitter;
std::unordered_map<std::string, std::string> m_variable_name_map; std::unique_ptr<GPURuntimeContext> m_ctx;
std::map<std::string, size_t> m_name_index_map;
std::shared_ptr<ngraph::Function> m_function; std::shared_ptr<ngraph::Function> m_function;
bool m_release_function;
std::map<std::string, size_t> m_name_index_map;
std::unordered_map<std::string, std::string> m_variable_name_map;
std::unordered_map<const Node*, std::string> m_node_function_map;
std::unordered_map<std::shared_ptr<Function>, std::list<std::shared_ptr<Node>>>
m_function_ordered_ops;
bool m_emit_timing;
bool m_is_compiled; bool m_is_compiled;
bool m_release_function;
bool m_temporaries_used;
std::string m_function_name;
std::string m_pch_header_source;
cublasHandle_t m_cublas_handle; cublasHandle_t m_cublas_handle;
cudnnHandle_t m_cudnn_handle; cudnnHandle_t m_cudnn_handle;
std::unique_ptr<GPUPrimitiveEmitter> m_primitive_emitter;
std::unique_ptr<GPURuntimeContext> m_ctx;
}; };
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment