Fix linux build issue with debug dump of shapes and data. (#2202)

Add option to dump just shapes or shapes and data.
This commit is contained in:
Scott McKay 2019-10-20 20:35:48 -07:00 committed by GitHub
parent 07e9f500da
commit 5c86889beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 17 deletions

View file

@ -18,7 +18,7 @@ set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES})
if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS)
target_compile_definitions(onnxruntime_framework PRIVATE DEBUG_NODE_INPUTS_OUTPUTS)
target_compile_definitions(onnxruntime_framework PRIVATE DEBUG_NODE_INPUTS_OUTPUTS=${onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS})
endif()

View file

@ -557,15 +557,15 @@ static void DumpTensor(const Tensor& tensor, const TensorShape& shape) {
auto data = tensor.DataAsSpan<T>();
auto print_val = [](const T& value) {
if (std::is_floating_point_v<T>)
if (std::is_floating_point<T>::value)
std::cout << std::setprecision(8) << value;
else
std::cout << value;
};
for (int row = 0; row < num_rows; ++row) {
for (size_t row = 0; row < num_rows; ++row) {
print_val(data[row * row_size]);
for (int i = 1; i < row_size; ++i) {
for (size_t i = 1; i < row_size; ++i) {
std::cout << ", ";
print_val(data[row * row_size + i]);
}
@ -622,22 +622,24 @@ void DumpNodeOutputs(OpKernelContext& context, const Node& node, const SessionSt
if (type) {
if (type->IsTensorType()) {
const auto& tensor = *context.Output<Tensor>(i);
const auto data_type = tensor.DataType();
const auto& shape = tensor.Shape();
std::cout << " Shape: " << shape << "\n";
// check tensor is on CPU before dumping it
auto& tensor_location = tensor.Location();
auto* provider = execution_providers.Get(tensor_location);
if (!provider) {
provider = cpu_execution_provider;
}
if (DEBUG_NODE_INPUTS_OUTPUTS > 1) {
// check tensor is on CPU before dumping it
auto& tensor_location = tensor.Location();
auto* provider = execution_providers.Get(tensor_location);
if (!provider) {
provider = cpu_execution_provider;
}
if (provider == cpu_execution_provider || tensor_location.mem_type == OrtMemTypeCPUOutput) {
DispatchOnTensorType(data_type, DumpTensor, tensor, shape);
} else {
std::cout << " is not on CPU. Provider=" << provider->Type() << "\n";
if (provider == cpu_execution_provider || tensor_location.mem_type == OrtMemTypeCPUOutput) {
const auto data_type = tensor.DataType();
DispatchOnTensorType(data_type, DumpTensor, tensor, shape);
} else {
std::cout << " is not on CPU. Provider=" << provider->Type() << "\n";
}
}
} else {
std::cout << " is non-tensor type.\n";

View file

@ -78,8 +78,11 @@ common::Status ExecuteSubgraph(const SessionState& session_state, const FeedsFet
ExecutionMode execution_mode, const bool& terminate_flag, const logging::Logger& logger);
#if defined(DEBUG_NODE_INPUTS_OUTPUTS)
// to create a build with these enabled run the build script with
// --cmake_extra_defines onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=ON
// to create a build with these enabled run the build script with 1 to dump just shapes, or 2 to dump shapes and data
// e.g.
// --cmake_extra_defines onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=1
// To unset you'll need to either delete CMakeCache.txt or run with
// --cmake_extra_defines onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=0
void DumpNodeInputs(const OpKernelContext& context, const Node& node);
void DumpNodeOutputs(OpKernelContext& context, const Node& node, const SessionState& session_state);
#endif