-
Notifications
You must be signed in to change notification settings - Fork 13.4k
gpu offload host code generation #142097
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
ZuseZ4
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
ZuseZ4:offload-host1
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
gpu offload host code generation #142097
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3debe14
make more builder functions generic
ZuseZ4 22a499f
add -Zoffload=Enable flag, to enable gpu (host) code generation
ZuseZ4 3dc0c3b
various wrappers
ZuseZ4 c1e5961
gpu host code generation
ZuseZ4 5d3ce24
add gpu offload codegen host side test
ZuseZ4 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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ use std::ops::Deref; | |
use std::{iter, ptr}; | ||
|
||
pub(crate) mod autodiff; | ||
pub(crate) mod gpu_offload; | ||
|
||
use libc::{c_char, c_uint, size_t}; | ||
use rustc_abi as abi; | ||
|
@@ -117,6 +118,70 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> { | |
} | ||
bx | ||
} | ||
|
||
pub(crate) fn my_alloca2(&mut self, ty: &'ll Type, align: Align, name: &str) -> &'ll Value { | ||
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. I'll find a better name for it. |
||
let val = unsafe { | ||
let alloca = llvm::LLVMBuildAlloca(self.llbuilder, ty, UNNAMED); | ||
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint); | ||
// Cast to default addrspace if necessary | ||
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx.type_ptr(), UNNAMED) | ||
}; | ||
if name != "" { | ||
let name = std::ffi::CString::new(name).unwrap(); | ||
llvm::set_value_name(val, &name.as_bytes()); | ||
} | ||
val | ||
} | ||
|
||
pub(crate) fn inbounds_gep( | ||
&mut self, | ||
ty: &'ll Type, | ||
ptr: &'ll Value, | ||
indices: &[&'ll Value], | ||
) -> &'ll Value { | ||
unsafe { | ||
llvm::LLVMBuildGEPWithNoWrapFlags( | ||
self.llbuilder, | ||
ty, | ||
ptr, | ||
indices.as_ptr(), | ||
indices.len() as c_uint, | ||
UNNAMED, | ||
GEPNoWrapFlags::InBounds, | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value { | ||
debug!("Store {:?} -> {:?}", val, ptr); | ||
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer); | ||
unsafe { | ||
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr); | ||
llvm::LLVMSetAlignment(store, align.bytes() as c_uint); | ||
store | ||
} | ||
} | ||
|
||
pub(crate) fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value { | ||
unsafe { | ||
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED); | ||
llvm::LLVMSetAlignment(load, align.bytes() as c_uint); | ||
load | ||
} | ||
} | ||
|
||
fn memset(&mut self, ptr: &'ll Value, fill_byte: &'ll Value, size: &'ll Value, align: Align) { | ||
unsafe { | ||
llvm::LLVMRustBuildMemSet( | ||
self.llbuilder, | ||
ptr, | ||
align.bytes() as c_uint, | ||
fill_byte, | ||
size, | ||
false, | ||
); | ||
} | ||
} | ||
} | ||
|
||
/// Empty string, to be used where LLVM expects an instruction name, indicating | ||
|
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.
I'll remove the dbg statements.