|
| 1 | +/** |
| 2 | + * Copyright (c) 2017-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#pragma once |
| 17 | + |
| 18 | +#include <string> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include <ATen/ATen.h> |
| 22 | +#include <ATen/DLConvertor.h> |
| 23 | + |
| 24 | +#include "tc/core/tensor.h" |
| 25 | + |
| 26 | +namespace tc { |
| 27 | +namespace aten { |
| 28 | +inline std::vector<DLTensorUPtr> makeDLTensors( |
| 29 | + const std::vector<at::Tensor>& tensors) { |
| 30 | + std::vector<DLTensorUPtr> dlTensors; |
| 31 | + for (auto tensor : tensors) { |
| 32 | + auto dlMTensor = at::toDLPack(tensor); |
| 33 | + dlTensors.push_back(makeDLTensor(&(dlMTensor->dl_tensor))); |
| 34 | + dlMTensor->deleter(dlMTensor); |
| 35 | + } |
| 36 | + return dlTensors; |
| 37 | +} |
| 38 | + |
| 39 | +inline std::vector<DLConstTensorUPtr> makeDLConstTensors( |
| 40 | + const std::vector<at::Tensor>& tensors) { |
| 41 | + std::vector<DLConstTensorUPtr> dlTensors; |
| 42 | + for (auto tensor : tensors) { |
| 43 | + auto dlMTensor = at::toDLPack(tensor); |
| 44 | + dlTensors.push_back(makeDLConstTensor(&(dlMTensor->dl_tensor))); |
| 45 | + dlMTensor->deleter(dlMTensor); |
| 46 | + } |
| 47 | + return dlTensors; |
| 48 | +} |
| 49 | +} // namespace aten |
| 50 | +} // namespace tc |
0 commit comments