-
-
Notifications
You must be signed in to change notification settings - Fork 292
Initial Metal backend support to dcompute #5118
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
base: master
Are you sure you want to change the base?
Changes from 29 commits
dcdbcfe
19eb201
8a2b6eb
8352f3d
63714b0
34080e8
5d356c3
17a1164
2579403
d67b452
828aab8
74076a9
7665f5c
b060909
ebc302b
330735f
d059c1c
8d6da31
63300d0
bd882b7
42771eb
a4a519a
3a64374
7641721
a0f976d
5687c2a
99e347f
2f46227
0d3b1eb
33a641b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //===-- gen/abi-metal.cpp ---------------------------------------*- C++ -*-===// | ||
| // | ||
| // LDC – the LLVM D compiler | ||
| // | ||
| // This file is distributed under the BSD-style LDC license. See the LICENSE | ||
| // file for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "gen/abi/abi.h" | ||
| #include "gen/dcompute/druntime.h" | ||
| #include "gen/dcompute/abi-rewrites.h" | ||
| #include "ir/irfuncty.h" | ||
| #include "dmd/mtype.h" | ||
| #include <optional> | ||
|
|
||
| using namespace dmd; | ||
|
|
||
| struct MetalABI : TargetABI { | ||
| DComputePointerRewrite pointerRewite; | ||
| DcomputeMetalScalarRewrite metalScalarRewrite; | ||
|
|
||
| auto returnInArg(TypeFunction *tf, bool needsThis) -> bool override { | ||
| return false; | ||
| } | ||
|
|
||
| auto passByVal(TypeFunction *tf, Type*t) -> bool override { | ||
| return false; | ||
| } | ||
|
|
||
| void rewriteFunctionType(IrFuncTy &fty) override { | ||
| for (auto arg : fty.args) { | ||
| if (!arg->byref) { | ||
| rewriteArgument(fty, *arg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override { | ||
| TargetABI::rewriteArgument(fty, arg); | ||
|
|
||
| if (arg.rewrite) { | ||
| return; | ||
| } | ||
|
|
||
| Type *ty = arg.type->toBasetype(); | ||
| std::optional<DcomputePointer> ptr; | ||
|
|
||
| if (ty->ty == TY::Tstruct && | ||
| (ptr = toDcomputePointer(static_cast<TypeStruct *>(ty)->sym))) { | ||
| pointerRewite.applyTo(arg); | ||
| } | ||
|
|
||
| if (dmd::isScalar(ty)) { | ||
| metalScalarRewrite.applyTo(arg); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| TargetABI* createMetalABI() { return new MetalABI(); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,19 @@ struct DComputePointerRewrite : ABIRewrite { | |
| return ptr->toLLVMType(true); | ||
| } | ||
| }; | ||
|
|
||
| struct DcomputeMetalScalarRewrite : ABIRewrite { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this now unused?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it still used in It is used to make scalar objects turn into a pointer in constant memory address space. Although it turns out scalars can also be stored in device level address space which will be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scalar arguments to kernels are just passed as parameters |
||
| LLType *type(Type* t) override { | ||
| // XXX: Scalar variables are stored in the constant memory space for Metal GPU | ||
| return llvm::PointerType::get(gIR->context(), 2/*Constant Memory space*/); | ||
| } | ||
|
|
||
| LLValue *getLVal(Type *dty, LLValue *v) override { | ||
| return v; | ||
| } | ||
|
|
||
| LLValue *put(DValue *v, bool isLValueExp, bool) override { | ||
| auto value = DtoRVal(v); | ||
| return value; | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.