ASSERT_EQ(allocated_span.size(), retrieved_span.size());
}
}
-
-TEST(IR_DATA, allocate_and_link_kernel)
-{
- using nncc::core::ADT::kernel::num_elements;
-
- // Create a kernel object
- auto module = coco::Module::create();
-
- const nncc::core::ADT::kernel::Shape shape{1, 1, 3, 3};
- auto bag = module->entity()->bag()->create(9);
- auto obj = module->entity()->object()->create<coco::KernelObject>();
-
- obj->bag(bag);
- obj->layout(coco::KernelLayouts::NHWC::create(shape));
-
- auto data = coco::Data::create();
-
- // weight(...) SHOULD return a null-span for an invalid bag
- {
- auto span = data->f32()->weight(bag);
-
- ASSERT_EQ(span.data(), nullptr);
- ASSERT_EQ(span.size(), 0);
- }
-
- // Create a blob and link it with kernel object
- data->f32()->allocate(obj);
-
- // weight(...) SHOULD return a valid for a valid bag
- {
- auto span = data->f32()->weight(bag);
-
- ASSERT_NE(span.data(), nullptr);
- ASSERT_EQ(span.size(), bag->size());
- }
-
- auto reader = data->f32()->read(obj);
- auto accessor = data->f32()->access(obj);
-
- ASSERT_TRUE(data->allocated(bag));
-
- static nncc::core::ADT::kernel::NCHWLayout l{};
-
- // Check wheter blob is zero-initialized, and updates its value
- for (uint32_t n = 0; n < shape.count(); ++n)
- {
- for (uint32_t ch = 0; ch < shape.depth(); ++ch)
- {
- for (uint32_t row = 0; row < shape.height(); ++row)
- {
- for (uint32_t col = 0; col < shape.width(); ++col)
- {
- EXPECT_FLOAT_EQ(reader->at(n, ch, row, col), 0.0f);
- accessor->at(n, ch, row, col) = l.offset(shape, n, ch, row, col);
- }
- }
- }
- }
-
- // Check wheter accessor behaves as expected
- for (uint32_t n = 0; n < shape.count(); ++n)
- {
- for (uint32_t ch = 0; ch < shape.depth(); ++ch)
- {
- for (uint32_t row = 0; row < shape.height(); ++row)
- {
- for (uint32_t col = 0; col < shape.width(); ++col)
- {
- EXPECT_FLOAT_EQ(reader->at(n, ch, row, col), l.offset(shape, n, ch, row, col));
- }
- }
- }
- }
-
- data->release(bag);
- ASSERT_FALSE(data->allocated(bag));
-}