Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin system #146

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5488cc8
Support plugin execution. Very limited capabilities for now.
m-kurtenacker Jan 31, 2023
0e1b609
Support for multiple input arguments.
m-kurtenacker Jul 28, 2022
3f0f38d
Use RTLD_GLOBAL to enable loading dependent plugins.
m-kurtenacker Sep 13, 2022
21e090e
Add plugin dependencies + option to return values from plugin intrins…
m-kurtenacker Sep 30, 2022
eaf6b75
Partial Evaluation between plugin steps.
m-kurtenacker Jan 20, 2023
da72529
Implement world.release to emit anydsl_release calls in backend, similar
m-kurtenacker Jun 23, 2023
5d2c468
Bugfix: llvm 14 needs pointer cast for release.
m-kurtenacker Jun 26, 2023
59aa49f
Fix MSVC build by disabling plugins
stlemme Jun 27, 2023
c706d3a
use proper CMAKE_DL_LIBS variable
stlemme Jun 27, 2023
a3d9092
Support return nullptr in plugins for void returns.
m-kurtenacker Jun 29, 2023
4d5b1b8
pass World and App to plugin function
michael-kenzel Jul 4, 2023
aea8051
Make plugins explicitly return a Def* to avoid UB.
m-kurtenacker Jul 5, 2023
986dc96
Do not const_cast the app node, use rebuild and replace_uses instead.
m-kurtenacker Jul 5, 2023
dd51c17
Gather plugins without copying continuations.
m-kurtenacker Jul 5, 2023
84fe231
Clearification on app nodes and world.cleanup().
m-kurtenacker Jul 5, 2023
c4423a0
Change plugin sorting comparisson to be asymetric.
m-kurtenacker Jul 5, 2023
3d73ba6
Do not build nvvm in debug mode. It produces broken ptx in some cases.
m-kurtenacker Apr 19, 2024
a81f7fc
Support plugin execution. Very limited capabilities for now.
m-kurtenacker Jan 31, 2023
51a0ae0
Support for multiple input arguments.
m-kurtenacker Jul 28, 2022
aa74f03
Use RTLD_GLOBAL to enable loading dependent plugins.
m-kurtenacker Sep 13, 2022
7d37d32
Add plugin dependencies + option to return values from plugin intrins…
m-kurtenacker Sep 30, 2022
4aed9b0
Partial Evaluation between plugin steps.
m-kurtenacker Jan 20, 2023
df0ceac
Implement world.release to emit anydsl_release calls in backend, similar
m-kurtenacker Jun 23, 2023
d4c4e13
Bugfix: llvm 14 needs pointer cast for release.
m-kurtenacker Jun 26, 2023
e6cb977
Fix MSVC build by disabling plugins
stlemme Jun 27, 2023
afb7d63
use proper CMAKE_DL_LIBS variable
stlemme Jun 27, 2023
6c704f0
Support return nullptr in plugins for void returns.
m-kurtenacker Jun 29, 2023
e45ae79
pass World and App to plugin function
michael-kenzel Jul 4, 2023
471d80b
Make plugins explicitly return a Def* to avoid UB.
m-kurtenacker Jul 5, 2023
8455787
Do not const_cast the app node, use rebuild and replace_uses instead.
m-kurtenacker Jul 5, 2023
807592e
Gather plugins without copying continuations.
m-kurtenacker Jul 5, 2023
1eebe0d
Clearification on app nodes and world.cleanup().
m-kurtenacker Jul 5, 2023
0c37e8d
Change plugin sorting comparisson to be asymetric.
m-kurtenacker Jul 5, 2023
d99f07c
Json: Export plugins and plugin dependencies.
m-kurtenacker Jan 20, 2023
968114c
[Json]: Export filters on plugins without dependencies.
m-kurtenacker Jan 20, 2023
20ab0c6
Plugin execution order: total ordering by calculating dependency depth.
m-kurtenacker Sep 4, 2023
4eb19d5
Bugfix Plugins: Work with new semantics for thorin.cleanup.
m-kurtenacker Oct 6, 2023
b44fbe4
Small improvements for internal continuations. Probably still buggy.
m-kurtenacker Nov 21, 2023
b345444
dump_scoped: Dump filters.
m-kurtenacker Nov 21, 2023
3ffeb3b
Fix handling and emission of external globals.
m-kurtenacker Dec 6, 2023
3c25ecc
Small bugfix in PE for multiple stacked run operations.
m-kurtenacker Dec 12, 2023
e3f8e45
Bugfix if no process can be made in plugin execution.
m-kurtenacker Dec 12, 2023
366f6b3
[JSON] Add support for inf and nan floating point.
m-kurtenacker Jan 19, 2024
63498d2
Some small changes to support edge cases created in certain plugins.
m-kurtenacker Feb 13, 2024
f4ef1d3
Allow disabling collored scoped_dump through environment variable.
m-kurtenacker Mar 19, 2024
417d8f3
WIP: evaluate plugins during PE, not after.
m-kurtenacker Mar 19, 2024
f4e655f
Improve plugin dependency management, allow filters with intrinsics.
m-kurtenacker Mar 27, 2024
138b6f4
Exceptions in plugins added back in.
m-kurtenacker Mar 28, 2024
2776537
Added Thorin::cleanup_fix_point as a less intrusive cleanup option.
m-kurtenacker Mar 28, 2024
a4c8aa0
Do not destroy external continuations during PE.
m-kurtenacker Apr 19, 2024
bf48e92
Merge remote-tracking branch 'origin/plugins' into plugins
m-kurtenacker Jun 20, 2024
50f60fd
Merge branch 'master' into plugins
m-kurtenacker Jun 24, 2024
53e3a87
Fix todo flag handling with plugins. Plugins can now return bottom.
m-kurtenacker Jul 24, 2024
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
Prev Previous commit
Next Next commit
Implement world.release to emit anydsl_release calls in backend, similar
to alloc.
  • Loading branch information
