Commit 938792b0 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Initial working commit of tested compile trap of detected divzero instructions

parent f919cb7e
......@@ -182,7 +182,7 @@ struct module
instruction_ref validate() const;
instruction_ref find_dangling_reference() const;
instruction_ref find_division_by_zero() const;
instruction_ref flag_division_by_zero() const;
void finalize(context& ctx);
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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_OPERATORS_MUL_HPP
#define MIGRAPHX_GUARD_OPERATORS_MUL_HPP
#include <array>
#include <migraphx/op/binary.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <cmath>
#include <utility>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {
struct divzero : binary<divzero>
{
std::string name() const { return "divzero"; }
std::string point_function() const { return "divzero"; }
auto apply() const
{
return [](auto x, auto y) { return 0 * x * y; };
}
};
} // namespace op
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
......@@ -628,35 +628,14 @@ instruction_ref module::find_dangling_reference() const
return end();
}
bool is_div_zero(instruction_ref ins)
instruction_ref module::flag_division_by_zero() const
{
const auto& op = instruction::get_output_alias(ins)->get_operator();
std::cout << op.name() << std::endl;
return op.name().find("divzero") != std::string::npos;
}
instruction_ref module::find_division_by_zero() const
{
std::cout << "start search" << std::endl;
auto last = std::prev(end());
if(last->name() == "divzero")
{
std::cout << "search" << std::endl;
auto div_zero = std::find_if(
last->inputs().begin(), last->inputs().end(), [](auto x) { return is_div_zero(x); });
if(div_zero != last->inputs().end())
{
std::cout << "found divzero" << std::endl;
return *div_zero;
auto ins = end();
if (last->name() == "divzero") {
ins = begin();
}
}
else if(is_div_zero(last))
{
std::cout << "check last ref" << std::endl;
return last;
}
std::cout << "End ref" << std::endl;
return end();
return ins;
}
void module::finalize(context& ctx)
......
......@@ -195,9 +195,7 @@ void program::compile(const target& t, compile_options options)
std::to_string(index));
}
std::cout << "find div by zero" << std::endl;
std::cout << *mod << std::endl;
auto divide_by_zero = mod->find_division_by_zero();
auto divide_by_zero = mod->flag_division_by_zero();
if(divide_by_zero != mod->end())
{
auto index = std::distance(mod->begin(), divide_by_zero);
......
......@@ -43,6 +43,7 @@
#include <migraphx/op/argmax.hpp>
#include <migraphx/op/argmin.hpp>
#include <migraphx/op/rnn_var_sl_last_output.hpp>
#include <migraphx/op/divzero.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/par_dfor.hpp>
......@@ -695,6 +696,7 @@ struct ref_apply
apply_map["softmax"] = extend_op<ref_softmax<op::softmax>, op::softmax>();
apply_map["rnn_var_sl_last_output"] =
extend_op<ref_rnn_var_sl_last_output, op::rnn_var_sl_last_output>();
apply_map["divzero"] = simple_op<op::divzero>();
}
void apply()
......
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