Skip to content

Commit

Permalink
Fix issues detected by Coverity (2024.01) (NVIDIA#5272)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
  • Loading branch information
mzient committed Jan 9, 2024
1 parent da045a6 commit 5176fab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions dali/operators/random/rng_checkpointing_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,16 +77,18 @@ class RngCheckpointUtils<GPUBackend, curand_states> {
const auto &states_gpu = cpt.CheckpointState<curand_states>();
size_t n = states_gpu.length();
std::vector<curandState> states(n);
cudaMemcpy(states.data(), states_gpu.states(), n * sizeof(curandState),
cudaMemcpyDeviceToHost);
CUDA_CALL(cudaMemcpy(states.data(), states_gpu.states(), n * sizeof(curandState),
cudaMemcpyDeviceToHost));
return SnapshotSerializer().Serialize(states);
}

static void DeserializeCheckpoint(OpCheckpoint &cpt, const std::string &data) {
auto deserialized = SnapshotSerializer().Deserialize<std::vector<curandState>>(data);
curand_states states(deserialized.size());
cudaMemcpy(states.states(), deserialized.data(), sizeof(curandState) * deserialized.size(),
cudaMemcpyHostToDevice);
CUDA_CALL(cudaMemcpy(states.states(),
deserialized.data(),
sizeof(curandState) * deserialized.size(),
cudaMemcpyHostToDevice));
cpt.MutableCheckpointState() = states;
}
};
Expand Down
9 changes: 5 additions & 4 deletions dali/operators/util/randomizer.cuh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,13 +53,14 @@ struct curand_states {

DALI_HOST inline curand_states copy(AccessOrder order) const {
curand_states states(len_);
cudaMemcpyAsync(states.states_, states_, sizeof(curandState) * len_,
cudaMemcpyDeviceToDevice, order.stream());
CUDA_CALL(cudaMemcpyAsync(states.states_, states_, sizeof(curandState) * len_,
cudaMemcpyDeviceToDevice, order.stream()));
return states;
}

DALI_HOST inline void set(const curand_states &other) {
cudaMemcpy(states_, other.states_, sizeof(curandState) * len_, cudaMemcpyDeviceToDevice);
CUDA_CALL(cudaMemcpy(states_, other.states_, sizeof(curandState) * len_,
cudaMemcpyDeviceToDevice));
}

private:
Expand Down
6 changes: 3 additions & 3 deletions dali/pipeline/operator/checkpointing/checkpoint.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@ class OpGraph;
/**
* @brief Pipeline-wide state, passed from python side
*/
struct DLL_PUBLIC ExternalContextCheckpoint {
struct ExternalContextCheckpoint {
int epoch_idx; // Epoch index, as counted by python Pipeline
int iter; // Iteration, as counted by python Pipeline
};
Expand Down Expand Up @@ -78,7 +78,7 @@ class DLL_PUBLIC Checkpoint {
*/
DLL_PUBLIC void DeserializeFromProtobuf(const OpGraph &graph, const std::string &serialized_data);

ExternalContextCheckpoint external_ctx_cpt_;
ExternalContextCheckpoint external_ctx_cpt_{};

private:
std::vector<OpCheckpoint> cpts_;
Expand Down

0 comments on commit 5176fab

Please sign in to comment.