tensorflow/lite/delegates/gpu/common/gpu_model.cc
// Serialized model will lose polymorphic properties for GpuOperations.
// Here we will retrieve some information needed for generic execution of
// GpuOperations. Specifically, BindArguments and RecalculateGridSize must be
// executed.
Serialized model will lose polymorphic properties for GpuOperations.
Here we will retrieve some information needed for generic execution of
GpuOperations. Specifically, BindArguments and RecalculateGridSize must be
executed.
Serialized model will lose polymorphic properties for GpuOperations . Here we will retrieve some information needed for generic execution of GpuOperations . Specifically BindArguments and RecalculateGridSize must be executed .
absl::Status ResolvePolymorphicArgs(GpuModel* gpu_model) {
  class DummySpatialTensor : public GpuSpatialTensor {
   public:
    DummySpatialTensor() = default;
    explicit DummySpatialTensor(const BHWDC& shape,
                                const TensorDescriptor& tensor_desc)
        : shape_(shape), tensor_desc_(tensor_desc) {}
    ~DummySpatialTensor() override = default;
    int Width() const override { return shape_.w; }
    int Height() const override { return shape_.h; }
    int Depth() const override { return shape_.d; }
    int Channels() const override { return shape_.c; }
    int Slices() const override { return DivideRoundUp(shape_.c, 4); }
    int Batch() const override { return shape_.b; }
    TensorDescriptor GetDescriptor() const override { return tensor_desc_; }
   private:
    BHWDC shape_;
    TensorDescriptor tensor_desc_;
  };
  for (auto& node : gpu_model->nodes) {
    std::vector<DummySpatialTensor> src_tensors(node.inputs.size());
    for (int i = 0; i < node.inputs.size(); ++i) {
      const auto& tensor_desc = gpu_model->tensors[node.inputs[i]];
      src_tensors[i] =
          DummySpatialTensor(tensor_desc.GetBHWDCShape(), tensor_desc);
      node.gpu_operation->SetSrc(&src_tensors[i], i);
    }
    std::vector<DummySpatialTensor> dst_tensors(node.outputs.size());
    for (int i = 0; i < node.outputs.size(); ++i) {
      const auto& tensor_desc = gpu_model->tensors[node.outputs[i]];
      dst_tensors[i] =
          DummySpatialTensor(tensor_desc.GetBHWDCShape(), tensor_desc);
      node.gpu_operation->SetDst(&dst_tensors[i], i);
    }
    RETURN_IF_ERROR(
        node.gpu_operation->BindArguments(&node.gpu_operation->args_));
    node.gpu_operation->RecalculateGridSize();
  }
  return absl::OkStatus();
}
absl :: Status ResolvePolymorphicArgs ( GpuModel * gpu_model ) { class DummySpatialTensor : public GpuSpatialTensor { public : DummySpatialTensor ( ) = default ; explicit DummySpatialTensor ( const BHWDC & shape , const TensorDescriptor & tensor_desc ) : shape_ ( shape ) , tensor_desc_ ( tensor_desc ) { } ~ DummySpatialTensor ( ) override = default ; int Width ( ) const override { return shape_ . w ; } int Height ( ) const override { return shape_ . h ; } int Depth ( ) const override { return shape_ . d ; } int Channels ( ) const override { return shape_ . c ; } int Slices ( ) const override { return DivideRoundUp ( shape_ . c , 4 ) ; } int Batch ( ) const override { return shape_ . b ; } TensorDescriptor GetDescriptor ( ) const override { return tensor_desc_ ; } private : BHWDC shape_ ; TensorDescriptor tensor_desc_ ; } ; for ( auto & node : gpu_model -> nodes ) { std :: vector < DummySpatialTensor > src_tensors ( node . inputs . size ( ) ) ; for ( int i = 0 ; i < node . inputs . size ( ) ; ++ i ) { const auto & tensor_desc = gpu_model -> tensors [ node . inputs [ i ] ] ; src_tensors [ i ] = DummySpatialTensor ( tensor_desc . GetBHWDCShape ( ) , tensor_desc ) ; node . gpu_operation -> SetSrc ( & src_tensors [ i ] , i ) ; } std :: vector < DummySpatialTensor > dst_tensors ( node . outputs . size ( ) ) ; for ( int i = 0 ; i < node . outputs . size ( ) ; ++ i ) { const auto & tensor_desc = gpu_model -> tensors [ node . outputs [ i ] ] ; dst_tensors [ i ] = DummySpatialTensor ( tensor_desc . GetBHWDCShape ( ) , tensor_desc ) ; node . gpu_operation -> SetDst ( & dst_tensors [ i ] , i ) ; } RETURN_IF_ERROR ( node . gpu_operation -> BindArguments ( & node . gpu_operation -> args_ ) ) ; node . gpu_operation -> RecalculateGridSize ( ) ; } return absl :: OkStatus ( ) ; }
Serialized model will lose polymorphic properties for GpuOperations.
Serialized model will lose polymorphic properties for GpuOperations .