halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.77k stars 1.07k forks source link

"Internal Error Generator.cpp:1761 triggered by user code at : Condition failed: exprs_.size() == array_size() && funcs_.empty #8283

Closed phengxu closed 1 week ago

phengxu commented 3 weeks ago

After build my generator of halide, and then run in command and found internal error like:

0x000001d4d85809f0 "Internal Error at D:\surround360\vcpkg\buildtrees\halide\src\v17.0.1-ba7e30d7b4.clean\src\Generator.cpp:1761 triggered by user code at : Condition failed: exprs_.size() == arraysize() && funcs.empty... std::basic_stringbuf<char,std::char_traits,std::allocator>

I install halide version 17.0.1 by vcpkg on windows 11 and use Aot compile mode for an isp processor, the halide code is about looks below code snippet:

#include "Halide.h"
#include <gflags/gflags.h>
#include <iostream>

DEFINE_int32(output_bpp, 8,  "output image bits per pixel, either 8 or 16");

using namespace std;
using namespace Halide;

class CameraIspGen : public Halide::Generator<CameraIspGen>{ 
 public:
  Var x, y, c, yi, yo;
  Func toneCorrected;
  // Declare the configuration parameters for output variants code
  GeneratorParam<int> outputBpp{"outputBpp", 8};
  GeneratorParam<bool> Fast{"Fast", false};
  // Declare the input parameters since version 10 above as public memebers
  Input<Buffer<uint16_t, 2>> input{"input"};
  //some input here define。。。。

  Input<float> sharpeningR{"sharpeningR"};
  Input<float> sharpeningG{"sharpeningG"};
  Input<float> sharpeningB{"sharpeningB"};

  //..
  Output<Buffer<uint16_t, 3>> ispOutput{"ispOutput"};
  // Func ispOutput;
  // set from main configuration
  void setParams(bool fast, int outputBpp) {
          Fast.set(fast);
          this->outputBpp.set(outputBpp);
      }

  //some algorithm Func intermediate hree
  //...
  Func toneCorrected() {
    //some algorithm here ..
    // schedule ...
    return toneCorrected;
  }
  Func applyUnsharpMask() {
    Func sharpened;
    if (outputBpp == 8) {
      sharpened(x, y, c) = ...;
    } else {
      sharpened(x, y, c) = ...;
    }
    //some algorithm here ..
    // schedule ...

    return sharpened;
  }

 void generate() { // in version 17 halide use generate
    // get current architecture target
    target = get_target();

    Expr sR = 1.0f + cast<float>(sharpeningR);
    Expr sG = 1.0f + cast<float>(sharpeningG);
    Expr sB = 1.0f + cast<float>(sharpeningB);

    // isp pipeline func
    Func vignettingGain("vignettingGain");
    Func deinterleaved("deinterleaved");
    Func demosaiced_output("demosaiced");
    Func colorCorrected("ccm");
    Func sharpened("sharpened");

    // some algorithm here for combine my pipeline here.../

  if (Fast) {
      ispOutput(x, y, c) = toneCorrected(x , y, cp);
    } else {
      ispOutput = applyUnsharpMask(toneCorrected, ... outputBpp);
    }

    // Schedule the pipeline
    // some shecdule code here
  }
   CameraIspGen() { }

  private:
    Target target;
};
// main entry for call to generate the pipeline
int main(int argc, char **argv) {
  gflags::ParseCommandLineFlags(&argc, &argv, true);
   Target target = get_target_from_environment();
  // Build variants of the pipeline
  CameraIspGen cameraIsp;
  CameraIspGen cameraIspFast;
  // Set fast and output bpp flags
  cameraIsp.setParams(false,FLAGS_output_bpp);
  cameraIspFast.setParams(true,FLAGS_output_bpp);

  // Generate the pipeline
  cameraIsp.generate();
  cameraIspFast.generate();
  return 0;
}

Is there any expert who can kindly give me some hints? what I trying do is transfer old version of halide to new version for this code base https://github.com/facebookarchive/Surround360/blob/master/surround360_render/source/camera_isp/CameraIspGen.cpp

abadams commented 3 weeks ago

When using a generator, don't write your own int main. I think yours is doing things in the wrong sequence (I get a different error when I try to repro using your code). Instead just compile the generator against GenGen.cpp. See apps/local_laplacian for an example of how a Halide generator should be structured, or see the generators tutorial at https://halide-lang.org/tutorials/tutorial_lesson_15_generators.html

phengxu commented 2 weeks ago

Thank you very much, I read the tutorial and these tutorial are greate and very helpful to me, but after update my code by the tutorial guid, I still encounter errors that is confused and very hard to me to figure out what wrong with my code, and I open a new issue at this link:https://github.com/halide/Halide/issues/8300Please Help me! Thanks.