infershape_launchers_test.cc 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// 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.

#include <gtest/gtest.h>

17 18 19
#include "paddle/infrt/kernel/pten/infershaped/infershaped_kernel_launcher.h"
#include "paddle/infrt/kernel/pten/infershaped/infershaped_kernel_launchers.h"
#include "paddle/infrt/kernel/pten/infershaped/infershaped_utils.h"
20 21

namespace infrt {
22
namespace kernel {
23

24
namespace {
25 26 27
static void ElementwiseAddTest(const ::pten::DenseTensor& a,
                               const ::pten::DenseTensor& b,
                               ::pten::DenseTensor* c);
28 29 30 31 32 33 34 35
}

TEST(utils, registry) {
  constexpr uint8_t count =
      InferShapeHelper<decltype(&ElementwiseAddTest)>::count;
  CHECK_EQ(count, 2U);
}

36 37
TEST(ElementwiseAdd, launcher_registry) {
  host_context::KernelRegistry registry;
38 39 40 41
  RegisterInferShapeLaunchers(&registry);
  ASSERT_EQ(registry.size(), 1UL);
  auto creator = registry.GetKernel("elementwise_add");

42 43 44 45
  ::pten::CPUContext ctx{};
  ::pten::DenseTensor a{};
  ::pten::DenseTensor b{};
  ::pten::DenseTensor c{};
46 47

  host_context::KernelFrameBuilder kernel_frame_builder;
48
  kernel_frame_builder.AddArgument(new host_context::Value(std::move(ctx)));
49 50 51
  kernel_frame_builder.AddArgument(new host_context::Value(std::move(a)));
  kernel_frame_builder.AddArgument(new host_context::Value(std::move(b)));
  kernel_frame_builder.SetResults({new host_context::Value(std::move(c))});
52
  creator(&kernel_frame_builder);
53 54
}

55
}  // namespace kernel
56
}  // namespace infrt