-
-
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
Open
asindarov
wants to merge
30
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.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dcdbcfe
Implement initial support for Metal GPU backend
asindarov 19eb201
Implement support for simple saxpy kernel. Convert scalars into point…
asindarov 8a2b6eb
Resolve comments on incorrect logging & small cleanup
asindarov 8352f3d
Fix build error on CI
asindarov 63714b0
Fix CI build error
asindarov 34080e8
Fix CI build error
asindarov 5d356c3
Fix CI build error
asindarov 17a1164
Fix CI build error
asindarov 2579403
Fix CI build error
asindarov d67b452
Resolve comments on unused includes & small refactoring
asindarov 828aab8
Remove unused includes
asindarov 74076a9
Add falltrough comment and remove unnecessary change
asindarov 7665f5c
Remove unused include and whitespace
asindarov b060909
Update command line option for metal dcompute target
asindarov ebc302b
Update commented doc about metal dcompute target version
asindarov 330735f
Add codegen for metallib through xcrun -sdk macosx metallib terminal …
asindarov d059c1c
Move the error handling to line after writing the bitcode
asindarov 8d6da31
remove empty spaces and unused variables
asindarov 63300d0
remove unnecessary whitespaces
asindarov bd882b7
Fix CI error and add function inline pass for non-kernel functions
asindarov 42771eb
Add predefined global dcompute versions for cuda, ocl, metal
asindarov a4a519a
Add test case for metal GPU kernel metadata
asindarov 3a64374
rebase and resolve conflicts
asindarov 7641721
Add more tests
asindarov a0f976d
Fix build errors
asindarov 5687c2a
Fix build error
asindarov 99e347f
Fix build error
asindarov 2f46227
Fix build error
asindarov 0d3b1eb
Fix output llvm ir file name generation & remove unnecessary chunk of…
asindarov 33a641b
Instead of silently returning, give warning on other platforms that x…
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
| 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(); } |
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