-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
Draft
asindarov
wants to merge
20
commits into
ldc-developers:master
Choose a base branch
from
asindarov:metal-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
805ad58
Implement initial support for Metal GPU backend
asindarov 3420ee8
Implement support for simple saxpy kernel. Convert scalars into point…
asindarov eb96124
Resolve comments on incorrect logging & small cleanup
asindarov bf0016e
Fix build error on CI
asindarov 182df17
Fix CI build error
asindarov eae34b9
Fix CI build error
asindarov 05c37fc
Fix CI build error
asindarov 7fe3396
Fix CI build error
asindarov 5906ad4
Fix CI build error
asindarov 955b6ec
Resolve comments on unused includes & small refactoring
asindarov 172eda2
Remove unused includes
asindarov fce3b8e
Add falltrough comment and remove unnecessary change
asindarov 3615c1b
Remove unused include and whitespace
asindarov e98a9c3
Update command line option for metal dcompute target
asindarov 13ba222
Update commented doc about metal dcompute target version
asindarov d6b2612
Add codegen for metallib through xcrun -sdk macosx metallib terminal …
asindarov 392acdf
Move the error handling to line after writing the bitcode
asindarov cfb8a02
remove empty spaces and unused variables
asindarov 4c30105
remove unnecessary whitespaces
asindarov 8e1f05f
Fix CI error and add function inline pass for non-kernel functions
asindarov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (ty->isScalar()) { | ||
| metalScalarRewrite.applyTo(arg); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| TargetABI* createMetalABI() { return new MetalABI(); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this now unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it still used in
abi/metal.cppfile: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
Globalin the dcompute term as I understandThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scalar arguments to kernels are just passed as parameters