cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

thesquiff
Journeyman III

CAL can't launch kernel

Hi

I'm taking my first dive into CAL but am running into trouble. This will probably be trivial for someone to spot, but I can't work out what I'm doing wrong.

I have a very simple Brook+ kernel which I have compiled with brcc. I've then taken the IL code directly and used it unmodified.

When I run the program, the kernel doesn't execute and I get the error message: There was a problem running the program Error Code 1. The error string is Symbol "

...and the error string is cut short like that.

 

This error is coming from within RunProgram function from Samples.cpp.

 

Any ideas? The error is very vague for a beginner! Thanks in advance.

 


kernel void simpleMap(int g_idata[], out int g_odata<> {
    int idx = instance().x;
    //int idy = instance().y;
    g_odata = g_idata[idx];
}


 

// Device specific parameters
    unsigned int deviceNum  = 0;
    CALcontext ctx          = 0;
    CALdevice  device       = 0;   
    int numInputs = 1;
    int numOutputs = 1;
    int numConstantBuffers = 1;
    Data* data = NULL;
    CALresult r;


    printf("INITIALISING...\n");
    Initialize(&device, &ctx, deviceNum );

    //////////////////////////////////////////////////////////////////////////
    //
    //  Setup shader phase
    //
    //  Compile, Link and load the shader into a CALmodule.
    CALmodule stringMatchModule = 0;
    printf("LOADING AND COMPILING KERNEL...\n");
    if (!SetupKernel((CALchar*)stringMatchIL, &stringMatchModule, &ctx))
    {
        return 1;
    }

    //////////////////////////////////////////////////////////////////////////
    //
    //  Setup user data phase
    //
    //  Initialize CALresource's and CALmem handles,
    //  Map data into the respective memory handles
    //  and set up the context from the resources.
    printf("SETTING UP USER DATA SPACE...\n");  
    CALresource textRes  = 0;
    r = calResAllocLocal1D(&textRes, device, 512, CAL_FORMAT_INT_1, 0);
    calAssert(r, "There has been an error allocating resource.");
    // Mapping input resource to CPU
    // Returns 'fdata' as a CPU accessible pointer to resource 'inputRes'   
    // Filling values in input buffer
    int* textPtr     = NULL;
    CALuint inputPitch  = 0;   
    r = calResMap((CALvoid**)&textPtr, &inputPitch, textRes, 0);
    calAssert(r, "There has been an error mapping resource.");
    printf("Input pitch %d\n", inputPitch);

    for (int y = 0; y < 512; y++) {
        textPtr = y;
    }


    r = calResUnmap(textRes);
    calAssert(r, "There has been an error unmapping resource."); 

   
    //allocate space for result

    // Mapping output resource to CPU and initializing values
    printf("ALLOCATING OUTPUT SPACE...\n");
    CALresource outputRes  = 0;
    void* outputPtr = NULL;
    unsigned int outputPitch = 0;
    r = calResAllocLocal1D(&outputRes, device, 512, CAL_FORMAT_INT_1, 0);
    r = calResMap(&outputPtr, &outputPitch, outputRes, 0);
   
    calAssert(r, "There has been an error mapping resource.");
    printf("Output pitch %d\n", outputPitch);
   
    memset(outputPtr, 0, 512);

    r = calResUnmap(outputRes);
    calAssert(r, "There has been an error unmapping resource.");


    //getting memory handles to resources

    calAssert(r, "There was an error getting memory handle.");
    r = calCtxGetMem((CALmem*)&textPtr, ctx, textRes);
    calAssert(r, "There was an error getting memory handle.");


    r = calCtxGetMem((CALmem*)&outputPtr, ctx, outputRes);
    calAssert(r, "There was an error getting memory handle.");


    printf("BINDING IO\n");

    CALname textInputName = 0;
    CALname outputName = 0;

    
    r = calModuleGetName(&textInputName, ctx, stringMatchModule, "i0");
    calAssert(r, "There was an error obtaining input name handle. (textInputName)");
   
    r = calModuleGetName(&outputName, ctx, stringMatchModule, "o0");
    calAssert(r, "There was an error obtaining output name handle. (outputName)");

    CALmem textMem = 0;
    CALmem hashTableMem = 0;
    CALmem hashChainMem = 0;
    CALmem outputMem = 0;

    r = calCtxSetMem(ctx, textInputName, textMem);
    calAssert(r, "There was an error binding resource. textRes");


    r = calCtxSetMem(ctx, outputName, outputMem);
    calAssert(r, "There was an error binding resource. outputRes");

    //////////////////////////////////////////////////////////////////////////
    //
    //  Execution phase
    //
    //  Run the program for give Iterations and collect statistics
    //  main is the entry point into the shader program.
    double elapsedTime = 0;
    SampleInfo Info;
    if(!RunProgram(&ctx, &stringMatchModule, 512, 1, &Info))
    {
        return 1;
    }

0 Likes
4 Replies
gaurav_garg
Adept I

Could you make sure you are using non-address translated version of this kernel? AT version requires some constants to be bound on runtime side.

0 Likes

Yes, I think I am. There are two IL kernels generated, one suffixed with 0, one suffixed with 1. I'm using the 0 suffix one:

 

const char stringMatchIL[] = "il_ps_2_0\n"
        "dcl_literal l0,0x00000000,0x00000000,0x00000000,0x00000000\n"
        "dcl_literal l1,0x00000001,0x00000001,0x00000001,0x00000001\n"
        "dcl_literal l2,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF\n"
        "dcl_literal l3,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF\n"
        "dcl_literal l4,0x7F800000,0x7F800000,0x7F800000,0x7F800000\n"
        "dcl_literal l5,0x80000000,0x80000000,0x80000000,0x80000000\n"
        "dcl_literal l6,0x3E9A209B,0x3E9A209B,0x3E9A209B,0x3E9A209B\n"
        "dcl_literal l7,0x3F317218,0x3F317218,0x3F317218,0x3F317218\n"
        "dcl_literal l8,0x40490FDB,0x40490FDB,0x40490FDB,0x40490FDB\n"
        "dcl_literal l9,0x3FC90FDB,0x3FC90FDB,0x3FC90FDB,0x3FC90FDB\n"
        "dcl_literal l10,0x00000003,0x00000003,0x00000003,0x00000003\n"
        "dcl_literal l11,0x00000002,0x00000002,0x00000002,0x00000002\n"
        "dcl_output_usage(generic) o0.xyzw\n"
        "dcl_resource_id(0)_type(2d,unnorm)_fmtx(float)_fmty(float)_fmtz(float)_fmtw(float)\n"
        "dcl_input_position_interp(linear_noperspective) v0.xy__\n"
        "dcl_literal l12,0x3F000000,0x3F000000,0x3F000000,0x3F000000\n"
        "mov r275.xy__,v0.xyzw\n"
        "call 38 \n"
        "call 0 \n"
        "endmain\n"
        "\n"
        "func 0\n"
        "mov o0.xyzw,r274.xyzw\n"
        "ret\n"
        "\n"
        "func 20\n"
        "ieq r0.x___,r144.x000,l0.x000\n"
        "if_logicalnz r0.x000\n"
        "sample_resource(0)_sampler(0) r146.xyzw,r145.xy00\n"
        "endif\n"
        "mov r147.x___,r146.x000\n"
        "mov r143.x___,r147.x000\n"
        "ret_dyn\n"
        "ret\n"
        "\n"
        "func 37\n"
        "mov r272.x___,r271.x000\n"
        "itof r284.x___,r272.x000\n"
        "mov r273.x___,r284.x000\n"
        "mov r273._y__,l0.0x00\n"
        "mov r144.x___,r269.x000\n"
        "mov r145.xy__,r273.xy00\n"
        "call 20 \n"
        "mov r285.x___,r143.x000\n"
        "mov r270.x___,r285.x000\n"
        "ret\n"
        "\n"
        "func 38\n"
        "mov r279.x___,l12.x000\n"
        "mov r279._y__,l12.0x00\n"
        "sub r280.xy__,r275.xy00,r279.xy00\n"
        "mov r286.xyzw,r280.xy00\n"
        "mov r278.xyzw,r286.xyzw\n"
        "mov r269.x___,l0.x000\n"
        "ftoi r287.xyzw,r278.xyzw\n"
        "mov r271.xyzw,r287.xyzw\n"
        "call 37 \n"
        "mov r277.x___,r270.x000\n"
        "mov r281.x___,r277.x000\n"
        "mov r282.x___,r281.x000\n"
        "mov r282._y__,l0.0x00\n"
        "mov r282.__z_,l0.00x0\n"
        "mov r282.___w,l0.000x\n"
        "mov r276.xyzw,r282.xyzw\n"
        "mov r274.xyzw,r276.xyzw\n"
        "ret_dyn\n"
        "ret\n"
        "\n"
        "end\n"
        "";

0 Likes
gaurav_garg
Adept I

hmmm... I got it....you are binding symbol handles with NULL memory handles.

r = calCtxGetMem((CALmem*)&textPtr, ctx, textRes);     calAssert(r, "There was an error getting memory handle.");

 

    r = calCtxGetMem((CALmem*)&outputPtr, ctx, outputRes);     calAssert(r, "There was an error getting memory handle.");    

CALmem textMem = 0;     CALmem hashTableMem = 0;     CALmem hashChainMem = 0;     CALmem outputMem = 0;     r = calCtxSetMem(ctx, textInputName, textMem);     calAssert(r, "There was an error binding resource. textRes");     r = calCtxSetMem(ctx, outputName, outputMem);     calAssert(r, "There was an error binding resource. outputRes");



It should be -

CALmem textMem = 0;     CALmem hashTableMem = 0;     CALmem hashChainMem = 0;     CALmem outputMem = 0;

r = calCtxGetMem((CALmem*)&textMem, ctx, textRes);     calAssert(r, "There was an error getting memory handle.");

    r = calCtxGetMem((CALmem*)&outputMem, ctx, outputRes);     calAssert(r, "There was an error getting memory handle.");

r = calCtxSetMem(ctx, textInputName, textMem);     calAssert(r, "There was an error binding resource. textRes");     r = calCtxSetMem(ctx, outputName, outputMem);     calAssert(r, "There was an error binding resource. outputRes");

0 Likes

I knew it had to be something simple. Thank you so much for your help.

0 Likes