Skip to content

Commit 4400095

Browse files
committed
Fix kernel argument indices bug
1 parent 39df031 commit 4400095

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

source/adapters/cuda/kernel.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <atomic>
1717
#include <cassert>
1818
#include <numeric>
19+
#include <algorithm>
1920

2021
#include "program.hpp"
2122

@@ -68,6 +69,8 @@ struct ur_kernel_handle_t_ {
6869
args_size_t ParamSizes;
6970
/// Byte offset into /p Storage allocation for each parameter.
7071
args_index_t Indices;
72+
/// Largest argument index that has been added to this kernel so far.
73+
size_t InsertPos = 0;
7174
/// Aligned size in bytes for each local memory parameter after padding has
7275
/// been added. Zero if the argument at the index isn't a local memory
7376
/// argument.
@@ -110,13 +113,13 @@ struct ur_kernel_handle_t_ {
110113
OriginalLocalMemSize.resize(Index + 1);
111114
}
112115
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+
117117
std::memcpy(&Storage[InsertPos], Arg, Size);
118+
118119
Indices[Index] = &Storage[InsertPos];
119120
AlignedLocalMemSize[Index] = LocalSize;
121+
122+
InsertPos += Size;
120123
}
121124

122125
/// Returns the padded size and offset of a local memory argument.
@@ -177,10 +180,7 @@ struct ur_kernel_handle_t_ {
177180
AlignedLocalMemSize[SuccIndex] = SuccAlignedLocalSize;
178181

179182
// 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,
184184
sizeof(size_t));
185185
}
186186
}

0 commit comments

Comments
 (0)