Skip to content
Merged
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
11 changes: 9 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def rocmtestnode(Map conf) {
export MIGRAPHX_GPU_DEBUG=${gpu_debug}
export CXX=${compiler}
export CXXFLAGS='-Werror'
rocminfo
env
rm -rf build
mkdir build
Expand Down Expand Up @@ -66,12 +67,18 @@ def rocmtestnode(Map conf) {
checkout scm
}

def video_id = sh(returnStdout: true, script: 'getent group video | cut -d: -f3').trim()
def render_id = sh(returnStdout: true, script: 'getent group render | cut -d: -f3').trim()
def docker_opts = "--device=/dev/kfd --device=/dev/dri --cap-add SYS_PTRACE -v=${env.WORKSPACE}/../:/workspaces:rw,z"
docker_opts = docker_opts + " --group-add=${video_id} --group-add=${render_id} "
echo "Docker flags: ${docker_opts}"

gitStatusWrapper(credentialsId: "${env.migraphx_ci_creds}", gitHubContext: "Jenkins - ${variant}", account: 'ROCmSoftwarePlatform', repo: 'AMDMIGraphX') {
withCredentials([usernamePassword(credentialsId: 'docker_test_cred', passwordVariable: 'DOCKERHUB_PASS', usernameVariable: 'DOCKERHUB_USER')]) {
sh "echo $DOCKERHUB_PASS | docker login --username $DOCKERHUB_USER --password-stdin"
pre()
sh "docker pull ${DOCKER_IMAGE}:${env.IMAGE_TAG}"
withDockerContainer(image: "${DOCKER_IMAGE}:${env.IMAGE_TAG}", args: "--device=/dev/kfd --device=/dev/dri --group-add video --cap-add SYS_PTRACE -v=${env.WORKSPACE}/../:/workspaces:rw,z ${docker_args}") {
withDockerContainer(image: "${DOCKER_IMAGE}:${env.IMAGE_TAG}", args: docker_opts + docker_args) {
timeout(time: 4, unit: 'HOURS') {
body(cmake_build)
}
Expand Down Expand Up @@ -192,7 +199,7 @@ rocmtest clang_debug: rocmnode('mi200+') { cmake_build ->
}
}, mlir_debug: rocmnode('mi100+') { cmake_build ->
stage('MLIR Debug') {
withEnv(['MIGRAPHX_ENABLE_EXTRA_MLIR=1', 'MIGRAPHX_MLIR_USE_SPECIFIC_OPS=fused,attention,convolution,dot,convolution_backwards', 'MIGRAPHX_ENABLE_MLIR_INPUT_FUSION=1', 'MIGRAPHX_MLIR_ENABLE_SPLITK=1', 'MIGRAPHX_ENABLE_MLIR_REDUCE_FUSION=1', 'MIGRAPHX_ENABLE_SPLIT_REDUCE=1','MIGRAPHX_DISABLE_LAYERNORM_FUSION=1']) {
withEnv(['MIGRAPHX_ENABLE_EXTRA_MLIR=1', 'MIGRAPHX_MLIR_USE_SPECIFIC_OPS=fused,attention,convolution,dot,convolution_backwards', 'MIGRAPHX_ENABLE_MLIR_INPUT_FUSION=1', 'MIGRAPHX_MLIR_ENABLE_SPLITK=1', 'MIGRAPHX_ENABLE_MLIR_REDUCE_FUSION=1', 'MIGRAPHX_ENABLE_MLIR_GEG_FUSION=1', 'MIGRAPHX_ENABLE_SPLIT_REDUCE=1','MIGRAPHX_DISABLE_LAYERNORM_FUSION=1']) {
def sanitizers = "undefined"
// Note: the -fno-sanitize= is copied from upstream LLVM_UBSAN_FLAGS.
def debug_flags = "-g -O2 -fsanitize=${sanitizers} -fno-sanitize=vptr,function -fno-sanitize-recover=${sanitizers}"
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
ROCmSoftwarePlatform/rocm-recipes
ROCm/rocm-recipes
facebook/zstd@v1.5.7 -X subdir -DCMAKE_DIR=build/cmake
ccache@v4.1 -DENABLE_TESTING=OFF
pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/MIGraphX-dev-env-vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ Model performance tunable variables change the compilation behavior of a model.

| Default: Reduction fusions are turned off.

* - | ``MIGRAPHX_ENABLE_MLIR_GEG_FUSION``
| Turns on GEMM+GEMM fusions in MLIR.

- | ``1``: Turns on G+G fusions.
| ``0``: Returns to default behavior.

| Default: GEMM+GEMM fusions are turned off.

* - | ``MIGRAPHX_MLIR_ENABLE_SPLITK``
| Turns on Split-k performance configurations during MLIR tuning.

Expand Down Expand Up @@ -213,6 +221,14 @@ Model performance tunable variables change the compilation behavior of a model.

| Default: No tuning is done for composable kernels.

* - | ``MIGRAPHX_REWRITE_LRN``
| Turns on LRN-to-pooling lowering in the ``rewrite_pooling`` pass.


- | ``1``: Turns on LRN-to-pooling lowering.
| ``0``: Returns to default behavior.

| Default: LRN-to-pooling lowering is turned off.

Matching
**********
Expand Down
3 changes: 2 additions & 1 deletion examples/diffusion/python_stable_diffusion_3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python3 -m venv sd_venv
Install dependencies

```bash
pip install --upgrade pip
pip install -r torch_requirements.txt
pip install -r requirements.txt
```
Expand All @@ -37,7 +38,7 @@ huggingface-cli login
Export the models to onnx.
Currently, optimum does not have the changes required in their latest release. Please install from their development branch instead.
```bash
python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
pip install "optimum-onnx[onnxruntime]"@git+https://github.com/huggingface/optimum-onnx.git
```

Once optimum is built, use the following command to export the models:
Expand Down
4 changes: 2 additions & 2 deletions rbuild.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
cxx = ${rocm_path}/llvm/bin/clang++
cc = ${rocm_path}/llvm/bin/clang
deps =
ROCmSoftwarePlatform/rocm-recipes
ROCm/rocm-recipes
-f requirements.txt

[gh]
ignore =
danmar/cppcheck
ROCmSoftwarePlatform/rocMLIR
ROCm/rocMLIR
deps =
-f dev-requirements.txt
oneapi-src/oneDNN@v1.7
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ nlohmann/json@v3.8.0 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
ROCm/half@rocm-5.6.0
pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build
msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off -DMSGPACK_BUILD_EXAMPLES=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
sqlite3@3.43.2 -DCMAKE_POSITION_INDEPENDENT_CODE=On
sqlite3@3.50.4 -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/composable_kernel@b7775add2d28251674d81e220cd4a857b90b997a -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/rocMLIR@33b0fc534532f8e8cb7bec2b5f7d20a69be2def5 -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off
31 changes: 22 additions & 9 deletions src/driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
#include <iomanip>

namespace {

using dims_map = std::unordered_map<std::string, std::vector<std::size_t>>;

std::vector<std::string>
get_unrecognized_migraphx_envs(const char* envp[],
const std::map<std::string, std::string>& used_env)
Expand Down Expand Up @@ -213,7 +216,7 @@ struct loader

static auto parse_param_dims(const std::vector<std::string>& param_dims_info)
{
std::unordered_map<std::string, std::vector<std::size_t>> map_input_dims;
dims_map map_input_dims;
std::string name = "";
for(auto&& x : param_dims_info)
{
Expand Down Expand Up @@ -502,16 +505,24 @@ struct program_params
return map_load_args;
}

auto generate(const program& p, const target& t, bool offload, unsigned batch)
auto generate(const program& p,
const target& t,
bool offload,
unsigned batch,
dims_map map_input_dims = {})
{
parameter_map m;
auto param_shapes = p.get_parameter_shapes();
std::unordered_map<std::string, shape> static_param_shapes;
std::transform(
param_shapes.cbegin(),
param_shapes.cend(),
std::inserter(static_param_shapes, static_param_shapes.end()),
[&](const auto& x) { return std::make_pair(x.first, x.second.to_static(batch)); });
for(auto&& param : param_shapes)
{
if(contains(map_input_dims, param.first))
static_param_shapes[param.first] = {param.second.type(),
map_input_dims[param.first]};
else
static_param_shapes[param.first] = param.second.to_static(batch);
}

for(auto&& s : fill0)
m[s] = fill_argument(static_param_shapes.at(s), 0);
for(auto&& s : fill1)
Expand Down Expand Up @@ -591,7 +602,8 @@ struct compiler

auto params(const program& p)
{
return parameters.generate(p, ct.get_target(), co.offload_copy, l.batch);
return parameters.generate(
p, ct.get_target(), co.offload_copy, l.batch, loader::parse_param_dims(l.param_dims));
}

auto host_params(const program& p)
Expand Down Expand Up @@ -730,7 +742,8 @@ struct verify : command<verify>
std::cout << p << std::endl;

auto t = c.ct.get_target();
auto m = c.parameters.generate(p, t, true, c.l.batch);
auto m =
c.parameters.generate(p, t, true, c.l.batch, loader::parse_param_dims(c.l.param_dims));

if(c.to_fp16)
{
Expand Down
1 change: 1 addition & 0 deletions src/include/migraphx/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ struct MIGRAPHX_EXPORT module
ins_dep_map calc_implicit_deps() const;

void repeat_while_changes(std::size_t n, const std::function<void()>& f);
void localized_sort(instruction_ref start_ins, instruction_ref end_ins);

MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os, const module& m);
MIGRAPHX_EXPORT friend bool operator==(const module& x, const module& y);
Expand Down
26 changes: 15 additions & 11 deletions src/include/migraphx/raw_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ struct raw_data : raw_data_base
friend Stream& operator<<(Stream& os, const Derived& d)
{
if(not d.empty())
d.visit([&](auto x) { os << x; },
[&](auto&& xs) {
for(auto&& x : xs)
{
os << "{ ";
os << x;
os << " }, ";
}
});
d.fallback_visit([&](auto x) { os << x; },
[&](auto&& xs) {
for(auto&& x : xs)
{
os << "{ ";
os << x;
os << " }, ";
}
});
return os;
}

Expand Down Expand Up @@ -123,9 +123,13 @@ struct raw_data : raw_data_base
}
else
{
auto&& buffer = static_cast<const Derived&>(*this).data();
auto* buffer = static_cast<const Derived&>(*this).data();
shape view_shape = {shape::uint8_type, {s.bytes()}};
v(make_view(view_shape, reinterpret_cast<byte*>(buffer)));
using byte_type =
std::conditional_t<std::is_const<std::remove_pointer_t<decltype(buffer)>>{},
const byte*,
byte*>;
v(make_view(view_shape, reinterpret_cast<byte_type>(buffer)));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/include/migraphx/rewrite_pooling.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-2025 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 @@ -38,6 +38,7 @@ struct module;
*/
struct MIGRAPHX_EXPORT rewrite_pooling
{
bool rewrite_lrn = false;
std::string name() const { return "rewrite_pooling"; }
void apply(module& m) const;
};
Expand Down
25 changes: 25 additions & 0 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,31 @@ void module::repeat_while_changes(std::size_t n, const std::function<void()>& f)
}
}

// For topologically sorting a region in a module, canonically, such that the
// dependent chain between the two input instructions is last
void module::localized_sort(instruction_ref start_ins, instruction_ref end_ins)
{
// get the chain of instructions between start_ins and end_ins, inclusive
auto fusion_ins = find_instructions_between(start_ins, end_ins, this);

// move all instructions between start_ins & end_ins that are not in the fusion chain
// to the start_ins. In order, moving to the same destination, this will naturally preserve
// the preexisting topological order of the module
for(auto it = std::next(start_ins); it != end_ins;)
{
if(fusion_ins.count(it) == 0)
{
auto next = std::next(it); // move_instruction updates the iterator
this->move_instruction(it, start_ins);
it = next;
}
else
{
++it;
}
}
}

bool operator==(const module& x, const module& y) { return to_string(x) == to_string(y); }

std::ostream& operator<<(std::ostream& os, const module& m)
Expand Down
1 change: 1 addition & 0 deletions src/onnx/onnx_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ shape::type_t get_type(int dtype)
case 18: return shape::fp8e4m3fnuz_type;
case 21: return shape::uint8_type;
case 22: return shape::int8_type;
case 23: return shape::fp4x2_type;
case 14:
case 15:
case 16: return shape::bf16_type;
Expand Down
Loading
Loading