|
16 | 16 | #include <atomic>
|
17 | 17 | #include <cassert>
|
18 | 18 | #include <numeric>
|
| 19 | +#include <algorithm> |
19 | 20 |
|
20 | 21 | #include "program.hpp"
|
21 | 22 |
|
@@ -68,6 +69,8 @@ struct ur_kernel_handle_t_ {
|
68 | 69 | args_size_t ParamSizes;
|
69 | 70 | /// Byte offset into /p Storage allocation for each parameter.
|
70 | 71 | args_index_t Indices;
|
| 72 | + /// Largest argument index that has been added to this kernel so far. |
| 73 | + size_t InsertPos = 0; |
71 | 74 | /// Aligned size in bytes for each local memory parameter after padding has
|
72 | 75 | /// been added. Zero if the argument at the index isn't a local memory
|
73 | 76 | /// argument.
|
@@ -110,13 +113,13 @@ struct ur_kernel_handle_t_ {
|
110 | 113 | OriginalLocalMemSize.resize(Index + 1);
|
111 | 114 | }
|
112 | 115 | ParamSizes[Index] = Size;
|
113 |
| - // calculate the insertion point on the array |
114 |
| - size_t InsertPos = std::accumulate(std::begin(ParamSizes), |
115 |
| - std::begin(ParamSizes) + Index, 0); |
116 |
| - // Update the stored value for the argument |
| 116 | + |
117 | 117 | std::memcpy(&Storage[InsertPos], Arg, Size);
|
| 118 | + |
118 | 119 | Indices[Index] = &Storage[InsertPos];
|
119 | 120 | AlignedLocalMemSize[Index] = LocalSize;
|
| 121 | + |
| 122 | + InsertPos += Size; |
120 | 123 | }
|
121 | 124 |
|
122 | 125 | /// Returns the padded size and offset of a local memory argument.
|
@@ -177,10 +180,7 @@ struct ur_kernel_handle_t_ {
|
177 | 180 | AlignedLocalMemSize[SuccIndex] = SuccAlignedLocalSize;
|
178 | 181 |
|
179 | 182 | // Store new offset into local data
|
180 |
| - const size_t InsertPos = |
181 |
| - std::accumulate(std::begin(ParamSizes), |
182 |
| - std::begin(ParamSizes) + SuccIndex, size_t{0}); |
183 |
| - std::memcpy(&Storage[InsertPos], &SuccAlignedLocalOffset, |
| 183 | + std::memcpy(Indices[SuccIndex], &SuccAlignedLocalOffset, |
184 | 184 | sizeof(size_t));
|
185 | 185 | }
|
186 | 186 | }
|
|
0 commit comments