3 #include "waveguide/mesh.h" 5 #include "core/cl/include.h" 6 #include "core/conversions.h" 7 #include "core/exceptions.h" 36 template <
typename step_preprocessor,
typename step_postprocessor>
37 size_t run(
const core::compute_context& cc,
39 step_preprocessor&& pre,
40 step_postprocessor&& post,
41 const std::atomic_bool& keep_going) {
43 const auto num_nodes = mesh.get_structure().get_condensed_nodes().size();
46 cl::CommandQueue queue{cc.context, cc.device};
47 const auto make_zeroed_buffer = [&] {
48 auto ret = cl::Buffer{
49 cc.context, CL_MEM_READ_WRITE,
sizeof(cl_float) * num_nodes};
50 auto kernel =
program.get_zero_buffer_kernel();
51 kernel(cl::EnqueueArgs{queue, cl::NDRange{num_nodes}}, ret);
55 auto previous = make_zeroed_buffer();
56 auto current = make_zeroed_buffer();
58 const auto node_buffer = core::load_to_buffer(
59 cc.context, mesh.get_structure().get_condensed_nodes(),
true);
61 const auto boundary_coefficients_buffer = core::load_to_buffer(
62 cc.context, mesh.get_structure().get_coefficients(),
true);
64 cl::Buffer error_flag_buffer{cc.context, CL_MEM_READ_WRITE,
sizeof(cl_int)};
66 auto boundary_buffer_1 = core::load_to_buffer(
67 cc.context, get_boundary_data<1>(mesh.get_structure()),
false);
68 auto boundary_buffer_2 = core::load_to_buffer(
69 cc.context, get_boundary_data<2>(mesh.get_structure()),
false);
70 auto boundary_buffer_3 = core::load_to_buffer(
71 cc.context, get_boundary_data<3>(mesh.get_structure()),
false);
73 auto kernel =
program.get_kernel();
80 for (; pre(queue, current, step) && keep_going; ++step) {
82 core::write_value(queue, error_flag_buffer, 0, id_success);
85 kernel(cl::EnqueueArgs(queue,
86 cl::NDRange(mesh.get_structure()
87 .get_condensed_nodes()
92 mesh.get_descriptor().dimensions,
96 boundary_coefficients_buffer,
100 if (
const auto error_flag =
101 core::read_value<error_code>(queue, error_flag_buffer, 0)) {
102 if (error_flag & id_inf_error) {
103 throw core::exceptions::value_is_inf(
104 "Pressure value is inf, check filter coefficients.");
107 if (error_flag & id_nan_error) {
108 throw core::exceptions::value_is_nan(
109 "Pressure value is nan, check filter coefficients.");
112 if (error_flag & id_outside_mesh_error) {
113 throw std::runtime_error(
"Tried to read non-existant node.");
116 if (error_flag & id_suspicious_boundary_error) {
117 throw std::runtime_error(
"Suspicious boundary read.");
121 post(queue, current, step);
123 std::swap(previous, current);
Definition: capsule_base.h:9
Definition: gpu_geometry_tests.cpp:24