bla
This commit is contained in:
@@ -54,8 +54,8 @@ void test(fp32 *a, fp32 *b, fp32 *c, int32 M, int32 N, int32 K, int32 bound){\
|
||||
int1 checkc1[16] = ryc < N;\
|
||||
int1 checkc[16, 16] = checkc0[:, newaxis] && checkc1[newaxis, :];\
|
||||
for(k = K; k > 0; k = k - 8){\
|
||||
int1 sanitya[16, 8] = (k >= bound);\
|
||||
int1 sanityb[16, 8] = (k >= bound);\
|
||||
int1 sanitya[16, 8] = (k > 16);\
|
||||
int1 sanityb[16, 8] = (k > 16);\
|
||||
C = dot(a, b, C);\
|
||||
pa = pa + 8*M;\
|
||||
pb = pb + 8*K;\
|
||||
@@ -236,7 +236,7 @@ int main() {
|
||||
// execute machine code
|
||||
// Allocate buffers
|
||||
typedef float numeric_t;
|
||||
size_t M = 128, N = 128, K = 128;
|
||||
size_t M = 32, N = 32, K = 32;
|
||||
size_t bound = 8;
|
||||
std::vector<numeric_t> c(M*N);
|
||||
std::vector<numeric_t> rc(M*N);
|
||||
|
@@ -287,14 +287,17 @@ public:
|
||||
class assignment_expression: public expression{
|
||||
public:
|
||||
assignment_expression(node *lvalue, ASSIGN_OP_T op, node *rvalue)
|
||||
: lvalue_((named_expression*)lvalue), op_(op), rvalue_((expression*)rvalue) { }
|
||||
: lhs_((named_expression*)lvalue), op_(op), rhs_((expression*)rvalue) { }
|
||||
|
||||
const expression *lhs() const { return lhs_; }
|
||||
const expression *rhs() const { return rhs_; }
|
||||
|
||||
ir::value* codegen(ir::module *mod) const;
|
||||
|
||||
public:
|
||||
ASSIGN_OP_T op_;
|
||||
const expression *lvalue_;
|
||||
const expression *rvalue_;
|
||||
const expression *lhs_;
|
||||
const expression *rhs_;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -16,26 +16,32 @@ class context;
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class instruction: public user{
|
||||
public:
|
||||
struct mask_info_t {
|
||||
value *pred;
|
||||
value *else_value;
|
||||
};
|
||||
|
||||
protected:
|
||||
// constructors
|
||||
instruction(type *ty, unsigned num_ops, const std::string &name = "", instruction *next = nullptr);
|
||||
|
||||
public:
|
||||
// parent
|
||||
void set_parent(basic_block *block) { parent_ = block; }
|
||||
const basic_block *get_parent() const { return parent_; }
|
||||
basic_block *get_parent() { return parent_; }
|
||||
void set_parent(basic_block *block) { parent_ = block; }
|
||||
const basic_block *get_parent() const { return parent_; }
|
||||
basic_block *get_parent() { return parent_; }
|
||||
void erase_from_parent();
|
||||
// mask
|
||||
value* set_mask(value *mask) { mask_ = mask; }
|
||||
value* get_mask() { return mask_; }
|
||||
value* set_mask(value *pred, value *else_value = nullptr) { mask_ = {pred, else_value}; }
|
||||
const mask_info_t get_mask() const { return mask_; }
|
||||
// helpers
|
||||
bool has_tile_result_or_op();
|
||||
|
||||
private:
|
||||
basic_block *parent_;
|
||||
value *pred_;
|
||||
value *mask_;
|
||||
mask_info_t mask_;
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@@ -527,16 +527,16 @@ ir::value *conditional_expression::codegen(ir::module *mod) const{
|
||||
|
||||
/* Assignment expression */
|
||||
ir::value *assignment_expression::codegen(ir::module *mod) const{
|
||||
ir::value *rvalue = rvalue_->codegen(mod);
|
||||
ir::value *rhs = rhs_->codegen(mod);
|
||||
if(auto *x = dynamic_cast<const named_expression*>(lvalue_))
|
||||
mod->set_value(x->id()->name(), rvalue);
|
||||
mod->set_value(x->id()->name(), rhs);
|
||||
else if(auto* x = dynamic_cast<const unary_operator*>(lvalue_)){
|
||||
assert(x->get_op()==DEREF);
|
||||
assert(x->lvalue());
|
||||
ir::value *ptr = x->lvalue()->codegen(mod);
|
||||
rvalue = mod->get_builder().create_store(ptr, rvalue);
|
||||
rhs = mod->get_builder().create_store(ptr, rhs);
|
||||
}
|
||||
return rvalue;
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/* Type name */
|
||||
|
@@ -481,14 +481,16 @@ void selection::lower_tile_instruction(ir::instruction *ins, llvm::IRBuilder<> &
|
||||
BasicBlock *block = builder.GetInsertBlock();
|
||||
Module *module = block->getModule();
|
||||
Function *function = block->getParent();
|
||||
ir::value *mask = ins->get_mask();
|
||||
ir::instruction::mask_info_t mask = ins->get_mask();
|
||||
LLVMContext &ctx = builder.getContext();
|
||||
// helper to handle masks
|
||||
auto insert_masked = [&](indices_t idx, std::function<Value*()> insert_value) {
|
||||
BasicBlock *block = builder.GetInsertBlock();
|
||||
Value *result;
|
||||
if(mask){
|
||||
Value *llvm_mask = tmap_.at(mask)->get_value(idx);
|
||||
if(mask.pred){
|
||||
// if(mask.else_value)
|
||||
// std::cout << mask.else_value << std::endl;
|
||||
Value *llvm_mask = tmap_.at(mask.pred)->get_value(idx);
|
||||
BasicBlock *then_bb = BasicBlock::Create(ctx, "", function);
|
||||
BasicBlock *done_bb = BasicBlock::Create(ctx, "", function);
|
||||
builder.CreateCondBr(llvm_mask, then_bb, done_bb);
|
||||
@@ -499,7 +501,10 @@ void selection::lower_tile_instruction(ir::instruction *ins, llvm::IRBuilder<> &
|
||||
if(!ins->get_type()->is_void_ty()){
|
||||
Type *ty = result->getType();
|
||||
PHINode *phi = builder.CreatePHI(ty, 2);
|
||||
phi->addIncoming(llvm::UndefValue::get(ty), block);
|
||||
// if(mask.else_value)
|
||||
// phi->addIncoming(tmap_.at(mask.else_value)->get_value(idx), block);
|
||||
// else
|
||||
phi->addIncoming(llvm::UndefValue::get(ty), block);
|
||||
phi->addIncoming(result, then_bb);
|
||||
return (Value*)phi;
|
||||
}
|
||||
@@ -728,7 +733,6 @@ void selection::run(ir::module &src, Module &dst){
|
||||
for(unsigned n = 0; n < phi->get_num_incoming(); n++){
|
||||
ir::value *inc_val = phi->get_incoming_value(n);
|
||||
ir::basic_block *inc_block = phi->get_incoming_block(n);
|
||||
std::cout << typeid(*inc_val).name() << " " << inc_val << " " << inc_block << std::endl;
|
||||
BasicBlock *llvm_inc_block = last_block.at(inc_block);
|
||||
if(phi->get_type()->is_tile_ty()) {
|
||||
distributed_tile *phi_tile = (distributed_tile*)tmap_.at(phi);
|
||||
|
@@ -67,17 +67,15 @@ void tune::init_c_graph(ir::instruction *v) {
|
||||
}
|
||||
// Element-wise
|
||||
else if(dynamic_cast<ir::user*>(v)){
|
||||
std::cout << typeid(*v).name() << std::endl;
|
||||
for(unsigned i = 0; i < shapes.size(); i ++)
|
||||
for(ir::value* op: v->ops())
|
||||
add_constraint({v, i}, {op, i});
|
||||
}
|
||||
|
||||
/* Add mask constraints */
|
||||
if(ir::value *mask = v->get_mask()){
|
||||
std::cout << typeid(*mask).name() << " " << typeid(*v->ops()[0]).name() << std::endl;
|
||||
if(ir::value *pred = v->get_mask().pred){
|
||||
for(unsigned i = 0; i < shapes.size(); i++)
|
||||
add_constraint({v->ops()[0], i}, {mask, i});
|
||||
add_constraint({v->ops()[0], i}, {pred, i});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user