Skip to content

Commit

Permalink
Enable verbose mode for ov data types
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnick committed Jan 30, 2025
1 parent 848a7c3 commit 33ad419
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/plugins/intel_cpu/src/dnnl_extension_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ uint8_t DnnlExtensionUtils::sizeOfDataType(dnnl::memory::data_type dataType) {
}
}

dnnl::memory::data_type DnnlExtensionUtils::ElementTypeToDataType(const ov::element::Type& elementType) {
std::optional<dnnl::memory::data_type> DnnlExtensionUtils::ElementTypeToDataType(
const ov::element::Type& elementType,
DnnlExtensionUtils::nothrow_tag) noexcept {
switch (elementType) {
case ov::element::f32:
return memory::data_type::f32;
Expand Down Expand Up @@ -81,11 +83,18 @@ dnnl::memory::data_type DnnlExtensionUtils::ElementTypeToDataType(const ov::elem
case ov::element::undefined:
return memory::data_type::undef;
default: {
OPENVINO_THROW("CPU plugin does not support ", elementType.to_string(), " for use with oneDNN.");
return {};
}
}
}

dnnl::memory::data_type DnnlExtensionUtils::ElementTypeToDataType(const ov::element::Type& elementType,
DnnlExtensionUtils::throw_tag) {
auto&& result = ElementTypeToDataType(elementType, nothrow_tag{});
OPENVINO_ASSERT(result, "CPU plugin does not support ", elementType.to_string(), " for use with oneDNN.");
return result.value();
}

ov::element::Type DnnlExtensionUtils::DataTypeToElementType(const dnnl::memory::data_type& dataType) {
switch (dataType) {
case memory::data_type::f32:
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/intel_cpu/src/dnnl_extension_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#pragma once

#include <optional>
#include <string>

#include "common/c_types_map.hpp"
Expand All @@ -25,9 +26,18 @@ class Shape;
class IMemory;

class DnnlExtensionUtils {
public:
struct throw_tag {};
struct nothrow_tag {};

public:
static uint8_t sizeOfDataType(dnnl::memory::data_type dataType);
static dnnl::memory::data_type ElementTypeToDataType(const ov::element::Type& elementType);
static dnnl::memory::data_type ElementTypeToDataType(const ov::element::Type& elementType,
throw_tag tag = throw_tag{});

static std::optional<dnnl::memory::data_type> ElementTypeToDataType(const ov::element::Type& elementType,
nothrow_tag) noexcept;

static ov::element::Type DataTypeToElementType(const dnnl::memory::data_type& dataType);
static Dim convertToDim(const dnnl::memory::dim& dim);
static dnnl::memory::dim convertToDnnlDim(const Dim& dim);
Expand Down
45 changes: 36 additions & 9 deletions src/plugins/intel_cpu/src/utils/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Verbose::printInfo() {
written_total += size;
};

auto formatMemDesc = [&](const dnnl_memory_desc_t& desc, std::string& prefix) {
auto formatDnnlMemDesc = [&](const dnnl_memory_desc_t& desc, std::string& prefix) {
prefix = colorize(BLUE, prefix);
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, " ");
shift(written);
Expand All @@ -121,20 +121,47 @@ void Verbose::printInfo() {
shift(written);
};

auto formatDefaultMemDesc = [&](const MemoryDescCPtr& desc, std::string& prefix) {
prefix = colorize(BLUE, prefix);
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, " ");
shift(written);
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, "%s", prefix.c_str());
shift(written);
const auto& prc = desc->getPrecision().to_string();
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, "%s", prc.c_str());
shift(written);
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, ":");
shift(written);
// mimic dnnl format
const auto& dims = desc->getShape().getDims();
if (!dims.empty()) {
std::string dims_str = dim2str(dims.front());
std::for_each(++(dims.begin()), dims.end(), [&dims_str](size_t dim) {
dims_str.append("x" + std::to_string(dim));
});
written = snprintf(portsInfo + written_total, CPU_VERBOSE_DAT_LEN - written_total, "%s", dims_str.c_str());
shift(written);
}
};

for (size_t i = 0; i < node->getParentEdges().size(); i++) {
std::string prefix("src:" + std::to_string(i) + ':');
formatMemDesc(MemoryDescUtils::convertToDnnlMemoryDesc(node->getParentEdgeAt(i)->getMemory().getDesc().clone())
->getDnnlDesc()
.get(),
prefix);
const auto& desc = node->getParentEdgeAt(i)->getMemory().getDescPtr();
if (DnnlExtensionUtils::ElementTypeToDataType(desc->getPrecision(), DnnlExtensionUtils::nothrow_tag{})) {
formatDnnlMemDesc(MemoryDescUtils::convertToDnnlMemoryDesc(desc)->getDnnlDesc().get(), prefix);
} else {
formatDefaultMemDesc(desc, prefix);
}
}

for (size_t i = 0; i < node->getChildEdges().size(); i++) {
std::string prefix("dst:" + std::to_string(i) + ':');
formatMemDesc(MemoryDescUtils::convertToDnnlMemoryDesc(node->getChildEdgeAt(i)->getMemory().getDesc().clone())
->getDnnlDesc()
.get(),
prefix);
const auto& desc = node->getChildEdgeAt(i)->getMemory().getDescPtr();
if (DnnlExtensionUtils::ElementTypeToDataType(desc->getPrecision(), DnnlExtensionUtils::nothrow_tag{})) {
formatDnnlMemDesc(MemoryDescUtils::convertToDnnlMemoryDesc(desc)->getDnnlDesc().get(), prefix);
} else {
formatDefaultMemDesc(desc, prefix);
}
}

std::string post_ops;
Expand Down

0 comments on commit 33ad419

Please sign in to comment.