| 67 | } // namespace |
| 68 | |
| 69 | std::vector<ComputeTaskDescriptorPtr> Add(int id, |
| 70 | const std::vector<ValueId> input_ids, |
| 71 | ValueId output_id, |
| 72 | const AddAttributes& attr, |
| 73 | const RuntimeOptions& options) { |
| 74 | auto desc = std::make_shared<ComputeTaskDescriptor>(); |
| 75 | desc->id = id; |
| 76 | |
| 77 | // Add scalar |
| 78 | const float* add_value = absl::get_if<float>(&attr.param); |
| 79 | if (add_value) { |
| 80 | desc->is_linkable = true; |
| 81 | desc->shader_source = |
| 82 | R"(FLT4 linkable$0(FLT4 value, int linear_index, uint3 gid) { |
| 83 | return value + )" + |
| 84 | std::to_string(*add_value) + ";}"; |
| 85 | desc->input_buffers = {{input_ids[0]}}; |
| 86 | desc->output_buffer = {output_id}; |
| 87 | return {desc}; |
| 88 | } |
| 89 | |
| 90 | desc->is_linkable = false; |
| 91 | desc->shader_source = GetAddTableCode(input_ids.size()); |
| 92 | |
| 93 | for (int i = 0; i < input_ids.size(); ++i) { |
| 94 | const std::string buffer_name = |
| 95 | "device FLT4* const src_buffer" + std::to_string(i); |
| 96 | desc->input_buffers.push_back({input_ids[i], buffer_name}); |
| 97 | } |
| 98 | |
| 99 | desc->output_buffer = {output_id, "device FLT4* dst_buffer", |
| 100 | [input_ids](const std::map<ValueId, BHWC>& buffers) { |
| 101 | return buffers.find(input_ids[0])->second; |
| 102 | }}; |
| 103 | |
| 104 | desc->uniform_buffers = { |
| 105 | {"constant uniforms& params", |
| 106 | [input_ids](const std::map<ValueId, BHWC>& buffers) { |
| 107 | const auto& dimension = buffers.find(input_ids[0])->second; |
| 108 | std::vector<int> uniform_params = {dimension.w, dimension.h, 0, 0}; |
| 109 | return VectorToUint8Vector(uniform_params); |
| 110 | }}, |
| 111 | }; |
| 112 | |
| 113 | desc->resize_function = [input_ids](const std::map<ValueId, BHWC>& buffers) { |
| 114 | const auto& src_dim = buffers.find(input_ids[0])->second; |
| 115 | const uint3 groups_size{16, 16, 1}; |
| 116 | int groups_x = IntegralDivideRoundUp(src_dim.w, groups_size.x); |
| 117 | int groups_y = IntegralDivideRoundUp(src_dim.h, groups_size.y); |
| 118 | const int dst_layers = IntegralDivideRoundUp(src_dim.c, 4); |
| 119 | int groups_z = IntegralDivideRoundUp(dst_layers, groups_size.z); |
| 120 | return std::make_pair(groups_size, uint3{groups_x, groups_y, groups_z}); |
| 121 | }; |
| 122 | return {desc}; |
| 123 | } |
| 124 | |
| 125 | } // namespace metal |
| 126 | } // namespace gpu |
no test coverage detected