Add stronger checking

- Add assertions to enforce that objects are of the correct kind and
  have been allocated.

- Make destructors check if objects have been allocated before
  deleting.

- Operations that require a non-NullDevice return failure if given a
  NullDevice.

- Use static_cast rather than reinterpret_cast when cohersing from a
  base class to a derived class.

Change-Id: I02ee0ea9d7982fd7ca29d49c9b02cfae111b7127
This commit is contained in:
Tony Tye
2021-01-10 02:09:00 +00:00
parent 001fd66cac
commit e5431676d4
11 changed files with 96 additions and 13 deletions
+10 -1
View File
@@ -1505,6 +1505,7 @@ HSAILProgram::HSAILProgram(Device& device, amd::Program& owner)
maxScratchRegs_(0),
executable_(NULL),
loaderContext_(this) {
assert(device.isOnline());
machineTarget_ = gpuNullDevice().hwInfo()->targetName_;
loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}
@@ -1516,9 +1517,12 @@ HSAILProgram::HSAILProgram(NullDevice& device, amd::Program& owner)
maxScratchRegs_(0),
executable_(NULL),
loaderContext_(this) {
assert(!device.isOnline());
isNull_ = true;
machineTarget_ = gpuNullDevice().hwInfo()->targetName_;
loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
// Cannot load onto a NullDevice.
loader_ = nullptr;
}
HSAILProgram::~HSAILProgram() {
@@ -1736,6 +1740,11 @@ std::string HSAILProgram::hsailOptions() {
}
bool HSAILProgram::allocKernelTable() {
if (isNull()) {
// Cannot create a kernel table for offline devices.
return false;
}
uint size = kernels().size() * sizeof(size_t);
kernels_ = new gpu::Memory(gpuDevice(), size);