Skip to content

FEAT-#145: oneDNN: Support for existing onednn_graph dialect ops. #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dnnl/JsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ inline mlir::Attribute JsonParser::readAttr() {
} else if (_str == "s64[]") {
_ia64.clear();
readNumArray(_ia64);
attr = _builder.getI64ArrayAttr(_ia64);
attr = _builder.getDenseI64ArrayAttr(_ia64);
} else if (_str == "f32[]") {
_fa32.clear();
readNumArray(_fa32);
attr = _builder.getF32ArrayAttr(_fa32);
attr = _builder.getDenseF32ArrayAttr(_fa32);
} else if (_str == "string") {
_reader.read_string(&_str);
attr = _builder.getStringAttr(_str);
Expand Down
14 changes: 14 additions & 0 deletions src/dnnl/JsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
#include <stdfloat>
#else
namespace std {
#if defined(__SIZEOF_FLOAT__) && __SIZEOF_FLOAT__ == 4
using float32_t = float;
#elif defined(__SIZEOF_DOUBLE__) && __SIZEOF_DOUBLE__ == 4
using float32_t = double;
#else
static_assert(false, "Unable to determine 32-bit floating point type");
#endif
} // namespace std
#endif

Expand Down Expand Up @@ -145,8 +151,16 @@ class JsonParser {
}
std::unordered_map<std::string, OpBuilderFn> _opBuilders{
GC_OP("Add", mlir::onednn_graph::AddOp),
GC_OP("Divide", mlir::onednn_graph::DivOp),
GC_OP("MatMul", mlir::onednn_graph::MatMulOp),
GC_OP("Multiply", mlir::onednn_graph::MulOp),
GC_OP("Pow", mlir::onednn_graph::PowOp),
GC_OP("ReduceMean", mlir::onednn_graph::ReduceMeanOp),
GC_OP("ReduceSum", mlir::onednn_graph::ReduceSumOp),
GC_OP("ReLU", mlir::onednn_graph::ReLUOp),
GC_OP("Sigmoid", mlir::onednn_graph::SigmoidOp),
GC_OP("Subtract", mlir::onednn_graph::SubOp),
GC_OP("Typecast", mlir::onednn_graph::TypeCastOp),
};
#undef GC_OP

Expand Down
2 changes: 1 addition & 1 deletion test/dnnl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ foreach (TEST_SOURCE ${TEST_SOURCES})
target_include_directories(${TEST_NAME} PRIVATE ${GC_LIB_INCLUDES})
if (${TEST_NAME} MATCHES "^TestApi.*")
# The API tests are linked with the shared lib
target_link_libraries(${TEST_NAME} PRIVATE graph_compiler)
target_link_libraries(${TEST_NAME} PRIVATE LLVMSupport graph_compiler)
else ()
# The other tests are linked with the static lib and have non-public includes
target_link_libraries(${TEST_NAME} PRIVATE graph_compiler_static)
Expand Down
16 changes: 15 additions & 1 deletion test/dnnl/DnnlTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@
#include <sstream>
#include <string>

static std::string read_str_resource(const std::string &name) {
#if __cplusplus > 202002L
#include <stdfloat>
#else
namespace std {
#if defined(__SIZEOF_FLOAT__) && __SIZEOF_FLOAT__ == 4
using float32_t = float;
#elif defined(__SIZEOF_DOUBLE__) && __SIZEOF_DOUBLE__ == 4
using float32_t = double;
#else
static_assert(false, "No 32-bit floating point type available");
#endif
} // namespace std
#endif

static std::string readStrResource(const std::string &name) {
std::filesystem::path res_dir{"resources"};
auto path = std::filesystem::absolute(res_dir / name);
std::ifstream file(path);
Expand Down
2 changes: 1 addition & 1 deletion test/dnnl/TestApiBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "graph/backend/elyzor/include/dnnl_graph_compiler.h"

TEST(TestApiBasic, basicWorkflow) {
auto json = read_str_resource("add.json");
auto json = readStrResource("add.json");

const struct dnnl_graph_compiler_context ctx = {.num_threads = 4};
const struct dnnl_graph_compiler *gc;
Expand Down
Loading