Restructure GPU compilation execution pipeline (#903)

* Restructure gpu compilation execution pipeline

* Add compilation server/client infrastructure

* Add wgpu executor
This commit is contained in:
Dennis Kobert
2022-12-31 02:52:04 +01:00
committed by Keavon Chambers
parent be32f7949f
commit 79ad3e7908
43 changed files with 2744 additions and 482 deletions

View File

@@ -11,7 +11,9 @@ license = "MIT OR Apache-2.0"
[features]
memoization = ["once_cell"]
default = ["memoization"]
gpu = ["graph-craft/gpu", "graphene-core/gpu"]
gpu = ["graphene-core/gpu", "gpu-compiler-bin-wrapper", "compilation-client"]
vulkan = ["gpu", "vulkan-executor"]
wgpu = ["gpu", "wgpu-executor"]
[dependencies]
@@ -19,6 +21,10 @@ graphene-core = {path = "../gcore", features = ["async", "std" ], default-featur
borrow_stack = {path = "../borrow_stack"}
dyn-any = {path = "../../libraries/dyn-any", features = ["derive"]}
graph-craft = {path = "../graph-craft"}
vulkan-executor = {path = "../vulkan-executor", optional = true}
wgpu-executor = {path = "../wgpu-executor", optional = true}
gpu-compiler-bin-wrapper = {path = "../gpu-compiler/gpu-compiler-bin-wrapper", optional = true}
compilation-client = {path = "../compilation-client", optional = true}
bytemuck = {version = "1.8" }
tempfile = "3"
once_cell = {version= "1.10", optional = true}

View File

@@ -14,47 +14,26 @@ impl<'n, I: IntoIterator<Item = S>, NN: Node<(), Output = &'n NodeNetwork> + Cop
fn eval(self, input: I) -> Self::Output {
let network = self.0.eval(());
use graph_craft::executor::Compiler;
use graph_craft::executor::Executor;
use graph_craft::gpu::compiler::Metadata;
let compiler = Compiler {};
let proto_network = compiler.compile(network.clone(), true);
let m = Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
use graph_craft::gpu::context::Context;
use graph_craft::gpu::executor::GpuExecutor;
let executor: GpuExecutor<S, O> = GpuExecutor::new(Context::new(), proto_network, m, temp_dir.path()).unwrap();
let data: Vec<_> = input.into_iter().collect();
let result = executor.execute(Box::new(data)).unwrap();
let result = dyn_any::downcast::<Vec<O>>(result).unwrap();
*result
map_gpu_impl(network, input)
}
}
fn map_gpu_impl<I: IntoIterator<Item = S>, S: StaticTypeSized + Sync + Send + Pod, O: StaticTypeSized + Sync + Send + Pod>(network: &NodeNetwork, input: I) -> Vec<O> {
use graph_craft::executor::Executor;
let bytes = compilation_client::compile_sync::<S, O>(network.clone()).unwrap();
let words = unsafe { std::slice::from_raw_parts(bytes.as_ptr() as *const u32, bytes.len() / 4) };
use wgpu_executor::{Context, GpuExecutor};
let executor: GpuExecutor<S, O> = GpuExecutor::new(Context::new_sync().unwrap(), words.into(), "gpu::eval".into()).unwrap();
let data: Vec<_> = input.into_iter().collect();
let result = executor.execute(Box::new(data)).unwrap();
let result = dyn_any::downcast::<Vec<O>>(result).unwrap();
*result
}
impl<'n, I: IntoIterator<Item = S>, NN: Node<(), Output = &'n NodeNetwork> + Copy, S: StaticTypeSized + Sync + Send + Pod, O: StaticTypeSized + Sync + Send + Pod> Node<I> for MapGpuNode<NN, I, S, O> {
type Output = Vec<O>;
fn eval(self, input: I) -> Self::Output {
let network = self.0.eval(());
use graph_craft::executor::Compiler;
use graph_craft::executor::Executor;
use graph_craft::gpu::compiler::Metadata;
let compiler = Compiler {};
let proto_network = compiler.compile(network.clone(), true);
let m = Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
use graph_craft::gpu::context::Context;
use graph_craft::gpu::executor::GpuExecutor;
let executor: GpuExecutor<S, O> = GpuExecutor::new(Context::new(), proto_network, m, temp_dir.path()).unwrap();
let data: Vec<_> = input.into_iter().collect();
let result = executor.execute(Box::new(data)).unwrap();
let result = dyn_any::downcast::<Vec<O>>(result).unwrap();
*result
map_gpu_impl(network, input)
}
}
@@ -79,6 +58,8 @@ impl<NN: Node<(), Output = String> + Copy> Node<Image> for MapGpuSingleImageNode
let network = NodeNetwork {
inputs: vec![0],
disabled: vec![],
previous_output: None,
output: 0,
nodes: [(
0,
@@ -114,6 +95,8 @@ impl<NN: Node<(), Output = String> + Copy> Node<Image> for &MapGpuSingleImageNod
let network = NodeNetwork {
inputs: vec![0],
output: 0,
disabled: vec![],
previous_output: None,
nodes: [(
0,
DocumentNode {