Skip to content

Commit a9d4130

Browse files
1tnguyenbettinaheim
authored andcommitted
Fix uninitialized memory issue for the result buffer in kron (#2475)
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
1 parent ceb6132 commit a9d4130

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

runtime/nvqir/custatevec/CuStateVecCircuitSimulator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ class CuStateVecCircuitSimulator
216216
void *newDeviceStateVector;
217217
HANDLE_CUDA_ERROR(cudaMalloc((void **)&newDeviceStateVector,
218218
stateDimension * sizeof(CudaDataType)));
219-
219+
HANDLE_CUDA_ERROR(cudaMemset(newDeviceStateVector, 0,
220+
stateDimension * sizeof(CudaDataType)));
220221
// Place the state data on device. Could be that
221222
// we just need the zero state, or the user could have provided one
222223
void *otherState;
@@ -283,6 +284,8 @@ class CuStateVecCircuitSimulator
283284
void *newDeviceStateVector;
284285
HANDLE_CUDA_ERROR(cudaMalloc((void **)&newDeviceStateVector,
285286
stateDimension * sizeof(CudaDataType)));
287+
HANDLE_CUDA_ERROR(cudaMemset(newDeviceStateVector, 0,
288+
stateDimension * sizeof(CudaDataType)));
286289
constexpr int32_t threads_per_block = 256;
287290
uint32_t n_blocks =
288291
(stateDimension + threads_per_block - 1) / threads_per_block;

0 commit comments

Comments
 (0)