Commit e2e814e3 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

Fix build for MacOS (#1112)

* remove reference to ngraph core code from codegen. add stand-alone implementations of needed funcions

* fixed potential pointer leak

* clean up file_util

* more file util cleanup, removing unused functions

* interpreter works on mac

* CPU and INTERPRETER build and pass unmit tests on macos

* move get_directory to file_util

* cleanup
parent d18a9faf
...@@ -52,9 +52,11 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") ...@@ -52,9 +52,11 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(MKLPACKAGE "mklml_mac_${MKLVERSION}.tgz") set(MKLPACKAGE "mklml_mac_${MKLVERSION}.tgz")
set(MKL_SHA1_HASH d76083fd5a79767a96572ad0e23e7f4c892818f2) set(MKL_SHA1_HASH d76083fd5a79767a96572ad0e23e7f4c892818f2)
set(MKL_LIBS libmklml.dylib libiomp5.dylib)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(MKLPACKAGE "mklml_win_${MKLVERSION}.tgz") set(MKLPACKAGE "mklml_win_${MKLVERSION}.tgz")
set(MKL_SHA1_HASH d607ca92d7bfc101f0828c0b005098b75531669b) set(MKL_SHA1_HASH d607ca92d7bfc101f0828c0b005098b75531669b)
set(MKL_LIBS mklml.dll libiomp5md.dll)
endif() endif()
set(MKLURL ${MKLURLROOT}${MKLPACKAGE}) set(MKLURL ${MKLURLROOT}${MKLPACKAGE})
......
...@@ -204,12 +204,6 @@ endif() ...@@ -204,12 +204,6 @@ endif()
target_include_directories(ngraph PUBLIC "${NGRAPH_INCLUDE_PATH}") target_include_directories(ngraph PUBLIC "${NGRAPH_INCLUDE_PATH}")
target_link_libraries(ngraph PUBLIC dl pthread) target_link_libraries(ngraph PUBLIC dl pthread)
if (APPLE)
set_property(TARGET ngraph PROPERTY PREFIX "lib")
set_property(TARGET ngraph PROPERTY OUTPUT_NAME "ngraph.so")
set_property(TARGET ngraph PROPERTY SUFFIX "")
endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Installation logic... # Installation logic...
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
......
...@@ -75,9 +75,8 @@ add_custom_target(header_resource ...@@ -75,9 +75,8 @@ add_custom_target(header_resource
if (NGRAPH_CPU_ENABLE OR NGRAPH_GPU_ENABLE) if (NGRAPH_CPU_ENABLE OR NGRAPH_GPU_ENABLE)
add_library(codegen SHARED ${SRC}) add_library(codegen SHARED ${SRC})
set_target_properties(codegen PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION}) set_target_properties(codegen PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
add_dependencies(codegen header_resource) add_dependencies(codegen header_resource libmkldnn libeigen)
target_include_directories(codegen SYSTEM PUBLIC ${CMAKE_BINARY_DIR}) target_include_directories(codegen SYSTEM PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(codegen PRIVATE libllvm) target_link_libraries(codegen PRIVATE libllvm ngraph)
target_link_libraries(codegen PUBLIC libmkldnn libeigen pthread dl)
install(TARGETS codegen DESTINATION ${NGRAPH_INSTALL_LIB}) install(TARGETS codegen DESTINATION ${NGRAPH_INSTALL_LIB})
endif() endif()
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "header_resource.hpp" #include "header_resource.hpp"
#include "ngraph/codegen/compiler.hpp" #include "ngraph/codegen/compiler.hpp"
#include "ngraph/file_util.hpp" #include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
#if defined(__clang__) #if defined(__clang__)
...@@ -273,6 +272,7 @@ void codegen::StaticCompiler::add_header_search_path(const string& p) ...@@ -273,6 +272,7 @@ void codegen::StaticCompiler::add_header_search_path(const string& p)
} }
} }
} }
std::unique_ptr<codegen::Module> std::unique_ptr<codegen::Module>
codegen::StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& m_compiler_action, codegen::StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& m_compiler_action,
const string& source) const string& source)
......
This diff is collapsed.
...@@ -22,35 +22,73 @@ ...@@ -22,35 +22,73 @@
namespace ngraph namespace ngraph
{ {
class file_util; namespace file_util
} {
// @brief Returns the name with extension for a given path
// @param path The path to the output file
std::string get_file_name(const std::string& path);
class ngraph::file_util // @brief Returns the file extension
{ // @param path The path to the output file
public: std::string get_file_ext(const std::string& path);
static std::string get_file_name(const std::string&);
static std::string get_file_ext(const std::string&); // @brief Returns the directory portion of the given path
static std::string path_join(const std::string& s1, const std::string& s2); // @param path The path to the output file
static size_t get_file_size(const std::string& filename); std::string get_directory(const std::string& path);
static void remove_directory(const std::string& dir);
static bool make_directory(const std::string& dir); // @brief Serialize a Function to as a json file
static std::string make_temp_directory(const std::string& path = ""); // @param s1 Left side of path
static std::string get_temp_directory(); // @param s2 Right side of path
static void remove_file(const std::string& file); std::string path_join(const std::string& s1, const std::string& s2);
static std::vector<char> read_file_contents(const std::string& path);
static std::string read_file_to_string(const std::string& path); // @brief Returns the size in bytes of filename
static void iterate_files(const std::string& path, // @param filename The name of the file
std::function<void(const std::string& file, bool is_dir)> func, size_t get_file_size(const std::string& filename);
bool recurse = false);
static std::string tmp_filename(const std::string& extension = ""); // @brief Removes all files and directories starting at dir
static void touch(const std::string& filename); // @param dir The path of the directory to remove
static bool exists(const std::string& filename); void remove_directory(const std::string& dir);
static int try_get_lock(const std::string& filename);
static void release_lock(int fd, const std::string& filename); // @brief Create a directory
static time_t get_timestamp(const std::string& filename); // @param dir Path of the directory to create
// @param func The Function to serialize
private: // @return true if the directory was created, false otherwise
static void iterate_files_worker(const std::string& path, bool make_directory(const std::string& dir);
std::function<void(const std::string& file, bool is_dir)> func,
bool recurse = false); // @brief Gets the path of the system temporary directory
}; // @return the path to the system temporary directory
std::string get_temp_directory_path();
// @brief Removes a file from the filesystem
// @param file The path to the file to be removed
void remove_file(const std::string& file);
// @brief Reads the contents of a file
// @param path The path of the file to read
// @return vector<char> of the file's contents
std::vector<char> read_file_contents(const std::string& path);
// @brief Reads the contents of a file
// @param path The path of the file to read
// @return string of the file's contents
std::string read_file_to_string(const std::string& path);
// @brief Iterate through files and optionally directories. Symbolic links are skipped.
// @param path The path to iterate over
// @param func A callback function called with each file or directory encountered
// @param recurse Optional parameter to enable recursing through path
void iterate_files(const std::string& path,
std::function<void(const std::string& file, bool is_dir)> func,
bool recurse = false);
// @brief Create a temporary file
// @param extension Optional extension for the temporary file
// @return Name of the temporary file
std::string tmp_filename(const std::string& extension = "");
// @brief Test for the existence of a path or file
// @param path The path to test
// @param true if the path exists, false otherwise
bool exists(const std::string& path);
}
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <sstream> #include <sstream>
#include "ngraph/file_util.hpp"
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp" #include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
...@@ -42,6 +43,26 @@ runtime::Backend::~Backend() ...@@ -42,6 +43,26 @@ runtime::Backend::~Backend()
{ {
} }
// This doodad finds the full path of the containing shared library
static string find_my_file()
{
Dl_info dl_info;
dladdr(reinterpret_cast<void*>(find_my_file), &dl_info);
return dl_info.dli_fname;
}
// This will be uncommented when we add support for listing all known backends
// static bool is_backend(const string& path)
// {
// bool rc = false;
// string name = file_util::get_file_name(path);
// if (name.find("_backend.") != string::npos)
// {
// NGRAPH_INFO << name;
// }
// return rc;
// }
void* runtime::Backend::open_shared_library(string type) void* runtime::Backend::open_shared_library(string type)
{ {
string ext = SHARED_LIB_EXT; string ext = SHARED_LIB_EXT;
...@@ -55,8 +76,11 @@ void* runtime::Backend::open_shared_library(string type) ...@@ -55,8 +76,11 @@ void* runtime::Backend::open_shared_library(string type)
{ {
type = type.substr(0, colon); type = type.substr(0, colon);
} }
string name = "lib" + to_lower(type) + "_backend" + ext; string lib_name = "lib" + to_lower(type) + "_backend" + ext;
handle = dlopen(name.c_str(), RTLD_NOW | RTLD_GLOBAL); string my_directory = file_util::get_directory(find_my_file());
string full_path = file_util::path_join(my_directory, lib_name);
NGRAPH_INFO << full_path;
handle = dlopen(full_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (handle) if (handle)
{ {
function<void()> create_backend = function<void()> create_backend =
...@@ -68,14 +92,16 @@ void* runtime::Backend::open_shared_library(string type) ...@@ -68,14 +92,16 @@ void* runtime::Backend::open_shared_library(string type)
else else
{ {
dlclose(handle); dlclose(handle);
throw runtime_error("Failed to find create_backend function in library '" + name + "'"); throw runtime_error("Failed to find create_backend function in library '" + lib_name +
"'");
} }
s_open_backends.insert({name, handle}); s_open_backends.insert({lib_name, handle});
} }
else else
{ {
string err = dlerror(); string err = dlerror();
throw runtime_error("Library open for Backend '" + name + "' failed with error:\n" + err); throw runtime_error("Library open for Backend '" + lib_name + "' failed with error:\n" +
err);
} }
return handle; return handle;
} }
......
...@@ -52,7 +52,7 @@ shared_ptr<Node> ...@@ -52,7 +52,7 @@ shared_ptr<Node>
} }
NodeVector new_outputs; NodeVector new_outputs;
for (auto o : m_outputs) for (auto o : m_output_nodes)
{ {
new_outputs.push_back(nm.get(o)); new_outputs.push_back(nm.get(o));
} }
...@@ -65,7 +65,7 @@ ngraph::runtime::cpu::op::LoopKernel::LoopKernel(const NodeVector& node_list, ...@@ -65,7 +65,7 @@ ngraph::runtime::cpu::op::LoopKernel::LoopKernel(const NodeVector& node_list,
const NodeVector& args) const NodeVector& args)
: RequiresTensorViewArgs("LoopKernel", {args}) : RequiresTensorViewArgs("LoopKernel", {args})
, m_node_list(node_list) , m_node_list(node_list)
, m_outputs(outputs) , m_output_nodes(outputs)
{ {
auto ref = node_list.at(0); auto ref = node_list.at(0);
for (auto n : node_list) for (auto n : node_list)
......
...@@ -39,10 +39,10 @@ namespace ngraph ...@@ -39,10 +39,10 @@ namespace ngraph
copy_with_new_args(const NodeVector& new_args) const override; copy_with_new_args(const NodeVector& new_args) const override;
const NodeVector& get_node_list() const { return m_node_list; } const NodeVector& get_node_list() const { return m_node_list; }
const NodeVector& get_kernel_outputs() const { return m_outputs; } const NodeVector& get_kernel_outputs() const { return m_output_nodes; }
private: private:
NodeVector m_node_list; NodeVector m_node_list;
NodeVector m_outputs; NodeVector m_output_nodes;
}; };
} }
} }
......
...@@ -90,8 +90,8 @@ TEST(file_util, path_join) ...@@ -90,8 +90,8 @@ TEST(file_util, path_join)
} }
} }
TEST(file_util, get_temp_directory) TEST(file_util, get_temp_directory_path)
{ {
string tmp = file_util::get_temp_directory(); string tmp = file_util::get_temp_directory_path();
EXPECT_NE(0, tmp.size()); EXPECT_NE(0, tmp.size());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment