Commit a3a162e9 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Add per-os shim for execution support

Splits support for using tbb (oneTBB now) between OS's when using
std::execution::par

It appears TBB support seems to wane in earlier versions of g++ in CentOS and
other OS's still require testing/containers to verify builds.

The MIGraphX shim should just operate as normal with copy_if and sort() calls
if TBB support isn't functional for the current OS/g++ version

Also moved the TBB dependency from install_preqs to Ubuntu Docker. Shouldn't breka
other dockers if support isn't added
parent 750c42d6
...@@ -50,11 +50,16 @@ endif() ...@@ -50,11 +50,16 @@ endif()
if(NOT WIN32) if(NOT WIN32)
file(READ "/etc/os-release" ETC_ISSUE) file(READ "/etc/os-release" ETC_ISSUE)
string(REGEX MATCH "Debian|Ubuntu|CentOS|RHEL|SLES" DIST ${ETC_ISSUE}) string(REGEX MATCH "Debian|Ubuntu|CentOS|RHEL|SLES" DIST ${ETC_ISSUE})
set(USE_TBB Off)
if (DIST STREQUAL "Debian") if (DIST STREQUAL "Debian")
message(STATUS "Debian OS detected!") message(STATUS "Debian OS detected!")
add_compile_definitions(DEBIAN_DISTRO)
set(USE_TBB On)
elseif(DIST STREQUAL "Ubuntu") elseif(DIST STREQUAL "Ubuntu")
message(STATUS "Ubuntu OS detected!") message(STATUS "Ubuntu OS detected!")
add_compile_definitions(DEBIAN_DISTRO)
set(USE_TBB On)
elseif(DIST STREQUAL "CentOS") elseif(DIST STREQUAL "CentOS")
message(STATUS "CENTOS detected!") message(STATUS "CENTOS detected!")
elseif(DIST STREQUAL "Red Hat") elseif(DIST STREQUAL "Red Hat")
......
...@@ -49,6 +49,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow- ...@@ -49,6 +49,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-
hipblas \ hipblas \
hipify-clang \ hipify-clang \
half \ half \
libtbb2 \
libtbb-dev \
libssl-dev \ libssl-dev \
zlib1g-dev && \ zlib1g-dev && \
apt-get clean && \ apt-get clean && \
......
...@@ -247,8 +247,11 @@ target_include_directories(migraphx SYSTEM PUBLIC $<BUILD_INTERFACE:${HALF_INCLU ...@@ -247,8 +247,11 @@ target_include_directories(migraphx SYSTEM PUBLIC $<BUILD_INTERFACE:${HALF_INCLU
find_package(Threads) find_package(Threads)
target_link_libraries(migraphx PUBLIC Threads::Threads) target_link_libraries(migraphx PUBLIC Threads::Threads)
find_package(TBB REQUIRED) if(USE_TBB)
target_link_libraries(migraphx PRIVATE TBB::tbb) find_package(TBB REQUIRED)
target_link_libraries(migraphx PRIVATE TBB::tbb)
message(STATUS "Using TBB for parallel execution")
endif()
find_package(nlohmann_json 3.8.0 REQUIRED) find_package(nlohmann_json 3.8.0 REQUIRED)
target_link_libraries(migraphx PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(migraphx PRIVATE nlohmann_json::nlohmann_json)
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_EXECUTION_HPP
#define MIGRAPHX_GUARD_EXECUTION_HPP
#ifdef DEBIAN_DISTRO
#include <execution>
#endif
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
template <class ForwardIt1, class ForwardIt2, class UnaryPredicate> // NOLINT
ForwardIt2 copy_if(ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, UnaryPredicate pred)
{
#ifdef DEBIAN_DISTRO
return std::copy_if(std::execution::par, first, last, d_first, pred);
#else
return std::copy_if(first, last, d_first, pred);
#endif
}
template <class RandomIt, class Compare>
constexpr void sort(RandomIt first, RandomIt last, Compare comp)
{
#ifdef DEBIAN_DISTRO
return std::sort(std::execution::par, first, last, comp);
#else
return std::sort(first, last, comp);
#endif
}
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <queue> #include <queue>
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <execution>
#include <migraphx/config.hpp> #include <migraphx/config.hpp>
#include <migraphx/ranges.hpp> #include <migraphx/ranges.hpp>
#include <migraphx/float_equal.hpp> #include <migraphx/float_equal.hpp>
...@@ -38,6 +37,7 @@ ...@@ -38,6 +37,7 @@
#include <migraphx/check_shapes.hpp> #include <migraphx/check_shapes.hpp>
#include <migraphx/output_iterator.hpp> #include <migraphx/output_iterator.hpp>
#include <migraphx/argument.hpp> #include <migraphx/argument.hpp>
#include <migraphx/execution.hpp>
namespace migraphx { namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS { inline namespace MIGRAPHX_INLINE_NS {
...@@ -253,10 +253,8 @@ struct nonmaxsuppression ...@@ -253,10 +253,8 @@ struct nonmaxsuppression
return std::make_pair(sc, box_idx - 1); return std::make_pair(sc, box_idx - 1);
}); });
} }
std::sort(std::execution::par, migraphx::sort(
boxes_heap.begin(), boxes_heap.begin(), boxes_heap.end(), std::greater<std::pair<double, int64_t>>{});
boxes_heap.end(),
std::greater<std::pair<double, int64_t>>{});
return boxes_heap; return boxes_heap;
} }
...@@ -302,8 +300,7 @@ struct nonmaxsuppression ...@@ -302,8 +300,7 @@ struct nonmaxsuppression
std::vector<std::pair<double, int64_t>> remainder_boxes(boxes_heap.size()); std::vector<std::pair<double, int64_t>> remainder_boxes(boxes_heap.size());
auto it = std::copy_if( auto it = migraphx::copy_if(
std::execution::par,
boxes_heap.begin() + 1, boxes_heap.begin() + 1,
boxes_heap.end(), boxes_heap.end(),
remainder_boxes.begin(), remainder_boxes.begin(),
......
...@@ -33,7 +33,7 @@ export LANG=C.UTF-8 ...@@ -33,7 +33,7 @@ export LANG=C.UTF-8
# Need pip3 and Python headers to build dependencies # Need pip3 and Python headers to build dependencies
apt update && apt install -y python3-pip python3-dev cmake rocm-cmake rocblas miopen-hip openmp-extras libtbb2 libtbb-dev apt update && apt install -y python3-pip python3-dev cmake rocm-cmake rocblas miopen-hip openmp-extras
# Needed for cmake to build various pip packages # Needed for cmake to build various pip packages
pip3 install setuptools wheel pip3 install setuptools wheel
......
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