Skip to content

Commit

Permalink
Optimize Decompose()/Dispose()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Nov 2, 2024
1 parent 641f639 commit 7ea9e0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/common/qengine.cl
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap
}

partStateProb[lcv] = partProb;
const real1 prob = partStateProb[lcv];
if (prob > REAL1_EPSILON) {
partStateAngle[lcv] /= prob;
}
}

for (bitCapIntOcl lcv = ID; lcv < remainderPower; lcv += Nthreads) {
Expand All @@ -618,13 +622,6 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap
remainderStateAngle[lcv] /= prob;
}
}

for (bitCapIntOcl lcv = ID; lcv < partPower; lcv += Nthreads) {
const real1 prob = partStateProb[lcv];
if (prob > REAL1_EPSILON) {
partStateAngle[lcv] /= prob;
}
}
}

void kernel decomposeamp(
Expand Down
11 changes: 5 additions & 6 deletions src/qengine/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,19 +1200,18 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP
partStateProb[lcv] += nrm;
remainderStateAngle[k] += arg(amp) * nrm;
}

const real1 prob = partStateProb[lcv];
if (prob > amplitudeFloor) {
partStateAngle[lcv] /= prob;
}
});
par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
const real1 prob = remainderStateProb[lcv];
if (prob > amplitudeFloor) {
remainderStateAngle[lcv] /= prob;
}
});
par_for(0U, partPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
const real1 prob = partStateProb[lcv];
if (prob > amplitudeFloor) {
partStateAngle[lcv] /= prob;
}
});
} else {
par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) {
bitCapIntOcl j = lcv & pow2MaskOcl(start);
Expand Down

0 comments on commit 7ea9e0e

Please sign in to comment.