Skip to content

Commit

Permalink
Don't return pointers to a local variable in dali_operator_test. (#5585)
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Zientkiewicz <[email protected]>
  • Loading branch information
mzient authored Jul 29, 2024
1 parent de81944 commit 2d6f097
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions dali/test/dali_operator_test.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2018-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 @@ -123,27 +123,20 @@ inline void AddOperatorToPipeline(Pipeline &pipeline, const OpSpec &op_spec) {
pipeline.AddOperator(op_spec);
}


inline Workspace CreateWorkspace() {
Workspace ws;
return ws;
}


inline void RunPipeline(Pipeline &pipeline) {
pipeline.Run();
}

inline std::vector<TensorListWrapper>
GetOutputsFromPipeline(Pipeline &pipeline, const std::string &output_backend) {
GetOutputsFromPipeline(Workspace &ws, Pipeline &pipeline, const std::string &output_backend) {
std::vector<TensorListWrapper> ret;
auto workspace = CreateWorkspace();
pipeline.Outputs(&workspace);
for (int output_idx = 0; output_idx < workspace.NumOutput(); output_idx++) {
if (workspace.OutputIsType<CPUBackend>(output_idx)) {
ret.emplace_back(&workspace.Output<CPUBackend>(output_idx));
ws = {};
pipeline.Outputs(&ws);
for (int output_idx = 0; output_idx < ws.NumOutput(); output_idx++) {
if (ws.OutputIsType<CPUBackend>(output_idx)) {
ret.emplace_back(&ws.Output<CPUBackend>(output_idx));
} else {
ret.emplace_back(&workspace.Output<GPUBackend>(output_idx));
ret.emplace_back(&ws.Output<GPUBackend>(output_idx));
}
}
return ret;
Expand Down Expand Up @@ -284,10 +277,11 @@ class DaliOperatorTest : public ::testing::Test, public ::testing::WithParamInte
BuildPipeline(pipeline, op_spec);
SetInputInPipeline(pipeline, input);
RunPipeline(pipeline);
return GetOutputsFromPipeline(pipeline, output_backend);
return GetOutputsFromPipeline(ws_, pipeline, output_backend);
}

size_t num_threads_ = 1;
Workspace ws_;
};

} // namespace testing
Expand Down

0 comments on commit 2d6f097

Please sign in to comment.