fix a pagefault when wrong argument (extent) passed in hipMemset3D API

Change-Id: I779fc14ccd7c942d1ae0a938ebfd3c2e728ff761
This commit is contained in:
Aryan Salmanpour
2020-09-22 00:53:32 -04:00
zatwierdzone przez Aryan Salmanpour
rodzic 19acb0bfe5
commit a680b514b3
+33 -32
Wyświetl plik
@@ -1850,18 +1850,27 @@ hipError_t ihipMemset3D(hipPitchedPtr pitchedDevPtr,
hipExtent extent,
hipStream_t stream,
bool isAsync = false) {
if (pitchedDevPtr.pitch == extent.width) {
return ihipMemset(pitchedDevPtr.ptr, value, sizeof(int8_t), extent.width * extent.height * extent.depth, stream, isAsync);
}
// Workaround for cases when pitch > row untill fill kernel will be updated to support pitch.
// Fallback to filling one row at a time.
amd::HostQueue* queue = hip::getQueue(stream);
size_t offset = 0;
amd::Memory* memory = getMemoryObject(pitchedDevPtr.ptr, offset);
auto sizeBytes = extent.width * extent.height * extent.depth;
if (memory == nullptr) {
return hipErrorInvalidValue;
}
if (sizeBytes > memory->getSize()) {
return hipErrorInvalidValue;
}
if (pitchedDevPtr.pitch == extent.width) {
return ihipMemset(pitchedDevPtr.ptr, value, sizeof(int8_t), static_cast<size_t>(sizeBytes), stream, isAsync);
}
// Workaround for cases when pitch > row until fill kernel will be updated to support pitch.
// Fall back to filling one row at a time.
amd::HostQueue* queue = hip::getQueue(stream);
amd::Coord3D origin(offset);
amd::Coord3D region(pitchedDevPtr.xsize, pitchedDevPtr.ysize, extent.depth);
amd::BufferRect rect;
@@ -1870,34 +1879,26 @@ hipError_t ihipMemset3D(hipPitchedPtr pitchedDevPtr,
return hipErrorInvalidValue;
}
if (memory != nullptr) {
std::vector<amd::FillMemoryCommand*> commands;
std::vector<amd::FillMemoryCommand*> commands;
for (size_t slice = 0; slice < extent.depth; slice++) {
for (size_t row = 0; row < extent.height; row++) {
const size_t rowOffset = rect.offset(0, row, slice);
amd::FillMemoryCommand* command = new amd::FillMemoryCommand(*queue,
CL_COMMAND_FILL_BUFFER,
amd::Command::EventWaitList{},
*memory->asBuffer(),
&value,
sizeof(int8_t),
amd::Coord3D{rowOffset, 0, 0},
amd::Coord3D{extent.width, 1, 1});
for (size_t slice = 0; slice < extent.depth; slice++) {
for (size_t row = 0; row < extent.height; row++) {
const size_t rowOffset = rect.offset(0, row, slice);
amd::FillMemoryCommand *command = new amd::FillMemoryCommand(*queue,
CL_COMMAND_FILL_BUFFER, amd::Command::EventWaitList { },
*memory->asBuffer(), &value, sizeof(int8_t), amd::Coord3D { rowOffset,
0, 0 }, amd::Coord3D { extent.width, 1, 1 });
command->enqueue();
commands.push_back(command);
}
command->enqueue();
commands.push_back(command);
}
}
for (auto &command: commands) {
if (!isAsync) {
command->awaitCompletion();
}
command->release();
for (auto &command : commands) {
if (!isAsync) {
command->awaitCompletion();
}
} else {
return hipErrorInvalidValue;
command->release();
}
return hipSuccess;