"examples/dreambooth/train_dreambooth_lora_sdxl.py" did not exist on "04ddad484e26ed9689eef5aeee674895d007485a"
Commit 03b1421c authored by Paul's avatar Paul
Browse files

Add tracing during compilation

parent 73e91069
......@@ -3,6 +3,7 @@ add_library(migraph
auto_contiguous.cpp
dead_code_elimination.cpp
eliminate_contiguous.cpp
env.cpp
generate.cpp
program.cpp
shape.cpp
......
#include <migraph/env.hpp>
#include <migraph/ranges.hpp>
#include <cstdlib>
namespace migraph {
bool enabled(const char * name)
{
auto e = env(name);
if(e.empty())
return false;
return contains({"1", "enable", "enabled", "yes", "true"}, e.front());
}
bool disabled(const char * name)
{
auto e = env(name);
if(e.empty())
return false;
return contains({"0", "disable", "disabled", "no", "false"}, e.front());
}
std::vector<std::string> env(const char* name)
{
auto p = std::getenv(name);
if(p == nullptr)
return {};
else
return {{p}};
}
} // namespace migraph
#ifndef MIGRAPH_GUARD_RTGLIB_ENV_HPP
#define MIGRAPH_GUARD_RTGLIB_ENV_HPP
#include <vector>
#include <string>
namespace migraph {
// Declare a cached environment variable
#define MIGRAPH_DECLARE_ENV_VAR(x) \
struct x { static const char* value() { return #x; } }; // NOLINT
bool enabled(const char * name);
bool disabled(const char * name);
std::vector<std::string> env(const char* name);
template<class T>
bool enabled(T)
{
static const bool result = enabled(T::value());
return result;
}
template<class T>
bool disabled(T)
{
static const bool result = disabled(T::value());
return result;
}
} // namespace migraph
#endif
......@@ -2,13 +2,60 @@
#define MIGRAPH_GUARD_MIGRAPHLIB_RANGES_HPP
#include <algorithm>
#include <initializer_list>
namespace migraph {
template <int N>
struct rank : rank<N - 1>
{
};
template <>
struct rank<0>
{
};
namespace detail {
template <class String, class T>
auto generic_find_impl(rank<2>, String&& s, const T& x) -> decltype(s.begin() + s.find(x), s.npos)
{
auto index = s.find(x);
if (index == s.npos) return s.end();
else return s.begin() + index;
}
template <class C, class T>
auto generic_find_impl(rank<1>, C&& c, const T& x) -> decltype(c.find(x))
{
return c.find(x);
}
template <class C, class T>
bool contains(C&& c, T&& x)
auto generic_find_impl(rank<0>, C&& c, const T& x)
{
return std::find(c.begin(), c.end(), x);
}
} // namespace detail
template <class C, class T>
auto generic_find(C&& c, const T& x)
{
return detail::generic_find_impl(rank<2>{}, c, x);
}
template <class C, class T>
bool contains(const C& c, const T& x)
{
return generic_find(c, x) != c.end();
}
template <class T, class U>
bool contains(const std::initializer_list<T>& c, const U& x)
{
return c.find(x) != c.end();
return generic_find(c, x) != c.end();
}
template <class Range, class Iterator>
......
#include <migraph/program.hpp>
#include <migraph/stringutils.hpp>
#include <migraph/instruction.hpp>
#include <migraph/env.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
namespace migraph {
MIGRAPH_DECLARE_ENV_VAR(MIGRAPH_TRACE_COMPILE)
struct program_impl
{
// A list is used to keep references to an instruction stable
......@@ -183,9 +186,15 @@ void program::compile(const target& t)
{
assert(this->validate() == impl->instructions.end());
this->impl->ctx = t.get_context();
if(enabled(MIGRAPH_TRACE_COMPILE{}))
std::cout << *this << std::endl << std::endl;;
for(auto&& p : t.get_passes(this->impl->ctx))
{
if(enabled(MIGRAPH_TRACE_COMPILE{}))
std::cout << "Pass: " << p.name() << std::endl;
p.apply(*this);
if(enabled(MIGRAPH_TRACE_COMPILE{}))
std::cout << *this << std::endl << std::endl;
#ifndef NDEBUG
auto invalid = this->validate();
if(invalid != impl->instructions.end())
......
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