Commit 6fd76845 authored by Artur Wojcik's avatar Artur Wojcik
Browse files

merge uif2-rbuild to uif2-initial

parent fed23ec7
...@@ -49,7 +49,6 @@ endif() ...@@ -49,7 +49,6 @@ endif()
list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/llvm $ENV{ROCM_PATH} $ENV{HIP_PATH}) list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/llvm $ENV{ROCM_PATH} $ENV{HIP_PATH})
project(migraphx LANGUAGES C CXX) project(migraphx LANGUAGES C CXX)
include(CTest)
find_package(ROCM REQUIRED) find_package(ROCM REQUIRED)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
...@@ -88,6 +87,8 @@ set(CMAKE_REQUIRED_INCLUDES) ...@@ -88,6 +87,8 @@ set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES)
include(ROCMSetupVersion) include(ROCMSetupVersion)
include(ROCMCreatePackage)
include(ROCMTest)
option(BUILD_DEV "Build for development purpose only" OFF) option(BUILD_DEV "Build for development purpose only" OFF)
...@@ -290,9 +291,6 @@ rocm_enable_cppcheck( ...@@ -290,9 +291,6 @@ rocm_enable_cppcheck(
MIGRAPHX_USE_CLANG_TIDY MIGRAPHX_USE_CLANG_TIDY
) )
include(ROCMCreatePackage)
include(ROCMTest)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
......
...@@ -206,10 +206,14 @@ function(add_embed_library EMBED_NAME) ...@@ -206,10 +206,14 @@ function(add_embed_library EMBED_NAME)
target_include_directories(${INTERNAL_EMBED_LIB} PRIVATE "${EMBED_DIR}/include") target_include_directories(${INTERNAL_EMBED_LIB} PRIVATE "${EMBED_DIR}/include")
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations) target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations)
set_target_properties(${INTERNAL_EMBED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE On) set_target_properties(${INTERNAL_EMBED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE On)
add_library(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}> ${OUTPUT_FILES}) add_library(${EMBED_NAME} INTERFACE)
if(EMBED_USE STREQUAL "LD")
target_sources(${EMBED_NAME} INTERFACE ${OUTPUT_FILES})
endif()
if(EMBED_USE STREQUAL "RC") if(EMBED_USE STREQUAL "RC")
target_link_libraries(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>) target_link_libraries(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>)
endif() endif()
target_sources(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>)
target_include_directories(${EMBED_NAME} INTERFACE "${EMBED_DIR}/include") target_include_directories(${EMBED_NAME} INTERFACE "${EMBED_DIR}/include")
endfunction() endfunction()
...@@ -29,12 +29,7 @@ include(ROCMPackageConfigHelpers) ...@@ -29,12 +29,7 @@ include(ROCMPackageConfigHelpers)
include(RegisterOp) include(RegisterOp)
include(CheckCXXLinkerFlag) include(CheckCXXLinkerFlag)
if(WIN32) add_library(migraphx
# Due to compilation crashing, we need to use type-erased matchers on Windows.
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:MIGRAPHX_USE_TYPE_ERASED_MATCHERS=1>)
endif()
add_library(migraphx
adjust_allocation.cpp adjust_allocation.cpp
analyze_streams.cpp analyze_streams.cpp
apply_alpha_beta.cpp apply_alpha_beta.cpp
...@@ -108,6 +103,12 @@ add_library(migraphx ...@@ -108,6 +103,12 @@ add_library(migraphx
value.cpp value.cpp
verify_args.cpp verify_args.cpp
) )
if(WIN32)
# Due to compilation crashing, we need to use type-erased matchers on Windows.
target_compile_definitions(migraphx PUBLIC MIGRAPHX_USE_TYPE_ERASED_MATCHERS=1)
endif()
configure_file(version.h.in include/migraphx/version.h) configure_file(version.h.in include/migraphx/version.h)
rocm_set_soversion(migraphx ${MIGRAPHX_SO_VERSION}) rocm_set_soversion(migraphx ${MIGRAPHX_SO_VERSION})
function(register_migraphx_ops) function(register_migraphx_ops)
...@@ -327,5 +328,4 @@ rocm_export_targets( ...@@ -327,5 +328,4 @@ rocm_export_targets(
Threads Threads
${PACKAGE_DEPENDS} ${PACKAGE_DEPENDS}
) )
...@@ -88,10 +88,17 @@ int exec(const std::string& cmd, std::function<void(process::writer)> std_in) ...@@ -88,10 +88,17 @@ int exec(const std::string& cmd, std::function<void(process::writer)> std_in)
constexpr std::size_t MIGRAPHX_PROCESS_BUFSIZE = 4096; constexpr std::size_t MIGRAPHX_PROCESS_BUFSIZE = 4096;
enum class direction
{
input,
output
};
template <direction dir, bool inherit_handle = true>
class pipe class pipe
{ {
public: public:
explicit pipe(bool inherit_handle = true) explicit pipe()
{ {
SECURITY_ATTRIBUTES attrs; SECURITY_ATTRIBUTES attrs;
attrs.nLength = sizeof(SECURITY_ATTRIBUTES); attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
...@@ -101,8 +108,21 @@ class pipe ...@@ -101,8 +108,21 @@ class pipe
if(CreatePipe(&m_read, &m_write, &attrs, 0) == FALSE) if(CreatePipe(&m_read, &m_write, &attrs, 0) == FALSE)
throw GetLastError(); throw GetLastError();
if(SetHandleInformation(&m_read, HANDLE_FLAG_INHERIT, 0) == FALSE) if(inherit_handle)
throw GetLastError(); {
if(dir == direction::output)
{
// Do not inherit the read handle for the output pipe
if(SetHandleInformation(m_read, HANDLE_FLAG_INHERIT, 0) == 0)
throw GetLastError();
}
else
{
// Do not inherit the write handle for the input pipe
if(SetHandleInformation(m_write, HANDLE_FLAG_INHERIT, 0) == 0)
throw GetLastError();
}
}
} }
pipe(const pipe&) = delete; pipe(const pipe&) = delete;
...@@ -112,10 +132,31 @@ class pipe ...@@ -112,10 +132,31 @@ class pipe
~pipe() ~pipe()
{ {
CloseHandle(m_read); if(m_read != nullptr)
m_read = nullptr; CloseHandle(m_read);
CloseHandle(m_write);
m_write = nullptr; if(m_write != nullptr)
CloseHandle(m_write);
}
void close_read_handle()
{
if(m_read != nullptr)
{
if(CloseHandle(m_read) == 0)
MIGRAPHX_THROW("Error closing read handle: " + std::to_string(GetLastError()));
m_read = nullptr;
}
}
void close_write_handle()
{
if(m_write != nullptr)
{
if(CloseHandle(m_write) == 0)
MIGRAPHX_THROW("Error closing write handle: " + std::to_string(GetLastError()));
m_write = nullptr;
}
} }
std::optional<std::pair<bool, DWORD>> read(LPVOID buffer, DWORD length) const std::optional<std::pair<bool, DWORD>> read(LPVOID buffer, DWORD length) const
...@@ -158,13 +199,14 @@ int exec(const std::string& cmd, F f) ...@@ -158,13 +199,14 @@ int exec(const std::string& cmd, F f)
STARTUPINFO info; STARTUPINFO info;
PROCESS_INFORMATION process_info; PROCESS_INFORMATION process_info;
pipe in{}, out{}; pipe<direction::input> input{};
pipe<direction::output> output{};
ZeroMemory(&info, sizeof(STARTUPINFO)); ZeroMemory(&info, sizeof(STARTUPINFO));
info.cb = sizeof(STARTUPINFO); info.cb = sizeof(STARTUPINFO);
info.hStdError = out.get_write_handle(); info.hStdError = output.get_write_handle();
info.hStdOutput = out.get_write_handle(); info.hStdOutput = output.get_write_handle();
info.hStdInput = in.get_read_handle(); info.hStdInput = input.get_read_handle();
info.dwFlags |= STARTF_USESTDHANDLES; info.dwFlags |= STARTF_USESTDHANDLES;
ZeroMemory(&process_info, sizeof(process_info)); ZeroMemory(&process_info, sizeof(process_info));
...@@ -183,7 +225,7 @@ int exec(const std::string& cmd, F f) ...@@ -183,7 +225,7 @@ int exec(const std::string& cmd, F f)
return GetLastError(); return GetLastError();
} }
f(in, out); f(input, output);
WaitForSingleObject(process_info.hProcess, INFINITE); WaitForSingleObject(process_info.hProcess, INFINITE);
...@@ -193,6 +235,9 @@ int exec(const std::string& cmd, F f) ...@@ -193,6 +235,9 @@ int exec(const std::string& cmd, F f)
CloseHandle(process_info.hProcess); CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread); CloseHandle(process_info.hThread);
input.close_read_handle();
output.close_write_handle();
return static_cast<int>(status); return static_cast<int>(status);
} }
// cppcheck-suppress catchExceptionByValue // cppcheck-suppress catchExceptionByValue
...@@ -208,7 +253,7 @@ int exec(const std::string& cmd) ...@@ -208,7 +253,7 @@ int exec(const std::string& cmd)
HANDLE std_out{GetStdHandle(STD_OUTPUT_HANDLE)}; HANDLE std_out{GetStdHandle(STD_OUTPUT_HANDLE)};
return (std_out == nullptr or std_out == INVALID_HANDLE_VALUE) return (std_out == nullptr or std_out == INVALID_HANDLE_VALUE)
? GetLastError() ? GetLastError()
: exec(cmd, [&](const pipe&, const pipe& out) { : exec(cmd, [&](const pipe<direction::input>&, const pipe<direction::output>& out) {
for(;;) for(;;)
{ {
if(auto result = out.read(buffer, MIGRAPHX_PROCESS_BUFSIZE)) if(auto result = out.read(buffer, MIGRAPHX_PROCESS_BUFSIZE))
...@@ -226,7 +271,7 @@ int exec(const std::string& cmd) ...@@ -226,7 +271,7 @@ int exec(const std::string& cmd)
int exec(const std::string& cmd, std::function<void(process::writer)> std_in) int exec(const std::string& cmd, std::function<void(process::writer)> std_in)
{ {
return exec(cmd, [&](const pipe& in, const pipe&) { return exec(cmd, [&](const pipe<direction::input>& in, const pipe<direction::output>&) {
std_in([&](const char* buffer, std::size_t n) { in.write(buffer, n); }); std_in([&](const char* buffer, std::size_t n) { in.write(buffer, n); });
}); });
} }
......
...@@ -35,7 +35,8 @@ if(NOT WIN32) ...@@ -35,7 +35,8 @@ if(NOT WIN32)
endif() endif()
rocm_clang_tidy_check(migraphx_ref) rocm_clang_tidy_check(migraphx_ref)
target_link_libraries(migraphx_ref PUBLIC migraphx Threads::Threads) target_link_libraries(migraphx_ref PRIVATE Threads::Threads)
target_link_libraries(migraphx_ref PUBLIC migraphx)
target_include_directories(migraphx_ref SYSTEM PRIVATE ${BLAZE_INCLUDE}) target_include_directories(migraphx_ref SYSTEM PRIVATE ${BLAZE_INCLUDE})
target_compile_definitions(migraphx_ref PRIVATE -DBLAZE_USE_CPP_THREADS) target_compile_definitions(migraphx_ref PRIVATE -DBLAZE_USE_CPP_THREADS)
......
...@@ -30,9 +30,6 @@ function(add_api_test TEST_NAME TEST_SRC TEST_DIR) ...@@ -30,9 +30,6 @@ function(add_api_test TEST_NAME TEST_SRC TEST_DIR)
add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}> WORKING_DIRECTORY ${TEST_DIR}) add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}> WORKING_DIRECTORY ${TEST_DIR})
add_dependencies(tests ${NAME}) add_dependencies(tests ${NAME})
add_dependencies(check ${NAME}) add_dependencies(check ${NAME})
if(WIN32)
target_compile_definitions(${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
endfunction() endfunction()
# Workaround: C file dont work with clang-tidy right now, need a fix in rocm-cmake # Workaround: C file dont work with clang-tidy right now, need a fix in rocm-cmake
...@@ -44,9 +41,6 @@ function(add_c_api_test TEST_NAME TEST_SRC TEST_DIR) ...@@ -44,9 +41,6 @@ function(add_c_api_test TEST_NAME TEST_SRC TEST_DIR)
add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}> WORKING_DIRECTORY ${TEST_DIR}) add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}> WORKING_DIRECTORY ${TEST_DIR})
add_dependencies(tests ${NAME}) add_dependencies(tests ${NAME})
add_dependencies(check ${NAME}) add_dependencies(check ${NAME})
if(WIN32)
target_compile_definitions(${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
endfunction() endfunction()
add_api_test(array_base test_array_base.cpp ${TEST_ONNX_DIR}) add_api_test(array_base test_array_base.cpp ${TEST_ONNX_DIR})
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <atomic> #include <atomic>
#include <algorithm> #include <algorithm>
#include <array>
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
......
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