Exceptions using createcomputeshader

Started by
6 comments, last by Pink Horror 10 years, 6 months ago

Hi guys,

I am working in Visual Studio 2012 and I need to create a computeshader, which is with its 250 lines quite big, so i decided to precreate it with the inbuild HLSL compiler by generating a header file. The compiler didnt complained at all and the binary Array just got created, but if i want to bind the data to a shader object uisng the line:


device->CreateComputeShader(backpropshader, sizeof(backpropshader), NULL, &berechner);

backpropshader being the binary buffer in the header file, the Application raises an acess violation Exception. Does anyone know how this Exception could arise?

I am also concerned about the binary array to be 23 thousand lines long, is that normal?

the Shader is suposed to use the Backpropagation algorithm on several neuronal systems parallely:

This is the Shader reduced to a few lines, I hope its understandable though many of the variablenames are german.


cbuffer konstanten : register(b0)
{
    uint systemcount;

    uint neuronencount;
    uint ausgaenge; 
    uint eingaenge;
    uint vorgabensegment;
    uint vorgabencount;

    uint aufgabencount;


    uint lernschritte;
    uint lernstaerke;
};
struct Verbindung
{
    uint start;
    uint ende;
    float gewicht;
};
struct neurondaten
{
    float eingabe;
    float ausgabe;
    uint transfermodus;
    float fehler;
};

StructuredBuffer<float> Vorgabentemplate : register(u0);

RWStructuredBuffer<Verbindung> Verbindungen : register(u1);
RWStructuredBuffer<neurondaten> Neurone : register(u2);


void PROPAGATE(uint basisvorgabe, uint basisneuron, uint basisverbindung, uint endverbindung) 
{
    Neurone[basisneuron].ausgabe = 1.0f; //Biasneuron gleich setzen
    for (unsigned int einschreib1 = 1; einschreib1 < eingaenge; einschreib1++)
    {
        Neurone[basisneuron + einschreib1].ausgabe = Vorgabentemplate[basisvorgabe + einschreib1 - 1];
    }
    for (unsigned int einschreib2 = 1 + eingaenge; einschreib2 < neuronencount; einschreib2++)
    {
        Neurone[basisneuron + einschreib2].eingabe = 0;
        Neurone[basisneuron + einschreib2].fehler = 0;
    }
    //Neurone sind im Grundzustand

    for (unsigned int i = basisverbindung; i < endverbindung; i++)
    {
        if (Verbindungen[i].start == Verbindungen[i].ende)
        {
            switch (Neurone[Verbindungen[i].start].transfermodus)
            {
                 ....................
            }

        }
        else
        {
            Neurone[Verbindungen[i].ende].eingabe += Neurone[Verbindungen[i].start].ausgabe * Verbindungen[i].gewicht;
        }
    }
}


[numthreads(128, 1, 1)]
void BACKPROPAGATE( uint ID : SV_DispatchThreadID  )
{
    if (ID < systemcount)
    {
        float restfehler = 0;
        uint basisneuron = neuronencount * ID;
        uint basisverbindung = aufgabencount * ID;
        uint endbasisverbindung = aufgabencount * (ID + 1);
        for (unsigned int durchgang = 0; durchgang < lernschritte; durchgang++)
        {
            restfehler = 0;
            uint basisvorgabe = 0;
            for (unsigned int vorgabenzaehler = 0; vorgabenzaehler < vorgabencount; vorgabenzaehler++)
            {
                PROPAGATE(basisvorgabe,basisneuron,basisverbindung, endbasisverbindung);
                for (unsigned int fehlerstart = neuronencount - ausgaenge; fehlerstart < neuronencount; fehlerstart++)
                {
                    Neurone[basisneuron + fehlerstart].fehler = Neurone[basisneuron + fehlerstart].eingabe - Vorgabentemplate[basisvorgabe + eingaenge];
                    restfehler += Neurone[basisneuron + fehlerstart].fehler * Neurone[basisneuron + fehlerstart].fehler;
                }
               
                for (unsigned int i = endbasisverbindung - 1; i-- > basisverbindung;)
                {
                    if (Verbindungen[i].start == Verbindungen[i].ende) //refreshe den fehler
                    {
                        switch (Neurone[Verbindungen[i].start].transfermodus)
                        {
                            ..........
                        }

                    }
                    else
                    {
                        Verbindungen[i].gewicht -= lernschritte * Neurone[Verbindungen[i].ende].fehler * Neurone[Verbindungen[i].start].ausgabe;
                        Neurone[Verbindungen[i].start].fehler += Neurone[Verbindungen[i].ende].fehler * Verbindungen[i].gewicht;
                    }
                }
                basisvorgabe += vorgabensegment;
            }
        }
      

    }
}


Advertisement

Can you give the definition of backpropshader and how you initialize it? Normally you don't use sizeof nor feed a raw pointer to the CreateComputeShader method, generally you are returned a compiled binary blob which contains the shader binary and its size (among other metadata) and use GetBufferPointer() and GetBufferSize() to pass the correct values to this method. Also, I think it's not unusual for compiled shaders to be several kilobytes large, if the compiler is doing optimizations it may unroll loops inside the shader.to improve performance.

By the way, if backpropshader is not a fixed size array then sizeof is not doing what you think it is doing.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

I added the shader definition. I thought the Array would be fixed size, since its getting written into the header file while compiling the project, its definition is


const BYTE backpropshader[] =
{
...... tons of code......
}

so I thought I could just use its size to feed the function, relying on the msdn:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509633%28v=vs.85%29.aspx#compiling_at_build_time_to_header_files

I thought the blob method would only be used when creating the shader at runtime using compileshaderfromfile for example?

I think you are correct about that, my mistake. Does the debug layer return anything? Have you tried with a much simpler compute shader and getting the same error?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Unluckily even when everything except the naked function body is commented i get the same results (the compiled length decreased so I guess its updating the file), even though the array is still pretty large with 1000 lines of code, while everything thats left is:


[numthreads(128, 1, 1)]
void BACKPROPAGATE( uint ID : SV_DispatchThreadID  )
{

}

There are no erros or warnings being displayed about the shader file.

But I have extremly many warnings about makro redefinitions in the context of directx(80) which could eventually aflict that case (I have those warnings since I exported my project from visual c++ 2010 to visual studio 2012). I dont really knwo why.

Well, I have no proof that device or berechner are valid, so I blame one of them.

It would be nice to know what your callstack and the full text of the exception look like. Those will have more clues.

Thank you very much, I didn´t even validated the device pointer, as I knew my other Shaders compiled fine with the device. I unluckily forgot there to be another device declared inside the class overwriting the definition of the one outside the scope of the class. The devicepointer was not assigned to that one yet and was a zero pointer...

Thank you very much for that hint, now I feel really bad having bothered you two with this laughable problem huh.png .

Besides from that, does anyone has a clue why I end up getting those redefinition warnings after transfering visual c++ 2010 projects to visual studio 2012?


Besides from that, does anyone has a clue why I end up getting those redefinition warnings after transfering visual c++ 2010 projects to visual studio 2012?

I'd need more information to help with this.

This topic is closed to new replies.

Advertisement