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:
@@ -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);
|
||||
|
||||
@@ -349,6 +349,7 @@ class Program : public NullProgram {
|
||||
|
||||
//! Return a typecasted GPU device
|
||||
gpu::Device& gpuDevice() {
|
||||
assert(!isNull());
|
||||
return const_cast<gpu::Device&>(static_cast<const gpu::Device&>(device()));
|
||||
}
|
||||
|
||||
@@ -476,6 +477,7 @@ class HSAILProgram : public device::Program {
|
||||
|
||||
//! Return a typecasted GPU device. The device must not be the NullDevice.
|
||||
gpu::Device& gpuDevice() {
|
||||
assert(!isNull());
|
||||
return const_cast<gpu::Device&>(static_cast<const gpu::Device&>(device()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user