blob: 00aac55a8fbff288709b2930d89777005c992044 [file] [log] [blame]
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "caffe2/core/context.h"
#include "caffe2/core/operator.h"
namespace caffe2 {
// RecordShapeOp records the shape of the input tensor to a vector of int. You
// mostly don't need this operator explicitly, and it is mostly used in the
// autodiff process.
template <class Context>
class ShapeOp : public Operator<Context> {
public:
USE_OPERATOR_CONTEXT_FUNCTIONS;
USE_SIMPLE_CTOR_DTOR(ShapeOp);
bool RunOnDevice() override {
auto& input = Input(0);
auto* output = OperatorBase::Output<Tensor<Context>>(0);
output->Resize(input.ndim());
TIndex* output_data = output->template mutable_data<TIndex>();
context_.template CopyBytes<Context, Context>(
input.ndim() * sizeof(TIndex), input.dims().data(), output_data);
return true;
}
};
} // namespace caffe2