Skip to content

Commit 4484037

Browse files
authored
Replace ZeroInit with Fill (#474)
Changes "ZeroInitSize" into "FillSize" and introduces "FillValue" to make it possible to fill a buffer with a value other than zero.
1 parent 60c3719 commit 4484037

File tree

250 files changed

+444
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+444
-424
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ Buffers:
8888
- Name: Out1 # Buffer where our output will go
8989
Format: Float32
9090
Stride: 4
91-
ZeroInitSize: 8
91+
FillSize: 8
92+
FillValue: 0.0 # The FillValue is optional and defaults to zero
9293
- Name: Expected1 # Buffer which stores the expected result of our test
9394
Format: Float32
9495
Stride: 4
9596
Data: [ 0.0, 1.0 ]
9697
- Name: Out2 # Buffer where our output will go
9798
Format: Float16
9899
Stride: 2
99-
ZeroInitSize: 4 # ZeroInitSize needs to be 4 bytes minimum
100+
FillSize: 4 # FillSize needs to be 4 bytes minimum
100101
- Name: Expected2 # Buffer which stores the expected result of our test
101102
Format: Float16
102103
Stride: 2

lib/Support/Pipeline.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,36 @@ template <typename T> static void setData(IO &I, offloadtest::Buffer &B) {
138138
return;
139139
}
140140

141-
// zero-initialized buffer(s)
142-
int64_t ZeroInitSize;
143-
I.mapOptional("ZeroInitSize", ZeroInitSize, 0);
144-
if (ZeroInitSize > 0) {
145-
B.Size = ZeroInitSize;
141+
// Buffers can be initialized to be filled with a fixed value.
142+
int64_t FillSize;
143+
144+
// Explicitly reject ZeroInitSize to avoid a confusing error while
145+
// transitioning to FillSize. We can remove this once in flight PRs have had
146+
// time to go in.
147+
I.mapOptional("ZeroInitSize", FillSize, 0);
148+
if (FillSize > 0) {
149+
I.setError("invalid key 'ZeroInitSize' - did you mean 'FillSize'?");
150+
return;
151+
}
152+
153+
T FillValue;
154+
I.mapOptional("FillSize", FillSize, 0);
155+
I.mapOptional("FillValue", FillValue, T{});
156+
if (FillSize > 0) {
157+
B.Size = FillSize;
158+
llvm::SmallVector<T> FillData(FillSize);
159+
std::fill(FillData.begin(), FillData.end(), FillValue);
160+
146161
for (uint32_t I = 0; I < B.ArraySize; I++) {
147162
B.Data.push_back(std::make_unique<char[]>(B.Size));
148-
memset(B.Data.back().get(), 0, B.Size);
163+
memcpy(B.Data.back().get(), FillData.data(), B.Size);
149164
}
150165
return;
151166
}
167+
if (FillValue) {
168+
I.setError("'FillValue' specified without 'FillSize'");
169+
return;
170+
}
152171

153172
// single buffer input
154173
if (B.ArraySize == 1) {

test/Basic/DescriptorSets.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Buffers:
2323
- Name: Out1
2424
Format: Float32
2525
Channels: 4
26-
ZeroInitSize: 16
26+
FillSize: 16
2727
- Name: Out2
2828
Format: Float32
2929
Channels: 4
30-
ZeroInitSize: 16
30+
FillSize: 16
3131
DescriptorSets:
3232
- Resources:
3333
- Name: In

test/Basic/Mandelbrot.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Buffers:
6262
- Name: Tex
6363
Format: Float32
6464
Channels: 4
65-
ZeroInitSize: 268435456 # 1024 * 1024 * 4 channels / pixel * 4 bytes / channel
65+
FillSize: 268435456 # 1024 * 1024 * 4 channels / pixel * 4 bytes / channel
6666
OutputProps:
6767
Height: 4096
6868
Width: 4096

test/Basic/matrix_m-based_getter.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Buffers:
5050
Data: [ 1, 2, 3, 4]
5151
- Name: Out
5252
Format: Int32
53-
ZeroInitSize: 16
53+
FillSize: 16
5454
- Name: ExpectedOut
5555
Format: Int32
5656
Data: [ 1, 2, 3, 4 ]

test/Basic/matrix_one-based_getter.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Buffers:
5252
Data: [ 1, 2, 3, 4]
5353
- Name: Out
5454
Format: Int32
55-
ZeroInitSize: 16
55+
FillSize: 16
5656
- Name: ExpectedOut
5757
Format: Int32
5858
Data: [ 1, 2, 3, 4 ]

test/Basic/matrix_scalar_arithmetic.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ Buffers:
3232
Data: [ 2, 4, 6, 8, 10, 12 ]
3333
- Name: DivOut
3434
Format: Int32
35-
ZeroInitSize: 24
35+
FillSize: 24
3636
- Name: MulOut
3737
Format: Int32
38-
ZeroInitSize: 24
38+
FillSize: 24
3939
- Name: AddOut
4040
Format: Int32
41-
ZeroInitSize: 24
41+
FillSize: 24
4242
- Name: SubOut
4343
Format: Int32
44-
ZeroInitSize: 24
44+
FillSize: 24
4545
DescriptorSets:
4646
- Resources:
4747
- Name: In

test/Basic/matrix_scalar_constructor.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ RWBuffer<int> Out : register(u1);
55

66
[numthreads(6,1,1)]
77
void main(uint GI : SV_GroupIndex) {
8-
int2x3 A = int2x3(In[0], In[1], In[2],
9-
In[3], In[4], In[5]);
10-
8+
int2x3 A = int2x3(In[0], In[1], In[2],
9+
In[3], In[4], In[5]);
10+
1111
int row = GI / 2;
1212
int col = GI % 2;
1313
Out[GI] = A[col][row];
@@ -26,7 +26,7 @@ Buffers:
2626
Data: [ 1, 2, 3, 4, 5, 6]
2727
- Name: Out
2828
Format: Int32
29-
ZeroInitSize: 24
29+
FillSize: 24
3030
- Name: ExpectedOut
3131
Format: Int32
3232
Data: [ 1, 4, 2, 5, 3, 6 ]

test/Basic/simple.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Buffers:
2121
- Name: Out
2222
Format: Float32
2323
Channels: 4
24-
ZeroInitSize: 16
24+
FillSize: 16
2525
DescriptorSets:
2626
- Resources:
2727
- Name: In

test/Bugs/UAV-Sequental-Consistency.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Buffers:
2727
- Name: Result
2828
Format: Int32
2929
Stride: 4
30-
ZeroInitSize: 16
30+
FillSize: 16
3131
- Name: ExpectedResult
3232
Format: Int32
3333
Stride: 4

0 commit comments

Comments
 (0)