"src/targets/vscode:/vscode.git/clone" did not exist on "231b7edd6e793c59c64da729f14ef7971fc6f03c"
Commit 06fb0905 authored by Scott Thornton's avatar Scott Thornton
Browse files

Added MNIST test for cpu target

parents 0a59f103 cff16121
......@@ -100,4 +100,4 @@ CheckOptions:
# - key: readability-identifier-naming.MacroDefinitionCase
# value: UPPER_CASE
# - key: readability-identifier-naming.MacroDefinitionPrefix
# value: RTG_
# value: MIGRAPH_
cmake_minimum_required(VERSION 3.5)
project(rtglib)
project(migraphlib)
find_package(ROCM REQUIRED)
option( BUILD_SHARED_LIBS "Build as a shared library" ON )
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.4")
message(FATAL_ERROR "RTGLib requires at least gcc 5.4")
message(FATAL_ERROR "MIGraph requires at least gcc 5.4")
endif()
endif()
if(CMAKE_CXX_COMPILER MATCHES ".*hcc")
message(STATUS "Enable miopen backend")
set(RTG_ENABLE_MIOPEN On CACHE BOOL "")
set(MIGRAPH_ENABLE_MIOPEN On CACHE BOOL "")
else()
set(RTG_ENABLE_MIOPEN Off CACHE BOOL "")
set(MIGRAPH_ENABLE_MIOPEN Off CACHE BOOL "")
endif()
add_compile_options(-std=c++14)
......@@ -83,7 +85,7 @@ rocm_enable_clang_tidy(
HEADER_FILTER
".*hpp"
EXTRA_ARGS
-DRTG_USE_CLANG_TIDY
-DMIGRAPH_USE_CLANG_TIDY
ANALYZE_TEMPORARY_DTORS ON
)
......@@ -110,6 +112,8 @@ rocm_enable_cppcheck(
CPPCHECK=1
)
enable_testing()
add_subdirectory(src)
add_subdirectory(doc)
add_subdirectory(test)
......
def rocmtestnode(variant, name, body) {
def image = 'rtglib'
def image = 'migraphlib'
def cmake_build = { compiler, flags ->
def cmd = """
rm -rf build
......
# MIGraph
AMD's library for graph optimizations.
## Prerequisites
* [ROCm cmake modules](https://github.com/RadeonOpenCompute/rocm-cmake) **required**
* [MIOpen](https://github.com/ROCmSoftwarePlatform/MIOpen) for running on the GPU
* [HIP](https://github.com/ROCm-Developer-Tools/HIP) for running on the GPU
* [Protobuf](https://github.com/google/protobuf) for reading [onxx](https://github.com/onnx/onnx) files
## Installing the dependencies
The dependencies can be installed with the `install_deps.cmake`, script: `cmake -P install_deps.cmake`.
This will install by default to `/usr/local` but it can be installed in another location with `--prefix` argument:
```
cmake -P install_deps.cmake --prefix /some/local/dir
```
## Building MIGraph from source
## Configuring with cmake
First create a build directory:
```
mkdir build;
cd build;
```
Next configure cmake. The hcc compiler is required to build the MIOpen backend:
```
CXX=/opt/rocm/bin/hcc cmake ..
```
If the dependencies from `install_deps.cmake` was installed to another directory, the `CMAKE_PREFIX_PATH` needs to be set to what `--prefix` was set to from `install_deps.cmake`:
```
CXX=/opt/rocm/bin/hcc cmake -DCMAKE_PREFIX_PATH=/some/dir ..
```
#### Changing the cmake configuration
The configuration can be changed after running cmake by using `ccmake`:
` ccmake .. ` **OR** `cmake-gui`: ` cmake-gui ..`
## Building the library
The library can be built, from the `build` directory using the 'Release' configuration:
` cmake --build . --config Release ` **OR** ` make `
And can be installed by using the 'install' target:
` cmake --build . --config Release --target install ` **OR** ` make install `
This will install the library to the `CMAKE_INSTALL_PREFIX` path that was set.
## Running the tests
The tests can be run by using the 'check' target:
` cmake --build . --config Release --target check ` **OR** ` make check `
## Building the documentation
HTML and PDF documentation can be built using:
`cmake --build . --config Release --target doc` **OR** `make doc`
The generated documentation will be located in `doc/doxygen/`.
## Formatting the code
All the code is formatted using clang-format. To format a file, use:
```
clang-format-5.0 -style=file -i <path-to-source-file>
```
Also, githooks can be installed to format the code per-commit:
```
./.githooks/install
```
## Using docker
The easiest way to setup the development environment is to use docker. You can build the top-level docker file:
docker build -t migraph .
Then to enter the developement environment use `docker run`:
docker run --device='/dev/kfd' --device='/dev/dri' -v=`pwd`:/data -w /data --group-add video -it migraph
pfultz2/rocm-recipes
danmar/cppcheck@d9f9bdda7344e80585f71141be7797055d7987f3
# python/cpython@v3.6.6 -X autotools -H sha256:92aa914572c695c0aeb01b0a214813f414da4b51a371234df514a74761f2bb36
-f requirements.txt
......@@ -16,7 +16,7 @@ add_doxygen_doc(
CALL_GRAPH YES
CALLER_GRAPH YES
BUILTIN_STL_SUPPORT YES
PROJECT_NAME RTGLib
PROJECT_NAME MIGraph
SORT_MEMBERS_CTORS_1ST YES
SOURCE_BROWSER YES
GENERATE_TREEVIEW YES
......
......@@ -47,4 +47,14 @@ if(NOT CMakeGet_FOUND)
find_package(CMakeGet REQUIRED PATHS ${PREFIX})
endif()
# Set compiler to hcc if not set
if(NOT DEFINED ENV{CXX} AND NOT DEFINED CMAKE_CXX_COMPILER AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
find_program(HCC hcc PATHS /opt/rocm PATH_SUFFIXES bin)
if(HCC)
set(ENV{CXX} ${HCC})
else()
message(FATAL_ERROR "Cannot find hcc")
endif()
endif()
cmake_get_from(${CMAKE_CURRENT_LIST_DIR}/dev-requirements.txt PREFIX ${PREFIX} CMAKE_ARGS -DCMAKE_INSTALL_RPATH=${PREFIX}/lib ${PARSE_UNPARSED_ARGUMENTS})
add_library(rtg
add_library(migraph
generate.cpp
program.cpp
shape.cpp
)
rocm_clang_tidy_check(rtg)
target_include_directories(rtg PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
rocm_clang_tidy_check(migraph)
target_include_directories(migraph PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
add_subdirectory(onnx)
add_subdirectory(targets/cpu)
if(RTG_ENABLE_MIOPEN)
if(MIGRAPH_ENABLE_MIOPEN)
add_subdirectory(targets/miopen)
endif()
#include <rtg/generate.hpp>
#include <migraph/generate.hpp>
namespace rtg {
namespace migraph {
rtg::argument generate_argument(rtg::shape s, std::mt19937::result_type seed)
migraph::argument generate_argument(migraph::shape s, std::mt19937::result_type seed)
{
rtg::argument result;
migraph::argument result;
s.visit_type([&](auto as) {
using type = typename decltype(as)::type;
auto v = generate_tensor_data<type>(s, seed);
......@@ -13,4 +13,4 @@ rtg::argument generate_argument(rtg::shape s, std::mt19937::result_type seed)
return result;
}
} // namespace rtg
} // namespace migraph
#ifndef RTG_GUARD_RTGLIB_ARGUMENT_HPP
#define RTG_GUARD_RTGLIB_ARGUMENT_HPP
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_ARGUMENT_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_ARGUMENT_HPP
#include <rtg/shape.hpp>
#include <rtg/raw_data.hpp>
#include <migraph/shape.hpp>
#include <migraph/raw_data.hpp>
#include <functional>
namespace rtg {
namespace migraph {
/**
* @brief Arguments passed to instructions
......@@ -39,16 +39,10 @@ struct argument : raw_data<argument>
const shape& get_shape() const { return this->m_shape; }
template <class T>
T* cast() const
{
return reinterpret_cast<T*>(this->data());
}
private:
shape m_shape;
};
} // namespace rtg
} // namespace migraph
#endif
#ifndef RTG_GUARD_BUILTIN_HPP
#define RTG_GUARD_BUILTIN_HPP
#ifndef MIGRAPH_GUARD_BUILTIN_HPP
#define MIGRAPH_GUARD_BUILTIN_HPP
#include <rtg/operation.hpp>
#include <rtg/errors.hpp>
#include <migraph/context.hpp>
#include <migraph/errors.hpp>
namespace rtg {
namespace migraph {
namespace builtin {
struct literal
{
std::string name() const { return "@literal"; }
shape compute_shape(std::vector<shape>) const { RTG_THROW("builtin"); }
argument compute(shape, std::vector<argument>) const { RTG_THROW("builtin"); }
shape compute_shape(std::vector<shape>) const { MIGRAPH_THROW("builtin"); }
argument compute(context&, shape, std::vector<argument>) const { MIGRAPH_THROW("builtin"); }
};
struct outline
{
shape s;
std::string name() const { return "@outline"; }
shape compute_shape(std::vector<shape>) const { RTG_THROW("builtin"); }
argument compute(shape, std::vector<argument>) const { RTG_THROW("builtin"); }
shape compute_shape(std::vector<shape>) const { MIGRAPH_THROW("builtin"); }
argument compute(context&, shape, std::vector<argument>) const { MIGRAPH_THROW("builtin"); }
};
struct param
{
std::string parameter;
std::string name() const { return "@param"; }
shape compute_shape(std::vector<shape>) const { RTG_THROW("builtin"); }
argument compute(shape, std::vector<argument>) const { RTG_THROW("builtin"); }
shape compute_shape(std::vector<shape>) const { MIGRAPH_THROW("builtin"); }
argument compute(context&, shape, std::vector<argument>) const { MIGRAPH_THROW("builtin"); }
friend std::ostream& operator<<(std::ostream& os, const param& op)
{
os << op.name() << ":" << op.parameter;
......@@ -38,6 +38,6 @@ struct param
} // namespace builtin
} // namespace rtg
} // namespace migraph
#endif
#ifndef MIGRAPH_GUARD_CONTEXT_HPP
#define MIGRAPH_GUARD_CONTEXT_HPP
namespace migraph {
/*
* Type-erased interface for:
*
* struct context
* {
* };
*
*/
struct context
{
// Constructors
context() = default;
template <typename PrivateDetailTypeErasedT>
context(PrivateDetailTypeErasedT value)
: private_detail_te_handle_mem_var(
std::make_shared<private_detail_te_handle_type<
typename std::remove_reference<PrivateDetailTypeErasedT>::type>>(
std::forward<PrivateDetailTypeErasedT>(value)))
{
}
// Assignment
template <typename PrivateDetailTypeErasedT>
context& operator=(PrivateDetailTypeErasedT value)
{
if(private_detail_te_handle_mem_var.unique())
*private_detail_te_handle_mem_var = std::forward<PrivateDetailTypeErasedT>(value);
else if(!private_detail_te_handle_mem_var)
private_detail_te_handle_mem_var = std::make_shared<PrivateDetailTypeErasedT>(
std::forward<PrivateDetailTypeErasedT>(value));
return *this;
}
// Cast
template <typename PrivateDetailTypeErasedT>
PrivateDetailTypeErasedT* any_cast()
{
return private_detail_te_get_handle().type() == typeid(PrivateDetailTypeErasedT)
? std::addressof(static_cast<private_detail_te_handle_type<
typename std::remove_cv<PrivateDetailTypeErasedT>::type>&>(
private_detail_te_get_handle())
.private_detail_te_value)
: nullptr;
}
template <typename PrivateDetailTypeErasedT>
const typename std::remove_cv<PrivateDetailTypeErasedT>::type* any_cast() const
{
return private_detail_te_get_handle().type() == typeid(PrivateDetailTypeErasedT)
? std::addressof(static_cast<const private_detail_te_handle_type<
typename std::remove_cv<PrivateDetailTypeErasedT>::type>&>(
private_detail_te_get_handle())
.private_detail_te_value)
: nullptr;
}
const std::type_info& type_id() const
{
if(private_detail_te_handle_empty())
return typeid(std::nullptr_t);
else
return private_detail_te_get_handle().type();
}
private:
struct private_detail_te_handle_base_type
{
virtual ~private_detail_te_handle_base_type() {}
virtual std::shared_ptr<private_detail_te_handle_base_type> clone() const = 0;
virtual const std::type_info& type() const = 0;
};
template <typename PrivateDetailTypeErasedT>
struct private_detail_te_handle_type : private_detail_te_handle_base_type
{
template <typename PrivateDetailTypeErasedU = PrivateDetailTypeErasedT>
private_detail_te_handle_type(
PrivateDetailTypeErasedT value,
typename std::enable_if<std::is_reference<PrivateDetailTypeErasedU>::value>::type* =
nullptr)
: private_detail_te_value(value)
{
}
template <typename PrivateDetailTypeErasedU = PrivateDetailTypeErasedT>
private_detail_te_handle_type(
PrivateDetailTypeErasedT value,
typename std::enable_if<!std::is_reference<PrivateDetailTypeErasedU>::value,
int>::type* = nullptr) noexcept
: private_detail_te_value(std::move(value))
{
}
std::shared_ptr<private_detail_te_handle_base_type> clone() const override
{
return std::make_shared<private_detail_te_handle_type>(private_detail_te_value);
}
const std::type_info& type() const override { return typeid(private_detail_te_value); }
PrivateDetailTypeErasedT private_detail_te_value;
};
template <typename PrivateDetailTypeErasedT>
struct private_detail_te_handle_type<std::reference_wrapper<PrivateDetailTypeErasedT>>
: private_detail_te_handle_type<PrivateDetailTypeErasedT&>
{
private_detail_te_handle_type(std::reference_wrapper<PrivateDetailTypeErasedT> ref)
: private_detail_te_handle_type<PrivateDetailTypeErasedT&>(ref.get())
{
}
};
bool private_detail_te_handle_empty() const
{
return private_detail_te_handle_mem_var == nullptr;
}
const private_detail_te_handle_base_type& private_detail_te_get_handle() const
{
assert(private_detail_te_handle_mem_var != nullptr);
return *private_detail_te_handle_mem_var;
}
private_detail_te_handle_base_type& private_detail_te_get_handle()
{
assert(private_detail_te_handle_mem_var != nullptr);
if(!private_detail_te_handle_mem_var.unique())
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
return *private_detail_te_handle_mem_var;
}
std::shared_ptr<private_detail_te_handle_base_type> private_detail_te_handle_mem_var;
};
template <typename ValueType>
inline const ValueType* any_cast(const context* x)
{
return x->any_cast<ValueType>();
}
template <typename ValueType>
inline ValueType* any_cast(context* x)
{
return x->any_cast<ValueType>();
}
template <typename ValueType>
inline ValueType& any_cast(context& x)
{
auto* y = x.any_cast<typename std::remove_reference<ValueType>::type>();
if(y == nullptr)
throw std::bad_cast();
return *y;
}
template <typename ValueType>
inline const ValueType& any_cast(const context& x)
{
const auto* y = x.any_cast<typename std::remove_reference<ValueType>::type>();
if(y == nullptr)
throw std::bad_cast();
return *y;
}
} // namespace migraph
#endif
#ifndef RTG_GUARD_RTGLIB_DFOR_HPP
#define RTG_GUARD_RTGLIB_DFOR_HPP
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_DFOR_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_DFOR_HPP
namespace rtg {
namespace migraph {
// Multidimensional for loop
inline auto dfor()
......@@ -20,6 +20,6 @@ auto dfor(T x, Ts... xs)
};
}
} // namespace rtg
} // namespace migraph
#endif
#ifndef RTG_GUARD_ERASE_HPP
#define RTG_GUARD_ERASE_HPP
#ifndef MIGRAPH_GUARD_ERASE_HPP
#define MIGRAPH_GUARD_ERASE_HPP
namespace rtg {
namespace migraph {
/**
* @brief Erase all elements from a container
......@@ -29,6 +29,6 @@ auto erase_if(R&& r, P&& pred)
return r.erase(std::remove_if(r.begin(), r.end(), pred), r.end());
}
} // namespace rtg
} // namespace migraph
#endif
#ifndef RTG_GUARD_ERRORS_HPP
#define RTG_GUARD_ERRORS_HPP
#ifndef MIGRAPH_GUARD_ERRORS_HPP
#define MIGRAPH_GUARD_ERRORS_HPP
#include <exception>
#include <stdexcept>
#include <string>
namespace rtg {
namespace migraph {
/// Represents exceptions that can be thrown by rtglib
/// Represents exceptions that can be thrown by migraphlib
struct exception : std::runtime_error
{
exception(std::string msg = "") : std::runtime_error(msg) {}
......@@ -41,9 +41,9 @@ inline std::string make_source_context(const std::string& file, int line)
/**
* @brief Throw an exception with context information
*/
#define RTG_THROW(...) \
throw rtg::make_exception(rtg::make_source_context(__FILE__, __LINE__), __VA_ARGS__)
#define MIGRAPH_THROW(...) \
throw migraph::make_exception(migraph::make_source_context(__FILE__, __LINE__), __VA_ARGS__)
} // namespace rtg
} // namespace migraph
#endif
#ifndef MIGRAPH_GUARD_FALLTHROUGH_HPP
#define MIGRAPH_GUARD_FALLTHROUGH_HPP
namespace migraph {
#ifdef __clang__
#define MIGRAPH_FALLTHROUGH [[clang::fallthrough]]
#else
#define MIGRAPH_FALLTHROUGH
#endif
} // namespace migraph
#endif
#ifndef RTG_GUARD_RTGLIB_FLOAT_EQUAL_HPP
#define RTG_GUARD_RTGLIB_FLOAT_EQUAL_HPP
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_FLOAT_EQUAL_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_FLOAT_EQUAL_HPP
#include <algorithm>
#include <cmath>
......@@ -8,7 +8,7 @@
#include <iso646.h>
#endif
namespace rtg {
namespace migraph {
template <class... Ts>
using common_type = typename std::common_type<Ts...>::type;
......@@ -32,6 +32,6 @@ struct float_equal_fn
static constexpr float_equal_fn float_equal{};
} // namespace rtg
} // namespace migraph
#endif
#ifndef RTG_GUARD_RTGLIB_GENERATE_HPP
#define RTG_GUARD_RTGLIB_GENERATE_HPP
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP
#include <rtg/argument.hpp>
#include <migraph/argument.hpp>
#include <random>
namespace rtg {
namespace migraph {
template <class T>
std::vector<T> generate_tensor_data(rtg::shape s, std::mt19937::result_type seed = 0)
std::vector<T> generate_tensor_data(migraph::shape s, std::mt19937::result_type seed = 0)
{
std::vector<T> result(s.elements());
std::mt19937 engine{seed};
......@@ -16,8 +16,8 @@ std::vector<T> generate_tensor_data(rtg::shape s, std::mt19937::result_type seed
return result;
}
rtg::argument generate_argument(rtg::shape s, std::mt19937::result_type seed = 0);
migraph::argument generate_argument(migraph::shape s, std::mt19937::result_type seed = 0);
} // namespace rtg
} // namespace migraph
#endif
#ifndef RTG_GUARD_RTGLIB_INSTRUCTION_HPP
#define RTG_GUARD_RTGLIB_INSTRUCTION_HPP
#include <rtg/literal.hpp>
#include <rtg/shape.hpp>
#include <rtg/builtin.hpp>
#include <rtg/instruction_ref.hpp>
#include <rtg/erase.hpp>
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_INSTRUCTION_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_INSTRUCTION_HPP
#include <migraph/literal.hpp>
#include <migraph/shape.hpp>
#include <migraph/builtin.hpp>
#include <migraph/instruction_ref.hpp>
#include <migraph/erase.hpp>
#include <string>
namespace rtg {
namespace migraph {
shape compute_shape(operation op, std::vector<instruction_ref> args);
......@@ -52,7 +52,7 @@ struct instruction
{
for(auto&& arg : arguments)
{
rtg::erase(arg->output, *this);
migraph::erase(arg->output, *this);
}
}
......@@ -103,6 +103,6 @@ inline shape compute_shape(operation op, std::vector<instruction_ref> args)
return op.compute_shape(shapes);
}
} // namespace rtg
} // namespace migraph
#endif
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