Skip to content

Commit c39587b

Browse files
committed
Metal: fix minor shared buffer issues
1 parent 0555a4a commit c39587b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

apps/oidnTest.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,18 @@ TEST_CASE("device creation", "[device]")
146146

147147
TEST_CASE("buffer creation", "[buffer]")
148148
{
149+
const size_t bufferSize = 1024*768*3*4; // Metal requires shared buffer size to be multiple of 16K
149150
DeviceRef device = makeAndCommitDevice();
150151

151152
SECTION("default buffer")
152153
{
153-
BufferRef buffer = device.newBuffer(1234567);
154+
BufferRef buffer = device.newBuffer(bufferSize);
154155
REQUIRE(device.getError() == Error::None);
155156
}
156157

157158
SECTION("device buffer")
158159
{
159-
BufferRef buffer = device.newBuffer(1234567, Storage::Device);
160+
BufferRef buffer = device.newBuffer(bufferSize, Storage::Device);
160161
REQUIRE(device.getError() == Error::None);
161162
}
162163

@@ -167,14 +168,14 @@ TEST_CASE("buffer creation", "[buffer]")
167168

168169
if (managedMemorySupported)
169170
{
170-
BufferRef buffer = device.newBuffer(1234567, Storage::Managed);
171+
BufferRef buffer = device.newBuffer(bufferSize, Storage::Managed);
171172
REQUIRE(device.getError() == Error::None);
172173
}
173174
}
174175

175176
SECTION("shared buffer")
176177
{
177-
BufferRef buffer = device.newBuffer(1234567);
178+
BufferRef buffer = device.newBuffer(bufferSize);
178179
REQUIRE(device.getError() == Error::None);
179180

180181
BufferRef sharedBuffer = device.newBuffer(buffer.getData(), buffer.getSize());
@@ -195,7 +196,7 @@ TEST_CASE("buffer creation", "[buffer]")
195196

196197
SECTION("zero-sized shared buffer")
197198
{
198-
BufferRef buffer = device.newBuffer(1234567);
199+
BufferRef buffer = device.newBuffer(bufferSize);
199200
REQUIRE(device.getError() == Error::None);
200201

201202
BufferRef sharedBuffer = device.newBuffer(buffer.getData(), 0);
@@ -218,13 +219,13 @@ TEST_CASE("buffer creation", "[buffer]")
218219

219220
SECTION("invalid buffer storage")
220221
{
221-
BufferRef buffer = device.newBuffer(10000, static_cast<Storage>(-42));
222+
BufferRef buffer = device.newBuffer(bufferSize, static_cast<Storage>(-42));
222223
REQUIRE(device.getError() == Error::InvalidArgument);
223224
}
224225

225226
SECTION("device released before buffer")
226227
{
227-
BufferRef buffer = device.newBuffer(123456);
228+
BufferRef buffer = device.newBuffer(bufferSize);
228229
REQUIRE(device.getError() == Error::None);
229230
device.release();
230231
}
@@ -715,6 +716,7 @@ TEST_CASE("shared image", "[shared_image]")
715716

716717
TEST_CASE("inplace filter", "[inplace_filter]")
717718
{
719+
// Metal requires shared buffer size to be multiple of 16K
718720
const int W = 1920;
719721
const int H = 1080;
720722

devices/metal/metal_buffer.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
deallocator: nil];
6565

6666
if (!buffer)
67-
throw Exception(Error::OutOfMemory, "failed to create buffer");
67+
throw Exception(Error::InvalidArgument, "failed to create buffer");
6868
}
6969

7070
MetalBuffer::MetalBuffer(MetalEngine* engine, id<MTLBuffer> buffer)

doc/api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ its size in bytes. At buffer construction time no buffer data is allocated, but
714714
the buffer data provided by the user is used. The buffer data must remain valid
715715
for as long as the buffer may be used, and the user is responsible to free the
716716
buffer data when no longer required. The user must also ensure that the memory is
717-
accessible by the device by using allocation functions supported by the device
718-
(e.g. `sycl::malloc_device`, `cudaMalloc`, `hipMalloc`).
717+
accessible to the device by using a supported allocation function (e.g.
718+
`sycl::malloc_device`, `cudaMalloc`, `hipMalloc`) and alignment (e.g. Metal
719+
requires the allocation to be page-aligned).
719720

720721
Buffers can be also imported from graphics APIs as external memory, to avoid
721722
expensive copying of data through host memory. Different types of external

0 commit comments

Comments
 (0)