Skip to content

Commit

Permalink
Leak fix. (tensorflow#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBroughton authored Feb 17, 2020
1 parent 3e8cc3a commit 2e8dc93
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions tensorflow_quantum/core/qsim/mux_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace {
TEST(MuxTest, GetStateSpace) {
auto simulator = GetStateSpace(1, 1);
EXPECT_FALSE(simulator == nullptr);
delete simulator;
}

} // namespace
Expand Down
2 changes: 0 additions & 2 deletions tensorflow_quantum/core/qsim/state_space.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ bool StateSpace::Valid() const {

float* StateSpace::GetRawState() const { return state_; };

void StateSpace::SetRawState(float* state_update) { state_ = state_update; }

uint64_t StateSpace::GetNumEntries() const { return size_; }

uint64_t StateSpace::GetDimension() const { return size_ / 2; }
Expand Down
5 changes: 1 addition & 4 deletions tensorflow_quantum/core/qsim/state_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class StateSpace {
// Pointer to the raw state managed by this StateSpace
float* GetRawState() const;

// Replace the pointer in this object with a new one
void SetRawState(float* state_update);

// Dimension of the complex Hilbert space represented by this StateSpace
uint64_t GetDimension() const;

Expand Down Expand Up @@ -105,7 +102,7 @@ class StateSpace {
// Set the amplitude at the given state index
virtual void SetAmpl(const uint64_t i, const std::complex<float>& val) = 0;

private:
protected:
float* state_;
uint64_t size_;
uint64_t num_qubits_;
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/qsim/state_space_avx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ StateSpaceAVX::~StateSpaceAVX() { DeleteState(); }
StateSpaceType StateSpaceAVX::GetType() const { return StateSpaceType::AVX; }

void StateSpaceAVX::CreateState() {
SetRawState((float*)qsim::_aligned_malloc(sizeof(float) * GetNumEntries()));
state_ = (float*)qsim::_aligned_malloc(sizeof(float) * GetNumEntries());
}

void StateSpaceAVX::DeleteState() { qsim::_aligned_free(GetRawState()); }
void StateSpaceAVX::DeleteState() { qsim::_aligned_free(state_); }

StateSpace* StateSpaceAVX::Clone() const {
StateSpaceAVX* state_copy =
Expand Down
7 changes: 4 additions & 3 deletions tensorflow_quantum/core/qsim/state_space_slow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ StateSpaceSlow::~StateSpaceSlow() { DeleteState(); }
StateSpaceType StateSpaceSlow::GetType() const { return StateSpaceType::SLOW; }

void StateSpaceSlow::CreateState() {
SetRawState((float*)malloc(sizeof(float) * GetNumEntries()));
state_ = (float*)malloc(sizeof(float) * GetNumEntries());
}

void StateSpaceSlow::DeleteState() { free(GetRawState()); }
void StateSpaceSlow::DeleteState() { free(state_); }

StateSpace* StateSpaceSlow::Clone() const {
StateSpace* state_copy = new StateSpaceSlow(GetNumQubits(), GetNumThreads());
StateSpaceSlow* state_copy =
new StateSpaceSlow(GetNumQubits(), GetNumThreads());
return state_copy;
}

Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/qsim/state_space_sse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ StateSpaceSSE::~StateSpaceSSE() { DeleteState(); }
StateSpaceType StateSpaceSSE::GetType() const { return StateSpaceType::SSE; }

void StateSpaceSSE::CreateState() {
SetRawState((float*)qsim::_aligned_malloc(sizeof(float) * GetNumEntries()));
state_ = (float*)qsim::_aligned_malloc(sizeof(float) * GetNumEntries());
}

void StateSpaceSSE::DeleteState() { qsim::_aligned_free(GetRawState()); }
void StateSpaceSSE::DeleteState() { qsim::_aligned_free(state_); }

StateSpace* StateSpaceSSE::Clone() const {
StateSpaceSSE* state_copy =
Expand Down

0 comments on commit 2e8dc93

Please sign in to comment.