Making the generated Triton IR deterministic & a script to compare cached assembly (#522)

This commit is contained in:
daadaada
2022-05-24 23:56:36 +08:00
committed by GitHub
parent 80f6a2698b
commit d5eaa8dfa0
3 changed files with 91 additions and 12 deletions

View File

@@ -1,12 +1,14 @@
#ifndef TDL_INCLUDE_IR_CODEGEN_LIVENESS_H
#define TDL_INCLUDE_IR_CODEGEN_LIVENESS_H
#include <map>
#include <set>
#include <vector>
#include "triton/codegen/analysis/layout.h"
#include "triton/tools/graph.h"
#include "llvm/ADT/MapVector.h"
#include <set>
#include <vector>
namespace triton{
namespace ir{
@@ -42,14 +44,14 @@ struct segment {
class liveness {
private:
typedef std::map<shared_layout*, segment> intervals_map_t;
typedef llvm::MapVector<shared_layout*, segment> intervals_map_t;
public:
// constructor
liveness(layouts *l): layouts_(l){ }
// accessors
const intervals_map_t& get() const { return intervals_; }
segment get(shared_layout* v) const { return intervals_.at(v); }
segment get(shared_layout* v) const { return intervals_.lookup(v); }
// run
void run(ir::module &mod);

View File

@@ -3,8 +3,9 @@
#ifndef _TRITON_TOOLS_THREAD_GRAPH_H_
#define _TRITON_TOOLS_THREAD_GRAPH_H_
#include "llvm/ADT/SetVector.h"
#include <map>
#include <set>
#include <vector>
#include <iostream>
@@ -13,21 +14,21 @@ namespace tools{
template<class node_t>
class graph {
typedef std::map<node_t, std::set<node_t>> edges_t;
typedef std::map<node_t, llvm::SetVector<node_t>> edges_t;
public:
typedef std::map<size_t, std::vector<node_t>> cmap_t;
typedef std::map<node_t, size_t> nmap_t;
private:
void connected_components_impl(node_t x, std::set<node_t> &nodes,
void connected_components_impl(node_t x, llvm::SetVector<node_t> &nodes,
nmap_t* nmap, cmap_t* cmap, int id) const {
if(nmap)
(*nmap)[x] = id;
if(cmap)
(*cmap)[id].push_back(x);
if(nodes.find(x) != nodes.end()) {
nodes.erase(x);
if (nodes.count(x)) {
nodes.remove(x);
for(const node_t &y: edges_.at(x))
connected_components_impl(y, nodes, nmap, cmap, id);
}
@@ -39,7 +40,7 @@ public:
cmap->clear();
if(nmap)
nmap->clear();
std::set<node_t> nodes = nodes_;
llvm::SetVector<node_t> nodes = nodes_;
unsigned id = 0;
while(!nodes.empty()){
connected_components_impl(*nodes.begin(), nodes, nmap, cmap, id++);
@@ -59,7 +60,7 @@ public:
}
private:
std::set<node_t> nodes_;
llvm::SetVector<node_t> nodes_;
edges_t edges_;
};