Skip to content

Implement a new tensorview instruction #158

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

Merged
merged 2 commits into from
Dec 20, 2017
Merged

Implement a new tensorview instruction #158

merged 2 commits into from
Dec 20, 2017

Conversation

opti-mix
Copy link
Contributor

This instruction is used to create an unowned tensor with a required dimensionality from an existing tensor. The result is just a view of an existing tensor and does not allocate any new memory. Tensorview is essentially a typecast applied to a tensor.

Copy link
Contributor

@nadavrot nadavrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I am glad to see this land. I have a few comments about missing docs and one question. Thank you.

@@ -70,7 +70,10 @@ struct IRGenVisitor : NodeWalker {
}
assert(!generatedNodeDest_.count(N) &&
"Already generated code for this node");
assert(isa<AllocActivationInst>(v) && "The value must be an activation");
auto *dest = v;
if (auto *zn = dyn_cast<ZeroInst>(v))

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -59,6 +59,10 @@ class IRBuilder {

ReshapeInst *createReshapeOp(Value *input, llvm::ArrayRef<size_t> shape);

TensorViewInst *createTensorView(ElemKind elemKind,

This comment was marked as off-topic.

@@ -70,6 +70,24 @@ Tensor *Interpreter::getOrCreateTensor(const Value *v) {
return it->second;
}

Tensor *Interpreter::getOrCreateUnownedTensor(const Value *v,
const Value *src) {
assert(llvm::isa<TensorViewInst>(v) && "Expected a tensor view");

This comment was marked as off-topic.

@@ -60,6 +60,7 @@ class Interpreter final : public Backend {
/// tensor is already allocated for \p v.
/// \returns a tensor for \p v.
Tensor *getOrCreateTensor(const Value *v);
Tensor *getOrCreateUnownedTensor(const Value *v, const Value *src);

This comment was marked as off-topic.

auto odim = flattenCdr(outW.dims());
auto idim = flattenCdr(inW.dims());
assert(odim.first == idim.first && "Mismatch batch size");
// outW and inW are 2-dimensional.

This comment was marked as off-topic.

assert(inW.dims().size() == 2);
assert(inG.dims().size() == 2);

// outG and inW are 2-dimensional.

This comment was marked as off-topic.

Value *InGview = InG;
if (InGview->dims().size() != 2) {
auto idim = flattenCdr(InG->dims());
builder_.createZeroInst("zero", InG);

This comment was marked as off-topic.

auto idim = flattenCdr(inW.dims());
assert(odim.first == idim.first && "Mismatch batch size");
// outW and inW are 2-dimensional.
// Dimensions are batch size x activation. Weights are Y x Z.

This comment was marked as off-topic.

This instruction is used to create an unowned tensor with a required dimensionality from an existing tensor. The result is just a view of an existing tensor and does not allocate any new memory. Tensorview is essentially a typecast applied to a tensor.
@opti-mix opti-mix merged commit 6d6e80e into pytorch:master Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants