-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add a padding operator. #95
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03fdff1
add padding
mrbeann 4064629
add padding
mrbeann 9e54e3a
padding works
mrbeann 1090710
add py op
mrbeann 1b17e2a
fix tracer
mrbeann 02ef71e
update padding
mrbeann b2a51ba
Merge branch 'master' of https://github.com/harvard-acc/smaug into pa…
mrbeann c89fa42
update padding with more test and documentation
mrbeann fe44780
update padding
mrbeann d818a5f
update padding
mrbeann 7689d04
update padding
mrbeann 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 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 |
---|---|---|
|
@@ -28,42 +28,42 @@ class PaddingOp : public Operator { | |
|
||
/** | ||
* Set the paddingSize of the Tensor along each dimension. | ||
* The paddingSize is orgainized as <dim1_forward, dim1_backward, ... | ||
* ,dimk_backward> | ||
* The paddingSize is orgainized as <{dim0_begin, dim0_end, dim1_begin, | ||
* dim1_end, ... > | ||
*/ | ||
void setPaddingSize(RepeatedField<google::protobuf::int32> const& val) { | ||
void setPaddingSize(const RepeatedField<google::protobuf::int32>& val) { | ||
paddingSize.assign(val.begin(), val.end()); | ||
} | ||
|
||
void setPaddingSize(std::vector<int> const& val) { paddingSize = val; } | ||
|
||
std::vector<int> getPaddingSize() const { return paddingSize; } | ||
const std::vector<int>& getPaddingSize() const { return paddingSize; } | ||
|
||
void run() override { | ||
Tensor* input = getInput(0); | ||
Tensor* output = getOutput(0); | ||
Tensor* input = getInput(kInput); | ||
Tensor* output = getOutput(kOutput); | ||
int ndims = input->ndims(); | ||
const std::vector<int> inputDims = input->getShape().dims(); | ||
const std::vector<int> outputDims = output->getShape().dims(); | ||
const std::vector<int>& inputDims = input->getShape().dims(); | ||
const std::vector<int>& outputDims = output->getShape().dims(); | ||
int total_dim = 1; | ||
for (int i : outputDims) { | ||
total_dim *= i; | ||
} | ||
std::vector<float> vf(total_dim, 0); | ||
output->fillData(vf.data(), vf.size()); | ||
std::vector<int> destOrigin, paddingBegin, srcOrigin; | ||
std::vector<int> paddingBegin, srcOrigin; | ||
for (int i = 0; i < ndims; i++) { | ||
paddingBegin.push_back(paddingSize[2 * i]); | ||
paddingBegin.push_back(paddingSize.at(2 * i)); | ||
srcOrigin.push_back(0); | ||
} | ||
destOrigin = std::vector<int>(paddingBegin); | ||
std::vector<int> destOrigin = std::vector<int>(paddingBegin); | ||
std::vector<int> regionSize = inputDims; | ||
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. Same here - no need to make a copy of inputDims, just use it directly. I think you're trying to make it more clear what each vector is representing in the copyTensorRegion call but there's no need since the API documents it very clearly already. |
||
copyTensorRegion(output, input, destOrigin, srcOrigin, regionSize); | ||
} | ||
|
||
// Optional override for testing purposes. | ||
void createAllTensors() override { | ||
Tensor* input = getInput(0); | ||
Tensor* input = getInput(kInput); | ||
int ndims = input->ndims(); | ||
std::vector<int> dims = input->getShape().dims(); | ||
for (int i = 0; i < ndims; i++) { | ||
|
@@ -73,21 +73,21 @@ class PaddingOp : public Operator { | |
dims, input->getShape().getLayout(), Backend::Alignment); | ||
Tensor* output = new Tensor(name, shape); | ||
workspace->addTensor(output); | ||
outputs.at(0) = output; | ||
outputs.at(kOutput) = output; | ||
} | ||
|
||
// Optional but recommended function to verify operator parameters. | ||
bool validate() override { | ||
Tensor* input = getInput(0); | ||
Tensor* input = getInput(kInput); | ||
int ndims = input->ndims(); | ||
if (paddingSize.size() != 2 * ndims) { | ||
return false; | ||
} | ||
return Operator::validate(); | ||
} | ||
|
||
enum { kInputs, kNumInputs }; | ||
enum { kOutputs, kNumOutputs }; | ||
enum { kInput, kNumInputs }; | ||
enum { kOutput, kNumOutputs }; | ||
|
||
private: | ||
std::vector<int> paddingSize = {}; | ||
|
This file contains 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 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.
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.
Sorry, I should have caught this earlier. Why build
paddingBegin
and then copy it intodestOrigin
? Why not just use paddingBegin directly?