InfiniTensor/test/kernels/bang/test_bang_prelu.cc

47 lines
1.4 KiB
C++

#include "bang/bang_runtime.h"
#include "core/graph.h"
#include "core/kernel.h"
#include "core/runtime.h"
#include "operators/unary.h"
#include "test.h"
namespace infini {
template <class T>
void testPRelu(const std::function<void(void *, size_t, DataType)> &generator,
const Shape &shape) {
// Runtime
Runtime cpuRuntime = NativeCpuRuntimeObj::getInstance();
auto bangRuntime = make_ref<BangRuntimeObj>();
// Build input data on CPU
Tensor inputCpu = make_ref<TensorObj>(shape, DataType::Float32, cpuRuntime);
Tensor alphaCpu =
make_ref<TensorObj>(Shape{1, 1, 1, 1}, DataType::Float32, cpuRuntime);
inputCpu->dataMalloc();
inputCpu->setData(generator);
alphaCpu->dataMalloc();
alphaCpu->setData(generator);
// GPU
Graph bangGraph = make_ref<GraphObj>(bangRuntime);
auto inputGpu = bangGraph->cloneTensor(inputCpu);
auto alphaGpu = bangGraph->cloneTensor(alphaCpu);
auto gpuOp = bangGraph->addOp<T>(inputGpu, alphaGpu, nullptr);
bangGraph->dataMalloc();
bangRuntime->run(bangGraph);
auto outputGpu = gpuOp->getOutput();
auto outputGpu2Cpu = outputGpu->clone(cpuRuntime);
inputCpu->printData();
alphaCpu->printData();
outputGpu2Cpu->printData();
EXPECT_TRUE(1);
}
TEST(cnnl_PRelu, run) {
testPRelu<PReluObj>(IncrementalGenerator(), Shape{1, 2, 2, 3});
}
} // namespace infini