Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Exceptions using createcomputeshader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 06 October 2013 - 05:48 PM

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;
            }
        }
      

    }
}


 


Edited by directx user, 06 October 2013 - 05:59 PM.


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9299

Like
0Likes
Like

Posted 06 October 2013 - 06:00 PM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 06 October 2013 - 06:08 PM

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?



#4 Bacterius   Crossbones+   -  Reputation: 9299

Like
0Likes
Like

Posted 06 October 2013 - 06:29 PM

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?


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 06 October 2013 - 06:57 PM

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.


Edited by directx user, 06 October 2013 - 06:58 PM.


#6 Pink Horror   Members   -  Reputation: 1232

Like
0Likes
Like

Posted 06 October 2013 - 08:18 PM

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.



#7 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 07 October 2013 - 10:44 AM

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?


Edited by directx user, 07 October 2013 - 03:41 PM.


#8 Pink Horror   Members   -  Reputation: 1232

Like
0Likes
Like

Posted 08 October 2013 - 07:25 PM


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS