Repository navigation
Conv workspace via framework allocation #222
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
asglover
wants to merge
5
commits into
main
Choose a base branch
from
conv-workspace-via-framework-allocation
base: main
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
5 commits
Select commit
Hold shift + click to select a range
b7a2a78
framework managed workspace allocations
asglover b0aee00
make default zero so the allocation can be eliminated in atomic mode
asglover 9be39aa
fmt
asglover 3afa8a8
change to empty for performance, bug fix comes separately
asglover 9d0c2c2
remove zeroing for jax workspace as well
asglover 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
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 |
|---|---|---|
|
|
@@ -20,33 +20,49 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| KernelLaunchConfig backward_config_ref; | ||
| KernelLaunchConfig double_backward_config_ref; | ||
| int opt_level; | ||
| bool deterministic; | ||
|
|
||
| enum Kernel { | ||
| FORWARD = 0, | ||
| BACKWARD = 1, | ||
| DOUBLE_BACKWARD_A = 2, | ||
| DOUBLE_BACKWARD_B = 3, | ||
| FIXUP_FORWARD = 4, | ||
| FIXUP_BACKWARD = 5, | ||
| FIXUP_DOUBLE_BACKWARD_B = 6 | ||
| }; | ||
|
|
||
| JITConvImpl( | ||
| std::string jit_kernel, | ||
| KernelLaunchConfig forward_config_i, | ||
| KernelLaunchConfig backward_config_i, | ||
| KernelLaunchConfig double_backward_config_i, | ||
| int opt_level_i) : | ||
| int opt_level_i, | ||
| bool deterministic_i) : | ||
| jit(jit_kernel), | ||
| forward_config_ref(forward_config_i), | ||
| backward_config_ref(backward_config_i), | ||
| double_backward_config_ref(double_backward_config_i), | ||
| opt_level(opt_level_i) { | ||
| opt_level(opt_level_i), | ||
| deterministic(deterministic_i) { | ||
|
|
||
| vector<string> kernels = {"forward", "backward", "fixup_forward", "fixup_backward", "double_backward_A", "double_backward_B", "fixup_double_backwardB"}; | ||
| jit.compile(kernels, {{}, {}, {}, {}, {}, {}, {}}, opt_level); | ||
| vector<string> kernels = {"forward", "backward", "double_backward_A", "double_backward_B"}; | ||
| if(deterministic) { | ||
| kernels.insert(kernels.end(), {"fixup_forward", "fixup_backward", "fixup_double_backwardB"}); | ||
| } | ||
| jit.compile(kernels, vector<vector<int>>(kernels.size()), opt_level); | ||
|
|
||
| if(forward_config_ref.smem > 0) { | ||
| jit.set_max_smem(0, forward_config_ref.smem); | ||
| jit.set_max_smem(4, forward_config_ref.smem); | ||
| jit.set_max_smem(FORWARD, forward_config_ref.smem); | ||
| jit.set_max_smem(DOUBLE_BACKWARD_A, forward_config_ref.smem); | ||
|
Member
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. Cool, thanks for making this an enum |
||
| } | ||
|
|
||
| if(backward_config_ref.smem > 0) { | ||
| jit.set_max_smem(1, backward_config_ref.smem); | ||
| jit.set_max_smem(BACKWARD, backward_config_ref.smem); | ||
| } | ||
|
|
||
| if(double_backward_config_ref.smem > 0) { | ||
| jit.set_max_smem(5, double_backward_config_ref.smem); | ||
| jit.set_max_smem(DOUBLE_BACKWARD_B, double_backward_config_ref.smem); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -73,7 +89,8 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| dbl_bwd_dict["num_threads"], | ||
| dbl_bwd_dict["smem"] | ||
| ), | ||
| static_cast<int>(kernel_dims["opt_level"])) { } | ||
| static_cast<int>(kernel_dims["opt_level"]), | ||
| kernel_dims["deterministic"] != 0) { } | ||
|
|
||
| void exec_conv( | ||
| void* L1_in, | ||
|
|
@@ -90,9 +107,9 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| ConvData conv_data = {rows, cols, nnz, node_count}; | ||
|
|
||
| void *args[] = {&L1_in, &L2_in, &weights, &L3_out, &conv_data, &workspace}; | ||
| jit.execute(0, args, with_stream(forward_config_ref, stream)); | ||
| jit.execute(FORWARD, args, with_stream(forward_config_ref, stream)); | ||
|
|
||
| if(reinterpret_cast<uint64_t>(workspace) != 0) { | ||
| if(deterministic) { | ||
| void *fixup_args[] = {&workspace, &L3_out}; | ||
|
|
||
| KernelLaunchConfig fixup_config( | ||
|
|
@@ -102,7 +119,7 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| ); | ||
| fixup_config.hStream = stream; | ||
|
|
||
| jit.execute(2, fixup_args, fixup_config); | ||
| jit.execute(FIXUP_FORWARD, fixup_args, fixup_config); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -119,9 +136,9 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
|
|
||
| ConvData conv_data = {rows, cols, nnz, node_count}; | ||
| void *args[] = {&L1_in, &L1_grad, &L2_in, &L2_grad, &weight, &weight_grad, &L3_grad, &conv_data, &workspace, &transpose_perm}; | ||
| jit.execute(1, args, with_stream(backward_config_ref, stream)); | ||
| jit.execute(BACKWARD, args, with_stream(backward_config_ref, stream)); | ||
|
|
||
| if(reinterpret_cast<uint64_t>(workspace) != 0) { | ||
| if(deterministic) { | ||
| void *fixup_args[] = {&workspace, &L1_grad}; | ||
|
|
||
| KernelLaunchConfig fixup_config( | ||
|
|
@@ -131,7 +148,7 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| ); | ||
| fixup_config.hStream = stream; | ||
|
|
||
| jit.execute(3, fixup_args, fixup_config); | ||
| jit.execute(FIXUP_BACKWARD, fixup_args, fixup_config); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -150,28 +167,28 @@ class __attribute__ ((visibility ("default"))) JITConvImpl { | |
| &L1_grad, &L2_grad, &W_grad, &L3_dgrad, &conv_data, &wspace, &transpose_perm | ||
| }; | ||
|
|
||
| jit.execute(4, args, with_stream(forward_config_ref, stream)); | ||
| if(reinterpret_cast<uint64_t>(wspace) != 0) { | ||
| jit.execute(DOUBLE_BACKWARD_A, args, with_stream(forward_config_ref, stream)); | ||
| if(deterministic) { | ||
| void *fixup_args[] = {&wspace, &L3_dgrad}; | ||
| KernelLaunchConfig fixup_config( | ||
| forward_config_ref.num_blocks, | ||
| forward_config_ref.num_threads, | ||
| 0 | ||
| ); | ||
| fixup_config.hStream = stream; | ||
| jit.execute(2, fixup_args, fixup_config); | ||
| jit.execute(FIXUP_FORWARD, fixup_args, fixup_config); | ||
| } | ||
|
|
||
| jit.execute(5, args, with_stream(double_backward_config_ref, stream)); | ||
| if(reinterpret_cast<uint64_t>(wspace) != 0) { | ||
| jit.execute(DOUBLE_BACKWARD_B, args, with_stream(double_backward_config_ref, stream)); | ||
| if(deterministic) { | ||
| void *fixup_args[] = {&wspace, &L1_grad}; | ||
| KernelLaunchConfig fixup_config( | ||
| double_backward_config_ref.num_blocks, | ||
| double_backward_config_ref.num_threads, | ||
| 0 | ||
| ); | ||
| fixup_config.hStream = stream; | ||
| jit.execute(6, fixup_args, fixup_config); | ||
| jit.execute(FIXUP_DOUBLE_BACKWARD_B, fixup_args, fixup_config); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ Tensor tensor_zeros_like(const Tensor &ref, const std::vector<int64_t> &sizes) { | |
| return torch::zeros(sizes, ref.options()); | ||
| } | ||
|
|
||
| Tensor tensor_empty_bytes(const Tensor &ref, int64_t nbytes) { | ||
|
Member
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. Seems like this function is unused? |
||
| return torch::empty({nbytes}, ref.options().dtype(torch::kByte)); | ||
| } | ||
|
|
||
| void tensor_zero_(Tensor &tensor) { | ||
| tensor.zero_(); | ||
| } | ||
|
|
||
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.
Mm - it was always allocated by the framework (albeit at the Python level) - more accurate to state that it's allocated inside the extension at the C++ level.