Skip to content

Export oneDNN API graph compiler functions #68

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 3 commits into from
May 14, 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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(src)

add_library(graph_compiler SHARED ${GC_LIB_SOURCES})
target_include_directories(graph_compiler PUBLIC ${GC_LIB_INCLUDES})
set(GC_LIB_LINKED_LIBS
MLIRLinalgx
MLIRMicrokernel
MLIROnednnGraph
)
add_library(graph_compiler SHARED ${GC_LIB_SOURCES})
target_include_directories(graph_compiler PUBLIC ${GC_LIB_INCLUDES})
target_compile_options(graph_compiler PRIVATE -fvisibility=hidden)
target_link_options(graph_compiler PRIVATE -Wl,--gc-sections)
target_link_libraries(graph_compiler PRIVATE ${GC_LIB_LINKED_LIBS})

add_subdirectory(unittests)
Expand Down
32 changes: 19 additions & 13 deletions src/dnnl/dnnl_graph_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include <new>
#include <string_view>

#if defined _WIN32 || defined __CYGWIN__
#define GC_DLL_EXPORT __declspec(dllexport)
#else
#define GC_DLL_EXPORT __attribute__((visibility("default")))
#endif

// dnnl_graph_compiler.h interface implementation.
// TODO: Implement.

Expand All @@ -43,7 +49,8 @@ struct dnnl_graph_compiler {
compile(const std::string_view &graph_json) const;
};

const dnnl_graph_compiler_version *dnnl_graph_compiler_get_version(void) {
GC_DLL_EXPORT const dnnl_graph_compiler_version *
dnnl_graph_compiler_get_version(void) {
static const dnnl_graph_compiler_version ver = {
.api_version = {DNNL_GC_API_V_MAJOR, DNNL_GC_API_V_MINOR,
DNNL_GC_API_V_PATCH,
Expand All @@ -54,7 +61,7 @@ const dnnl_graph_compiler_version *dnnl_graph_compiler_get_version(void) {
return &ver;
}

dnnl_status_t
GC_DLL_EXPORT dnnl_status_t
dnnl_graph_compiler_create(const struct dnnl_graph_compiler_context *ctx,
const struct dnnl_graph_compiler **gc) {
try {
Expand All @@ -68,14 +75,14 @@ dnnl_graph_compiler_create(const struct dnnl_graph_compiler_context *ctx,
}
}

void dnnl_graph_compiler_destroy(const struct dnnl_graph_compiler *gc) {
GC_DLL_EXPORT void
dnnl_graph_compiler_destroy(const struct dnnl_graph_compiler *gc) {
delete gc;
}

dnnl_status_t
dnnl_graph_compiler_compile(const dnnl_graph_compiler *gc,
const char *graph_json,
const struct dnnl_graph_compiler_executable **exe) {
GC_DLL_EXPORT dnnl_status_t dnnl_graph_compiler_compile(
const dnnl_graph_compiler *gc, const char *graph_json,
const struct dnnl_graph_compiler_executable **exe) {
try {
auto ptr = gc->compile(std::string_view(graph_json));
*exe = ptr.release();
Expand All @@ -88,17 +95,16 @@ dnnl_graph_compiler_compile(const dnnl_graph_compiler *gc,
}
}

void dnnl_graph_compiler_destroy_executable(
GC_DLL_EXPORT void dnnl_graph_compiler_destroy_executable(
const struct dnnl_graph_compiler *gc,
const struct dnnl_graph_compiler_executable *exe) {
delete exe;
}

dnnl_status_t
dnnl_graph_compiler_execute(const struct dnnl_graph_compiler *gc,
const struct dnnl_graph_compiler_executable *exe,
dnnl_graph_compiler_tensor *inputs,
dnnl_graph_compiler_tensor *outputs) {
GC_DLL_EXPORT dnnl_status_t dnnl_graph_compiler_execute(
const struct dnnl_graph_compiler *gc,
const struct dnnl_graph_compiler_executable *exe,
dnnl_graph_compiler_tensor *inputs, dnnl_graph_compiler_tensor *outputs) {
try {
exe->execute(inputs, outputs);
return dnnl_success;
Expand Down