1+ #include < memory>
12#include < thread>
23#include < chrono>
34#include < iostream>
45#include " glm/glm.hpp"
6+ #include " taichi/aot_demo/draws/draw_points.hpp"
57#include " taichi/aot_demo/framework.hpp"
6- #include " taichi/aot_demo/interop/cross_device_copy .hpp"
8+ #include " taichi/aot_demo/shadow_buffer .hpp"
79
810using namespace ti ::aot_demo;
911
@@ -27,42 +29,11 @@ static std::string get_aot_file_dir(TiArch arch) {
2729 }
2830}
2931
30- template <typename T>
31- static void copy_to_vulkan_ndarray (ti::NdArray<T>& dst,
32- GraphicsRuntime& dst_runtime,
33- ti::NdArray<T>& src,
34- ti::Runtime& src_runtime, TiArch src_arch) {
35-
36- switch (src_arch) {
37- case TI_ARCH_VULKAN: {
38- InteropHelper<T>::copy_from_vulkan (dst_runtime, dst, src_runtime, src);
39- break ;
40- }
41- case TI_ARCH_X64: {
42- InteropHelper<T>::copy_from_cpu (dst_runtime, dst, src_runtime, src);
43- break ;
44- }
45- case TI_ARCH_CUDA: {
46- InteropHelper<T>::copy_from_cuda (dst_runtime, dst, src_runtime, src);
47- break ;
48- }
49- case TI_ARCH_OPENGL: {
50- InteropHelper<T>::copy_from_opengl (dst_runtime, dst, src_runtime, src);
51- break ;
52- }
53- default : {
54- throw std::runtime_error (" Unable to perform NdArray memory copy" );
55- }
56- }
57- }
58-
5932struct App2_mpm88 : public App {
6033 static const uint32_t NPARTICLE = 8192 * 2 ;
6134 static const uint32_t GRID_SIZE = 128 ;
6235
63- ti::Runtime runtime_;
6436 ti::AotModule module_;
65- TiArch arch_;
6637
6738 ti::ComputeGraph g_init_;
6839 ti::ComputeGraph g_update_;
@@ -74,8 +45,6 @@ struct App2_mpm88 : public App {
7445 ti::NdArray<float > J_;
7546 ti::NdArray<float > grid_v_;
7647 ti::NdArray<float > grid_m_;
77-
78- ti::NdArray<float > render_x_;
7948
8049 std::unique_ptr<GraphicsTask> draw_points;
8150
@@ -84,49 +53,40 @@ struct App2_mpm88 : public App {
8453 out.app_name = " 2_mpm88" ;
8554 out.framebuffer_width = 256 ;
8655 out.framebuffer_height = 256 ;
56+ out.supported_archs = {
57+ TI_ARCH_VULKAN,
58+ TI_ARCH_CUDA,
59+ TI_ARCH_X64,
60+ };
8761 return out;
8862 }
8963
90-
91- virtual void initialize (TiArch arch) override final {
92- if (arch != TI_ARCH_VULKAN && arch != TI_ARCH_X64 && arch != TI_ARCH_CUDA && arch != TI_ARCH_OPENGL) {
93- std::cout << " 1_hello_world_with_interop only supports cuda, x64, vulkan, opengl backends" << std::endl;
94- exit (0 );
95- }
96- arch_ = arch;
97-
98- GraphicsRuntime& g_runtime = F_->runtime ();
99- if (arch_ == TI_ARCH_VULKAN) {
100- // Reuse the vulkan runtime from renderer framework
101- runtime_ = ti::Runtime (arch_, F_->runtime (), false );;
102- } else {
103- runtime_ = ti::Runtime (arch_);
104- }
64+ virtual void initialize () override final {
65+ Renderer &renderer = F_->renderer ();
66+ ti::Runtime &runtime = F_->runtime ();
10567
10668 // 2. Load AOT module
10769#ifdef TI_AOT_DEMO_WITH_ANDROID_APP
10870 std::vector<uint8_t > tcm;
10971 F_->asset_mgr ().load_file (" E2_mpm88.tcm" , tcm);
110- module_ = runtime_ .create_aot_module (tcm);
72+ module_ = runtime .create_aot_module (tcm);
11173#else
112- auto aot_file_path = get_aot_file_dir (arch_ );
113- module_ = runtime_ .load_aot_module (aot_file_path);
74+ auto aot_file_path = get_aot_file_dir (runtime. arch () );
75+ module_ = runtime .load_aot_module (aot_file_path);
11476#endif
11577
11678 g_init_ = module_.get_compute_graph (" init" );
11779 g_update_ = module_.get_compute_graph (" update" );
11880
119- render_x_ = g_runtime.allocate_vertex_buffer (NPARTICLE, 2 , false /* host_access*/ );
81+ x_ = runtime.allocate_ndarray <float >({NPARTICLE}, {2 });
82+ v_ = runtime.allocate_ndarray <float >({NPARTICLE}, {2 });
83+ pos_ = runtime.allocate_ndarray <float >({NPARTICLE}, {3 });
84+ C_ = runtime.allocate_ndarray <float >({NPARTICLE}, {2 , 2 });
85+ J_ = runtime.allocate_ndarray <float >({NPARTICLE}, {});
86+ grid_v_ = runtime.allocate_ndarray <float >({GRID_SIZE, GRID_SIZE}, {2 });
87+ grid_m_ = runtime.allocate_ndarray <float >({GRID_SIZE, GRID_SIZE}, {});
12088
121- x_ = runtime_.allocate_ndarray <float >({NPARTICLE}, {2 }, false /* host_access*/ );
122- v_ = runtime_.allocate_ndarray <float >({NPARTICLE}, {2 });
123- pos_ = runtime_.allocate_ndarray <float >({NPARTICLE}, {3 });
124- C_ = runtime_.allocate_ndarray <float >({NPARTICLE}, {2 , 2 });
125- J_ = runtime_.allocate_ndarray <float >({NPARTICLE}, {});
126- grid_v_ = runtime_.allocate_ndarray <float >({GRID_SIZE, GRID_SIZE}, {2 });
127- grid_m_ = runtime_.allocate_ndarray <float >({GRID_SIZE, GRID_SIZE}, {});
128-
129- draw_points = g_runtime.draw_points (render_x_)
89+ draw_points = renderer.draw_points (x_)
13090 .point_size (3 .0f )
13191 .color (glm::vec3 (0 ,0 ,1 ))
13292 .build ();
@@ -144,18 +104,13 @@ struct App2_mpm88 : public App {
144104 g_update_[" grid_v" ] = grid_v_;
145105 g_update_[" grid_m" ] = grid_m_;
146106
147- Renderer& renderer = F_->renderer ();
148107 renderer.set_framebuffer_size (256 , 256 );
149108
150109 std::cout << " initialized!" << std::endl;
151110 }
152111 virtual bool update () override final {
153112 g_update_.launch ();
154113
155- auto & g_runtime = F_->runtime ();
156- copy_to_vulkan_ndarray<float >(render_x_, g_runtime, x_, runtime_, arch_);
157- runtime_.wait ();
158-
159114 std::cout << " stepped! (fps=" << F_->fps () << " )" << std::endl;
160115 return true ;
161116 }
0 commit comments