using namespace nnfw::kernel::acl;
TEST(KernelACL_TC, fcFloat32_1) {
- const android::nn::Shape inputShape = {OperandType::FLOAT32, {1, 1, 1, 100}, 1.0, 0};
- float inputData[100];
- const android::nn::Shape weightsShape = {OperandType::FLOAT32, {1, 1, 100, 1}, 1.0, 0};
- float weightsData[100];
-
- const android::nn::Shape biasShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0};
- float biasData[1];
-
- const android::nn::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 };
- float outputData[1];
+ util::TensorWrapper input({1,1,1,100});
+ util::TensorWrapper weights({1,1,100,1});
+ util::TensorWrapper bias({1,1,1,1});
+ util::TensorWrapper output({1,1,1,1});
int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
- util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0);
- util::initData(weightsData, sizeof(weightsData) / sizeof(weightsData[0]), 1.0);
- util::initData(biasData, sizeof(biasData) / sizeof(biasData[0]), 0.0);
- util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0);
-
- bool bret = fullyConnectedFloat32(inputData, inputShape,
- weightsData, weightsShape,
- biasData, biasShape,
+ input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 1.f;
+ });
+ weights.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 1.f;
+ });
+ bias.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 0.f;
+ });
+ output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 0.f;
+ });
+
+ bool bret = fullyConnectedFloat32(input.ptr<float>(), input.shape(),
+ weights.ptr<float>(), weights.shape(),
+ bias.ptr<float>(), bias.shape(),
activation,
- outputData, outputShape);
+ output.ptr<float>(), output.shape());
EXPECT_EQ(bret, true);
- float expectData[] = {
- 100.0f
- };
- bret = util::compareData(outputData, expectData, outputShape);
- EXPECT_EQ(bret, true);
+ util::TensorWrapper expected({1,1,1,1});
+ expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 100.f;
+ });
+ EXPECT_EQ(output, expected);
}
TEST(KernelACL_TC, fcFloat32_relu) {
- const android::nn::Shape inputShape = {OperandType::FLOAT32, {1, 1, 1, 100}, 1.0, 0};
- float inputData[100];
-
- const android::nn::Shape weightsShape = {OperandType::FLOAT32, {1, 1, 100, 1}, 1.0, 0};
- float weightsData[100];
- const android::nn::Shape biasShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0};
- float biasData[1];
+ util::TensorWrapper input({1,1,1,100});
+ util::TensorWrapper weights({1,1,100,1});
+ util::TensorWrapper bias({1,1,1,1});
+ util::TensorWrapper output({1,1,1,1});
- const android::nn::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 };
- float outputData[1];
-
- int32_t activation = ANEURALNETWORKS_FUSED_RELU;
-
- util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0);
- util::initData(weightsData, sizeof(weightsData) / sizeof(weightsData[0]), -1.0);
- util::initData(biasData, sizeof(biasData) / sizeof(biasData[0]), 0.0);
- util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0);
+ int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
- bool bret = fullyConnectedFloat32(inputData, inputShape,
- weightsData, weightsShape,
- biasData, biasShape,
+ input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 1.f;
+ });
+ weights.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return -1.f;
+ });
+ bias.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 0.f;
+ });
+ output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 0.f;
+ });
+
+ bool bret = fullyConnectedFloat32(input.ptr<float>(), input.shape(),
+ weights.ptr<float>(), weights.shape(),
+ bias.ptr<float>(), bias.shape(),
activation,
- outputData, outputShape);
+ output.ptr<float>(), output.shape());
EXPECT_EQ(bret, true);
- float expectData[] = {
- 0.0f
- };
- bret = util::compareData(outputData, expectData, outputShape);
- EXPECT_EQ(bret, true);
+ util::TensorWrapper expected({1,1,1,1});
+ expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ return 0.f;
+ });
+ EXPECT_EQ(output, expected);
}