Skip to content

Commit

Permalink
Fix device var uninit when ctx not owned
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed Oct 26, 2024
1 parent a9aaccc commit 510f63d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/CHIPBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,14 @@ void chipstar::Module::invalidateDeviceVariablesNoLock() {

void chipstar::Module::deallocateDeviceVariablesNoLock(
chipstar::Device *Device) {
if (!DeviceVariablesAllocated_)

Check warning on line 433 in src/CHIPBackend.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

src/CHIPBackend.cc:433:34 [readability-braces-around-statements]

statement should be inside braces
return;
invalidateDeviceVariablesNoLock();
for (auto *Var : ChipVars_) {
auto Err = Device->getContext()->free(Var->getDevAddr());
(void)Err;
if (!::Backend->getReinitializeFlag()) {
auto Err = Device->getContext()->free(Var->getDevAddr());
(void)Err;
}
Var->setDevAddr(nullptr);
}
DeviceVariablesAllocated_ = false;
Expand Down
3 changes: 3 additions & 0 deletions src/CHIPBackend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,7 @@ public:
*/
class Backend {
protected:
bool ReinitializeFlag_ = false;
chipstar::EventMonitor *EventMonitor_ = nullptr;

int MinQueuePriority_;
Expand All @@ -1838,6 +1839,8 @@ protected:
std::shared_ptr<spdlog::logger> Logger;

public:
void setReinitializeFlag(bool Flag) { ReinitializeFlag_ = Flag; }
bool getReinitializeFlag() const { return ReinitializeFlag_; }

Check warning on line 1843 in src/CHIPBackend.hh

View workflow job for this annotation

GitHub Actions / cpp-linter

src/CHIPBackend.hh:1843:8 [modernize-use-trailing-return-type]

use a trailing return type for this function
chipstar::Context *PrimaryContext = nullptr;
std::stack<chipstar::Context *> ChipCtxStack;

Expand Down
1 change: 1 addition & 0 deletions src/CHIPDriver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ extern hipError_t CHIPReinitialize(const uintptr_t *NativeHandles,

Backend->initializeFromNative(NativeHandles, NumHandles);
Backend->getActiveDevice()->addFromModuleState(ModuleState);
Backend->setReinitializeFlag(true);

return hipSuccess;
}

0 comments on commit 510f63d

Please sign in to comment.