Skip to content
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

testing real branch #80

Closed
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
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ else()
option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON)
endif()

option(MIGRAPHX_USE_ROCBLAS "Enable MIGraphX to use rocBLAS" ON)

# By default build shared libraries
option(BUILD_SHARED_LIBS "Create shared libraries" ON)

Expand Down Expand Up @@ -167,6 +169,9 @@ rocm_enable_clang_tidy(
-cert-dcl51-cpp
-cert-err33-c
-cert-str34-c
# We seed random numbers with constants for reproducibility
-cert-msc32-c
-cert-msc51-cpp
# Disable all alpha checks by default
-clang-analyzer-alpha*
# Enable some alpha checks
Expand Down Expand Up @@ -334,11 +339,18 @@ else()
set(DEPENDS_HIP_RUNTIME "hip-runtime-amd" )
endif()

if(MIGRAPHX_USE_ROCBLAS)
list(APPEND PACKAGE_DEPENDS rocblas)
endif()

rocm_package_add_deb_dependencies(SHARED_DEPENDS "hip-dev")
rocm_package_add_rpm_dependencies(SHARED_DEPENDS "hip-devel")

rocm_create_package(
NAME MIGraphX
DESCRIPTION "AMD's graph optimizer"
MAINTAINER "AMDMIGraphX Maintainer <[email protected]>"
LDCONFIG
PTH
DEPENDS miopen-hip rocblas ${DEPENDS_HIP_RUNTIME} hip-base half ${PACKAGE_DEPENDS}
DEPENDS miopen-hip ${DEPENDS_HIP_RUNTIME} half ${PACKAGE_DEPENDS}
)
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG PREFIX=/usr/local
RUN dpkg --add-architecture i386

# Install rocm key
RUN apt-get update && apt-get install -y gnupg2 --no-install-recommends curl && \
RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \
curl -sL http://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -

# Add rocm repository
Expand All @@ -15,6 +15,9 @@ RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/6.0
# From docs.amd.com for installing rocm. Needed to install properly
RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600"

# rocgdb doesn't work on 22.04, workaround by installing the older python packages that are in 20.04
RUN add-apt-repository -y ppa:deadsnakes/ppa

# Install dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \
apt-utils \
Expand All @@ -32,10 +35,10 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-
python3 \
python3-dev \
python3-pip \
software-properties-common \
libpython3.8 \
wget \
rocm-device-libs \
hip-base \
hip-dev \
libnuma-dev \
miopen-hip \
rocblas \
Expand Down
14 changes: 7 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ rocmtest clang_debug: rocmnode('mi100+') { cmake_build ->
cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_MLIR=On -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags_cxx}' -DCMAKE_C_FLAGS_DEBUG='${debug_flags}' -DGPU_TARGETS='${gpu_targets}'")
}
}
}, ck_hiprtc: rocmnode('mi100+') { cmake_build ->
stage('CK hipRTC') {
withEnv(['MIGRAPHX_ENABLE_CK=1', 'MIGRAPHX_TUNE_CK=1', 'MIGRAPHX_DISABLE_MLIR=1']) {
def gpu_targets = getgputargets()
cmake_build(flags: "-DCMAKE_BUILD_TYPE=release -DMIGRAPHX_USE_HIPRTC=On -DGPU_TARGETS='${gpu_targets}'")
}
}
//}, ck_hiprtc: rocmnode('mi100+') { cmake_build ->
// stage('CK hipRTC') {
// withEnv(['MIGRAPHX_ENABLE_CK=1', 'MIGRAPHX_TUNE_CK=1', 'MIGRAPHX_DISABLE_MLIR=1']) {
// def gpu_targets = getgputargets()
// cmake_build(flags: "-DCMAKE_BUILD_TYPE=release -DMIGRAPHX_USE_HIPRTC=On -DGPU_TARGETS='${gpu_targets}'")
// }
// }
}, clang_asan: rocmnode('nogpu') { cmake_build ->
stage('Clang ASAN') {
def sanitizers = "undefined,address"
Expand Down
2 changes: 1 addition & 1 deletion hip-clang.docker
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-
software-properties-common \
wget \
rocm-device-libs \
hip-base \
hip-dev \
libnuma-dev \
miopen-hip \
rocblas \
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ pybind/pybind11@d159a563383d10c821ba7b2a71905d1207db6de4 --build
msgpack/[email protected] -DMSGPACK_BUILD_TESTS=Off
[email protected] -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/composable_kernel@57cdd70b7cb14e5e3b60cd9a5f96ba8dc343763e -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/rocMLIR@ce62762a4f4f929e463091373f6d1f201da61204 -DBUILD_FAT_LIBROCKCOMPILER=On
ROCm/rocMLIR@e50d72fc6ab9a7a792d92a1ba7db6db45e4c508c -DBUILD_FAT_LIBROCKCOMPILER=On
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_library(migraphx
fp_to_double.cpp
fuse_concat.cpp
fuse_pointwise.cpp
fuse_pointwise_reduce.cpp
fuse_reduce.cpp
generate.cpp
inline_module.cpp
Expand Down Expand Up @@ -330,7 +331,10 @@ target_link_libraries(migraphx_all_targets INTERFACE migraphx_cpu)
target_compile_definitions(migraphx_all_targets INTERFACE -DHAVE_CPU)
endif()
if(MIGRAPHX_ENABLE_GPU)
list(APPEND MIGRAPHX_CONFIG_DEPENDS PACKAGE MIOpen PACKAGE rocblas)
if(MIGRAPHX_USE_ROCBLAS)
list(APPEND MIGRAPHX_CONFIG_DEPENDS PACKAGE rocblas)
endif()
list(APPEND MIGRAPHX_CONFIG_DEPENDS PACKAGE MIOpen)
add_subdirectory(targets/gpu)
target_link_libraries(migraphx_all_targets INTERFACE migraphx_gpu)
target_compile_definitions(migraphx_all_targets INTERFACE -DHAVE_GPU)
Expand Down
22 changes: 19 additions & 3 deletions src/api/include/migraphx/migraphx.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2024 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
Expand Down Expand Up @@ -67,8 +67,24 @@ std::string compute_type_name()
{
std::string name;
#if defined(_MSC_VER) && !defined(__clang__)
name = typeid(PrivateMigraphTypeNameProbe).name();
name = name.substr(7);
const char struct_name[] = "struct ";
const char class_name[] = "class ";
const char function_name[] = "compute_type_name<";
const char parameter_name[] = ">(void)";
const char cdecl_name[] = "__cdecl";

name = __FUNCSIG__;

auto begin = name.find(function_name) + sizeof(function_name) - 1;
auto length = name.find(parameter_name) - begin;
name = name.substr(begin, length);
if(name.find(class_name) == 0)
name = name.substr(sizeof(class_name) - 1);
else if(name.find(struct_name) == 0)
name = name.substr(sizeof(struct_name) - 1);
begin = name.find(cdecl_name);
if(begin != std::string::npos)
name.erase(begin, sizeof(cdecl_name) - 1);
#else
const char parameter_name[] = "PrivateMigraphTypeNameProbe ="; // NOLINT

Expand Down
20 changes: 19 additions & 1 deletion src/argument.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2024 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
Expand Down Expand Up @@ -102,6 +102,24 @@ void argument::assign_buffer(std::function<char*()> d)
})(s);
}

std::vector<argument> flatten(const std::vector<argument>& args)
{
std::vector<argument> result;
for(const auto& arg : args)
{
if(arg.get_shape().type() == shape::tuple_type)
{
auto subs = flatten(arg.get_sub_objects());
result.insert(result.end(), subs.begin(), subs.end());
}
else
{
result.push_back(arg);
}
}
return result;
}

std::vector<shape> to_shapes(const std::vector<argument>& args)
{
std::vector<shape> shapes;
Expand Down
18 changes: 15 additions & 3 deletions src/cpp_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ inline namespace MIGRAPHX_INLINE_NS {
cpp_generator::function&
cpp_generator::function::set_body(const module& m, const cpp_generator::generate_module_callback& g)
{
const std::string prefix = "zz";
std::unordered_map<migraphx::instruction_ref, std::string> names;
std::stringstream ss;

Expand All @@ -53,12 +54,13 @@ cpp_generator::function::set_body(const module& m, const cpp_generator::generate
}
else if(ins->name() == "@return")
{
assert(ins->inputs().size() == 1);
return_ins = ins->inputs().front();
names[ins] = prefix + "return";
ss << "auto " << names[ins] << " = " << g(ins, names) << ";\n";
return_ins = ins;
}
else
{
std::string n = "z" + std::to_string(names.size());
std::string n = prefix + std::to_string(names.size());
names[ins] = n;
ss << "auto " << n << " = " << g(ins, names) << ";\n";
}
Expand Down Expand Up @@ -125,6 +127,7 @@ struct cpp_generator_impl
std::function<std::string(std::string)> fmap = nullptr;
std::function<std::string(shape)> fresult = nullptr;
std::unordered_map<std::string, std::string> point_op_map = {};
bool always_return_tuple = false;
};
cpp_generator::cpp_generator() : impl(std::make_unique<cpp_generator_impl>()) {}

Expand All @@ -142,6 +145,8 @@ void cpp_generator::fmap(const std::function<std::string(std::string)>& f) { imp

void cpp_generator::fresult(const std::function<std::string(shape)>& f) { impl->fresult = f; }

void cpp_generator::always_return_tuple(bool b) { impl->always_return_tuple = b; }

void cpp_generator::add_point_op(const std::string& op_name, const std::string& code)
{
impl->point_op_map[op_name] = code;
Expand Down Expand Up @@ -222,6 +227,13 @@ cpp_generator::function cpp_generator::generate_module(const module& m,
});
return shape::cpp_type(ins->get_shape().type()) + "(" + string_literal + ")";
}
if(ins->name() == "@return")
{
// TODO: Customize the make_tuple call
if(impl->always_return_tuple or ins->inputs().size() != 1)
return "make_tuple(" + join_strings(to_args(ins->inputs(), names), ", ") + ")";
return names.at(ins->inputs().front());
}
auto s = g(ins, names);
if(impl->fresult)
return impl->fresult(ins->get_shape()) + '(' + s + ')';
Expand Down
6 changes: 3 additions & 3 deletions src/dom_info.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2024 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
Expand Down Expand Up @@ -31,7 +31,7 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

bool dominator_info::strictly_dominate(instruction_ref ins1, instruction_ref ins2)
bool dominator_info::strictly_dominate(instruction_ref ins1, instruction_ref ins2) const
{
if(ins1 == ins2)
return false;
Expand Down Expand Up @@ -65,7 +65,7 @@ dominator_info compute_dominator_generic(Visitor v)
if(children.size() == 1)
{
info.ins2idom[ins] = children.front();
instr2_doms[ins].insert(children.front());
instr2_doms[ins] = instr2_doms[children.front()];
}
else if(children.size() > 1)
{
Expand Down
6 changes: 2 additions & 4 deletions src/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2024 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
Expand All @@ -26,10 +26,8 @@ add_executable(driver
main.cpp
verify.cpp
passes.cpp
models.cpp
perf.cpp
resnet50.cpp
inceptionv3.cpp
alexnet.cpp
marker_roctx.cpp
)
set_target_properties(driver PROPERTIES OUTPUT_NAME migraphx-driver)
Expand Down
32 changes: 12 additions & 20 deletions src/driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ inline std::string get_version()

struct loader
{
std::string model;
std::string file;
std::string file_type;
unsigned batch = 1;
bool is_nhwc = true;
bool is_test = false;
unsigned trim = 0;
bool optimize = false;
bool skip_unknown_operators = false;
Expand All @@ -91,11 +91,10 @@ struct loader
void parse(argument_parser& ap)
{
ap(file, {}, ap.metavar("<input file>"), ap.file_exist(), ap.required(), ap.group("input"));
ap(model,
{"--model"},
ap.help("Load model"),
ap.type("resnet50|inceptionv3|alexnet"),
ap.matches({"resnet50", "inceptionv3", "alexnet"}),
ap(is_test,
{"--test"},
ap.help("Run a single GEMM to test MIGraphX"),
ap.set_value(true),
ap.group("input"));
ap(file_type, {"--onnx"}, ap.help("Load as onnx"), ap.set_value("onnx"));
ap(file_type, {"--tf"}, ap.help("Load as tensorflow"), ap.set_value("tf"));
Expand Down Expand Up @@ -312,7 +311,11 @@ struct loader
program load()
{
program p;
if(model.empty())
if(is_test)
{
p = test_gemm();
}
else
{
if(file_type.empty())
{
Expand Down Expand Up @@ -344,17 +347,6 @@ struct loader
p = migraphx::load(file);
}
}
else
{
if(model == "resnet50")
p = resnet50(batch);
else if(model == "inceptionv3")
p = inceptionv3(batch);
else if(model == "alexnet")
p = alexnet(batch);
else
MIGRAPHX_THROW("Unknown model: " + model);
}
if(trim > 0)
{
auto* mm = p.get_main_module();
Expand Down Expand Up @@ -396,7 +388,7 @@ struct loader
std::ofstream fs;
if(not output.empty())
{
fs.open(output);
fs.open(output, std::ios::binary);
os = &fs;
}

Expand Down Expand Up @@ -690,7 +682,7 @@ struct run_cmd : command<run_cmd>
struct perf : command<perf>
{
compiler c;
unsigned n = 100;
unsigned n = 100;
bool detailed = false;
void parse(argument_parser& ap)
{
Expand Down
Loading
Loading