-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][HIP] Keep track of only shared USM allocations and prefetch only for those #11218
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e3be4e
Keep track of only shared USM allocations and prefetch only for those
40ff737
Add pass to add global to module using new pass manager
0b17c0b
Add test
faaf5a1
Tidy up cpp file
e9f3df3
Remove libclc changes
b7ad08c
Remove superfluous brackets
0b9eacd
Make test simpler
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===- AMDGPUAddGlobalForAtomicXor.cpp ------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Some AMDGPU atomic instructions require a prefetch in order for them to work | ||
// properly when using hipMallocManaged. This pass scans a module for the | ||
// problematic atomic instructions and creates a global PrefetchNeeded if the | ||
// builtin is present. This allows the prefetch to happen at runtime only if the | ||
// problematic builtin is chosen. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "AMDGPUAddGlobalForAtomicXor.h" | ||
#include "llvm/IR/InstIterator.h" | ||
#include "llvm/IR/Instructions.h" | ||
|
||
using namespace llvm; | ||
|
||
#define NEW_GLOBAL_NAME "HipAtomicXorModuleNeedsPrefetch" | ||
|
||
namespace { | ||
|
||
bool moduleHasAtomicXor(Module &M) { | ||
for (auto &F : M) | ||
for (auto &I : instructions(F)) | ||
if (auto *AtomicInst = dyn_cast<AtomicRMWInst>(&I); | ||
AtomicInst && AtomicInst->getOperation() == AtomicRMWInst::Xor) | ||
return true; | ||
return false; | ||
} | ||
|
||
} // end anonymous namespace | ||
|
||
PreservedAnalyses | ||
AMDGPUAddGlobalForAtomicXorPass::run(Module &M, ModuleAnalysisManager &AM) { | ||
if (!moduleHasAtomicXor(M)) | ||
return PreservedAnalyses::all(); | ||
LLVMContext &Ctx = M.getContext(); | ||
M.getOrInsertGlobal(NEW_GLOBAL_NAME, Type::getInt1Ty(Ctx), [&] { | ||
return new GlobalVariable( | ||
M, Type::getInt1Ty(Ctx), true, GlobalValue::InternalLinkage, | ||
Constant::getAllOnesValue(Type::getInt1Ty(Ctx)), NEW_GLOBAL_NAME); | ||
}); | ||
return PreservedAnalyses::none(); | ||
} |
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,32 @@ | ||
//===- AMDGPUAddGlobalForAtomicXor.h --------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Some AMDGPU atomic instructions require a prefetch in order for them to work | ||
// properly when using hipMallocManaged. This pass scans a module for the | ||
// problematic atomic instructions and creates a global PrefetchNeeded if the | ||
// builtin is present. This allows the prefetch to happen at runtime only if the | ||
// problematic builtin is chosen. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_AMDGPU_ADDGLOBALFORATOMICXOR_H | ||
#define LLVM_LIB_TARGET_AMDGPU_ADDGLOBALFORATOMICXOR_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class AMDGPUAddGlobalForAtomicXorPass | ||
: public PassInfoMixin<AMDGPUAddGlobalForAtomicXorPass> { | ||
public: | ||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_AMDGPU_ADDGLOBALFORATOMICXOR_H |
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
11 changes: 11 additions & 0 deletions
11
llvm/test/Analysis/GlobalsModRef/amdgpu-atomic-xor-add-global.ll
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,11 @@ | ||
; RUN: sed -e s/.T1://g %s | opt -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-add-global-for-atomic-xor -S | FileCheck %s --check-prefix=CHECK1 | ||
; RUN: sed -e s/.T2://g %s | opt -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-add-global-for-atomic-xor -S | FileCheck %s --check-prefix=CHECK2 | ||
|
||
define i32 @test(ptr %p) { | ||
; CHECK1: @HipAtomicXorModuleNeedsPrefetch | ||
; CHECK2-NOT: @HipAtomicXorModuleNeedsPrefetch | ||
;T1: %1 = atomicrmw volatile xor ptr %p, i32 1 syncscope("agent-one-as") monotonic, align 4 | ||
;T2: %1 = atomicrmw volatile add ptr %p, i32 1 syncscope("agent-one-as") monotonic, align 4 | ||
ret i32 %1 | ||
} | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.