Capture the 3-stage pipeline into a CUDA graph and return it.
(stream, kernels, config, buffers, size)
| 107 | |
| 108 | |
| 109 | def build_graph(stream, kernels, config, buffers, size): |
| 110 | """Capture the 3-stage pipeline into a CUDA graph and return it.""" |
| 111 | add_k, mul_k, sub_k = kernels |
| 112 | a, b, c, r1, r2, r3 = buffers |
| 113 | |
| 114 | graph_builder = stream.create_graph_builder() |
| 115 | graph_builder.begin_building() |
| 116 | launch( |
| 117 | graph_builder, |
| 118 | config, |
| 119 | add_k, |
| 120 | a.data.ptr, |
| 121 | b.data.ptr, |
| 122 | r1.data.ptr, |
| 123 | np.uint64(size), |
| 124 | ) |
| 125 | launch( |
| 126 | graph_builder, |
| 127 | config, |
| 128 | mul_k, |
| 129 | r1.data.ptr, |
| 130 | c.data.ptr, |
| 131 | r2.data.ptr, |
| 132 | np.uint64(size), |
| 133 | ) |
| 134 | launch( |
| 135 | graph_builder, |
| 136 | config, |
| 137 | sub_k, |
| 138 | r2.data.ptr, |
| 139 | a.data.ptr, |
| 140 | r3.data.ptr, |
| 141 | np.uint64(size), |
| 142 | ) |
| 143 | graph_builder.end_building() |
| 144 | graph = graph_builder.complete() |
| 145 | graph.upload(stream) |
| 146 | return graph_builder, graph |
| 147 | |
| 148 | |
| 149 | def run_pipeline_graph(stream, graph, n_iters): |