LCOV - code coverage report
Current view: top level - xenolith/utils/shadernn/tests - XLSnnGenTest.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 50 0.0 %
Date: 2024-05-06 04:51:23 Functions: 0 11 0.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLSnnGenTest.h"
      24             : #include "XLCoreFrameQueue.h"
      25             : #include "XLCoreFrameRequest.h"
      26             : #include "XLVkLoop.h"
      27             : #include "XLApplication.h"
      28             : #include "SPBitmap.h"
      29             : 
      30             : namespace stappler::xenolith::vk::shadernn {
      31             : 
      32           0 : GenQueue::~GenQueue() { }
      33             : 
      34           0 : bool GenQueue::init() {
      35             :         using namespace core;
      36           0 :         Queue::Builder builder("Gen");
      37             : 
      38           0 :         auto imageAttachment = builder.addAttachemnt("OutputAttachment",
      39           0 :                         [&] (AttachmentBuilder &attachmentBuilder) -> Rc<Attachment> {
      40           0 :                 attachmentBuilder.defineAsOutput();
      41           0 :                 return Rc<vk::ImageAttachment>::create(attachmentBuilder,
      42           0 :                         ImageInfo(Extent3(16, 16, 16),
      43           0 :                                         ImageUsage::Storage | ImageUsage::TransferSrc,
      44           0 :                                         ImageTiling::Optimal, ImageFormat::R16G16B16A16_SFLOAT),
      45           0 :                         ImageAttachment::AttachmentInfo{
      46             :                                 .initialLayout = AttachmentLayout::General,
      47             :                                 .finalLayout = AttachmentLayout::General,
      48             :                                 .clearOnLoad = true,
      49             :                                 .clearColor = Color4F(0.0f, 0.0f, 0.0f, 0.0f)}
      50           0 :                 );
      51           0 :         });
      52             : 
      53           0 :         _genLayer = builder.addPass("GenLayer", PassType::Compute, RenderOrdering(0),
      54           0 :                         [&] (QueuePassBuilder &passBuilder) -> Rc<core::QueuePass> {
      55           0 :                 return Rc<GenerationLayer>::create(builder, passBuilder, imageAttachment);
      56             :         });
      57             : 
      58           0 :         _activationLayer = builder.addPass("ActivationLayer", PassType::Compute, RenderOrdering(1),
      59           0 :                         [&] (QueuePassBuilder &passBuilder) -> Rc<core::QueuePass> {
      60           0 :                 return Rc<ActivationLayer>::create(builder, passBuilder, imageAttachment, imageAttachment);
      61             :         });
      62             : 
      63           0 :         if (core::Queue::init(move(builder))) {
      64           0 :                 _imageAttachment = imageAttachment;
      65           0 :                 return true;
      66             :         }
      67           0 :         return false;
      68           0 : }
      69             : 
      70           0 : const core::AttachmentData *GenQueue::getGenDataAttachment() const {
      71           0 :         return static_cast<GenerationLayer *>(_genLayer->pass.get())->getDataAttachment();
      72             : }
      73             : 
      74           0 : const core::AttachmentData *GenQueue::getActivationDataAttachment() const {
      75           0 :         return static_cast<ActivationLayer *>(_activationLayer->pass.get())->getDataAttachment();
      76             : }
      77             : 
      78           0 : void GenQueue::run(Application *app, Extent3 e) {
      79           0 :         auto req = Rc<core::FrameRequest>::create(Rc<core::Queue>(this), core::FrameContraints{e});
      80             : 
      81           0 :         auto genInputData = Rc<GenerationDataInput>::alloc();
      82           0 :         genInputData->data = GenerationData{UVec3{0, 0, 0}, maxOf<uint16_t>(), -1.2f, 1.2f};
      83             : 
      84           0 :         req->addInput(getGenDataAttachment(), move(genInputData));
      85             : 
      86           0 :         auto activationInputData = Rc<ActivationDataInput>::alloc();
      87           0 :         activationInputData->data = ActivationData{UVec4{e.width, e.height, e.depth, 1}, Activation::SILU, -5.0f};
      88             : 
      89           0 :         req->addInput(getActivationDataAttachment(), move(activationInputData));
      90             : 
      91           0 :         req->setOutput(getImageAttachment(), [app] (core::FrameAttachmentData &data, bool success, Ref *) {
      92           0 :                 app->getGlLoop()->captureImage([app] (core::ImageInfoData info, BytesView view) {
      93           0 :                         if (!view.empty()) {
      94           0 :                                 for (size_t i = 0; i < info.extent.width; ++ i) {
      95           0 :                                         for (size_t i = 0; i < info.extent.height; ++ i) {
      96           0 :                                                 for (size_t i = 0; i < info.extent.depth; ++ i) {
      97           0 :                                                         std::cout << " " << view.readFloat16();
      98             :                                                 }
      99           0 :                                                 std::cout << "\n";
     100             :                                         }
     101           0 :                                         std::cout << "\n";
     102             :                                 }
     103             :                         }
     104           0 :                         app->end();
     105           0 :                 }, data.image->getImage(), core::AttachmentLayout::General);
     106           0 :                 return true;
     107             :         });
     108             : 
     109           0 :         app->getGlLoop()->runRenderQueue(move(req), 0);
     110           0 : }
     111             : 
     112             : }

Generated by: LCOV version 1.14