m-kurtenacker committed Jun 20, 2024
commit df0ceacc510368661b06708c1314189be3c88871
1 change: 1 addition & 0 deletions src/thorin/be/llvm/amdgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AMDGPUCodeGen : public CodeGen {
llvm::Value* emit_mathop(llvm::IRBuilder<>&, const MathOp*) override;
llvm::Value* emit_reserve(llvm::IRBuilder<>&, const Continuation*) override;
std::string get_alloc_name() const override { return "malloc"; }
std::string get_release_name() const override { return "free"; }

const Cont2Config& kernel_config_;
};
Expand Down
1 change: 1 addition & 0 deletions src/thorin/be/llvm/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CPUCodeGen : public CodeGen {

protected:
std::string get_alloc_name() const override { return "anydsl_alloc"; }
std::string get_release_name() const override { return "anydsl_release"; }
};

}
Expand Down
11 changes: 11 additions & 0 deletions src/thorin/be/llvm/llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ llvm::Value* CodeGen::emit_builder(llvm::IRBuilder<>& irbuilder, const Def* def)
} else if (auto alloc = def->isa<Alloc>()) {
emit_unsafe(alloc->mem());
return emit_alloc(irbuilder, alloc->alloced_type(), alloc->extra());
} else if (auto release = def->isa<Release>()) {
emit_unsafe(release->mem());
return emit_release(irbuilder, release->alloc());
} else if (auto slot = def->isa<Slot>()) {
return emit_alloca(irbuilder, convert(slot->type()->as<PtrType>()->pointee()), slot->unique_name());
} else if (auto vector = def->isa<Vector>()) {
Expand Down Expand Up @@ -1058,6 +1061,14 @@ llvm::Value* CodeGen::emit_alloc(llvm::IRBuilder<>& irbuilder, const Type* type,
return irbuilder.CreatePointerCast(void_ptr, llvm::PointerType::get(context(), 0));
}

llvm::Value* CodeGen::emit_release(llvm::IRBuilder<>& irbuilder, const Def* alloc) {
auto llvm_release = runtime_->get(*this, get_release_name().c_str());
llvm::Value* llvm_alloc = emit(alloc);
llvm::Value* release_args[] = { irbuilder.getInt32(0), llvm_alloc };
irbuilder.CreateCall(llvm_release, release_args);
return nullptr;
}

llvm::AllocaInst* CodeGen::emit_alloca(llvm::IRBuilder<>& irbuilder, llvm::Type* type, const std::string& name) {
// Emit the alloca in the entry block
auto entry = &irbuilder.GetInsertBlock()->getParent()->getEntryBlock();
Expand Down
2 changes: 2 additions & 0 deletions src/thorin/be/llvm/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CodeGen : public thorin::CodeGen, public thorin::Emitter<llvm::Value*, llv

llvm::AllocaInst* emit_alloca(llvm::IRBuilder<>&, llvm::Type*, const std::string&);
llvm::Value* emit_alloc (llvm::IRBuilder<>&, const Type*, const Def*);
llvm::Value* emit_release (llvm::IRBuilder<>&, const Def*);
virtual void emit_fun_decl_hook(Continuation*, llvm::Function*) {}
virtual llvm::Value* map_param(llvm::Function*, llvm::Argument* a, const Param*) { return a; }

Expand All @@ -87,6 +88,7 @@ class CodeGen : public thorin::CodeGen, public thorin::Emitter<llvm::Value*, llv
llvm::Value* emit_reserve_shared(llvm::IRBuilder<>&, const Continuation*, bool=false);

virtual std::string get_alloc_name() const = 0;
virtual std::string get_release_name() const = 0;
llvm::BasicBlock* cont2bb(Continuation* cont) { return cont2bb_[cont].first; }

virtual llvm::Value* emit_global(const Global*);
Expand Down
1 change: 1 addition & 0 deletions src/thorin/be/llvm/nvvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NVVMCodeGen : public CodeGen {
llvm::Value* emit_global(const Global*) override;

std::string get_alloc_name() const override { return "malloc"; }
std::string get_release_name() const override { return "free"; }

private:
llvm::Function* get_texture_handle_fun(llvm::IRBuilder<>&);
Expand Down
10 changes: 10 additions & 0 deletions src/thorin/primop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ Alloc::Alloc(World& world, const Type* type, const Def* mem, const Def* extra, D
set_type(world.tuple_type({world.mem_type(), world.ptr_type(type)}));
}

Release::Release(World& world, const Def* mem, const Def* alloc, Debug dbg)
: MemOp(world, Node_Release, nullptr, {mem, alloc}, dbg)
{
set_type(world.mem_type());
}

Load::Load(World& world, const Def* mem, const Def* ptr, Debug dbg)
: Access(world, Node_Load, nullptr, {mem, ptr}, dbg)
{
Expand Down Expand Up @@ -223,6 +229,10 @@ const Def* Alloc::rebuild(World& w, const Type* t, Defs o) const {
return w.alloc(t->as<TupleType>()->op(1)->as<PtrType>()->pointee(), o[0], o[1], debug());
}

const Def* Release::rebuild(World& w, const Type* t, Defs o) const {
return w.release(o[0], o[1], debug());
}

const Def* Assembly::rebuild(World& w, const Type* t, Defs o) const {
return w.assembly(t, o, asm_template(), output_constraints(), input_constraints(), clobbers(), flags(), debug());
}
Expand Down
14 changes: 14 additions & 0 deletions src/thorin/primop.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,20 @@ class Alloc : public MemOp {
friend class World;
};

class Release : public MemOp {
private:
Release(World& world, const Def* mem, const Def* alloc, Debug dbg);

public:
const Def* alloc() const { return op(1); }

private:
const Def* rebuild(World&, const Type*, Defs) const override;

friend class World;
};


/// Base class for @p Load and @p Store.
class Access : public MemOp {
protected:
Expand Down
1 change: 1 addition & 0 deletions src/thorin/tables/nodetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
THORIN_NODE(BlobPtr, mem_blob)
// MemOp
THORIN_NODE(Alloc, alloc)
THORIN_NODE(Release, release)
// Access
THORIN_NODE(Load, load)
THORIN_NODE(Store, store)
Expand Down
4 changes: 4 additions & 0 deletions src/thorin/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ const Def* World::alloc(const Type* type, const Def* mem, const Def* extra, Debu
return cse(new Alloc(*this, type, mem, extra, dbg));
}

const Def* World::release(const Def* mem, const Def* alloc, Debug dbg) {
return cse(new Release(*this, mem, alloc, dbg));
}

const Def* World::global(const Def* init, bool is_mutable, Debug dbg) {
return cse(new Global(*this, init, is_mutable, dbg));
}
Expand Down
1 change: 1 addition & 0 deletions src/thorin/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class World : public Streamable<World> {
const Def* slot(const Type* type, const Def* frame, Debug dbg = {}) { return cse(new Slot(*this, type, frame, dbg)); }
const Def* alloc(const Type* type, const Def* mem, const Def* extra, Debug dbg = {});
const Def* alloc(const Type* type, const Def* mem, Debug dbg = {}) { return alloc(type, mem, literal_qu64(0, dbg), dbg); }
const Def* release(const Def* mem, const Def* alloc, Debug dbg = {});
const Def* global(const Def* init, bool is_mutable = true, Debug dbg = {});
const Def* global_immutable_string(const std::string& str, Debug dbg = {});
const Def* lea(const Def* ptr, const Def* index, Debug dbg);
Expand Down