14 Replies Latest reply on Mar 20, 2008 9:24 PM by michael.chu

    Brook+ Question to anyone

    ryta1203
      I have a question:

      Can iterators be declared within a kernel? Can iterators be declared dynamically. I had a problem where if I tried to declare an iterator inside a switch Brook+ wouldn't compile, but outside the switch (outside of everything) it compiled fine.

      Essentially, I have a large 3D array that I want to initialize to some incremental value, for instance:

      for (l.....)
      for (j.....)
      for (k....)
      array[l][j][k] = k;

      Is it possible to intialize the stream directly within a kernel?

      The docs on Brook+ (and Brook in general) are not really that in depth and even the sample code seems to be either really generic (simple) or too specific. If someone can point me in the right direction that would be great. Thanks.
        • Brook+ Question to anyone
          MicahVillmow
          ryta1203,
          If you look at the constant.br sample in the samples/tests directory, it shows you how to assign a value to every element of the stream. So, if you have a large 3d array, you could do something such as:
          kernel void writeKernel(out float stream<>, float k)
          {
          stream = k;
          }
          void main()
          {
          float array[sizeX][sizeY][sizeZ];
          float K = 30; // Or some arbitrary value
          int stream_size = sizeX * sizeY * sizeZ;
          {
          float stream<stream_size>;
          writeKernel(stream, K);
          streamWrite(stream, array);
          }
          ...
          }
          The writeKernel function calls the kernel code on the GPU which assigns the value K to every element of the stream, and streamWrite copies that data to your array.

          Most of the samples are supposed to be specific and simple to showcase a single feature or way of doing something in brook.
            • Brook+ Question to anyone
              ryta1203
              I did look at the constant.br sample, since I thought that would help.

              Unfortunately, this doesn't solve the problem since in your example, K is a constant and I stated I would like it to increment. The other problem is that I do not want to flatten my 3D volume to a 1D volume, if at all possible.

              For instance, if the steam size is 2,2,4

              0,0,0 =1
              0,0,1=2
              0,0,2=3
              0,0,3=4
              0,1,0=1
              0,1,1=2
              0,1,2=3
              0,1,3=4
              .........
              .......
              1,1,3=4

              It looks to me like your example makes every element of the stream be 30 (//or some arbitrary value), or am I misunderstanding your example?

              Thanks.
            • Brook+ Question to anyone
              MicahVillmow
              Well, if there is some calculation that you are doing on the CPU, then it should be possible to do it in the kernel. From your example, it looks like in the case of 2,2,4, you want to assign the value as the index + 1, so pass in K of 4 and do something like:
              s = (indexof(s).x % K) + 1;
              The constant sample shows you have to write a single value to a whole stream, it should be fairly simple to modify the code to make it write a non-constant value or kernel computed value to the whole stream, in essence initializing the stream. Also, after discussing with another engineer about the flattening, there should be no difference in results if treated as a 1D stream based on how brook is implemented except for three caveats.
              First of which is that currently 3D streams do not work in brook+, this is an issue inherited from the mainline brook tree on sourceforge and is something that we will have corrected in a future version.
              Secondly, a 3D stream, if it did work, is translated into a 2D stream and address translation is applied to all the addresses. Since graphics cards do not handle 3D streams, it is being flattened anyways.
              Thirdly, the address translation is written in a generic way, and thus will be slower than if app specific translations of the coordinates were coded at the top of the kernel.

              Hope this helps you out with your problem.
                • Brook+ Question to anyone
                  ryta1203
                  My kernel:

                  kernel void init1(float value, out float b_traces1<> )
                  {
                  b_traces1 = value;
                  }

                  Main:

                  int main()
                  {
                  const int trace_size = 256;
                  float b_traces1<256>;
                  float value = 1.0;
                  init1(value, b_traces1);
                  return 0;
                  }

                  The runtime error message:

                  void init1 (::brook::stream b_traces1,
                  const float value) {
                  static const void *__init1_fp[] = {
                  "ps30", __init1_ps30,
                  "cal", __init1_cal,
                  "cpu", (void *) __init1_cpu,
                  NULL, NULL };
                  static ::brook::kernel __k(__init1_fp); //it says it cannot evaluate this expression
                  __k->PushOutput(b_traces1);
                  __k->PushConstant(value);
                  __k->Map();

                  }

                  I only get this runtime error message when in Debug mode (which from what you guys have already told me is a problem), but I just wanted to make sure. This is the output:

                  'MStack.exe': Loaded 'C:\Documents and Settings\admin\Desktop\MStack\release\MStack.exe', Symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\Program Files\AMD\CAL SDK v0.90.0_alpha\lib\xp32\amdcalrt.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\Program Files\AMD\CAL SDK v0.90.0_alpha\lib\xp32\amdcalcl.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcp80.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
                  'MStack.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
                  The program '[3372] MStack.exe: Native' has exited with code 0 (0x0).
                    • Brook+ Question to anyone
                      michael.chu
                      I've forwarded this to our engineers and will let you know what they find.

                      Michael.
                        • Brook+ Question to anyone
                          ryta1203
                          Originally posted by: michael.chu@amd.com

                          I've forwarded this to our engineers and will let you know what they find.



                          Michael.



                          Did you ever find anything out about this?
                            • Brook+ Question to anyone
                              michael.chu
                              I apologize for the delay! I hadn't heard back from them yet.

                              However, we recently just posted v1.0beta on the stream computing website (we haven't had a chance to email that out to everyone yet). I'm hoping this will have fixed many of the outstanding issues out there.

                              Can you download v1.0beta from the website and give that a try to see if the problem still exists?

                              Thanks!

                              Michael.
                                • Brook+ Question to anyone
                                  ryta1203
                                  No, betav1.0 did not fix these ALSO it gives the error (when I installed OVER the alpha version):

                                  calCtxRunProgramParams not found!
                                  Unable to initialize CAL runtime, falling back to CPU


                                  I then uninstalled Alpha using "Add/Remove Programs" and then installed Beta. Now my .br programs will not compile at all, giving the error "A" is not an option:

                                  1>------ Build started: Project: MStack, Configuration: Release Win32 ------
                                  1>Performing Custom Build Step
                                  1>C:\Program Files\AMD\BROOKPLUS SDK v1.00.0_beta\\sdk\bin\brcc.exe: unknown option -- A
                                  1>Brook+ Compiler
                                  1>Version: 1.00.0a Built: Mar 6 2008, 11:32:55
                                  1>brcc [-hkrgb] [-o prefix] [-p shader ] foo.br
                                  1> -h help (print this message)
                                  1> -k keep generated IL program (in foo.il)
                                  1> -r diasable address virtualization
                                  1> -g enable fast math (less accurate)
                                  1> -o prefix prefix prepended to all output files
                                  1> -p shader cpu or cal (can specify multiple)
                                  1> -b turn on bison debugging
                                  1> -f turn on flex debugging
                                  1>Project : error PRJ0019: A tool returned an error code from "Performing Custom Build Step"
                                  1>Build log was saved at "file://c:\Documents and Settings\admin\Desktop\MStack\MStack\Release\BuildLog.htm"
                                  1>MStack - 1 error(s), 0 warning(s)
                                  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

                                  I am probably going to uninstall the beta and reinstall the alpha. Any other suggestions?

                                  EDIT: I took out the -A option (not sure why this is still in the documentation if it doesn't work) and my .br file compiled; however, the program crashed at runtime saying that it couldn't find brook.dll. I will edit again when fixed.

                                  EDIT2: I was unable to fix the .dll problem, any suggestions? I tried to re-install everything several times but no luck.
                                    • Brook+ Question to anyone
                                      michael.chu
                                      Sorry about the -A still being in the docs. I'll let the team know to get that out of there.

                                      -A is now automatically implied for brcc.

                                      Can you make sure that the v1.0beta brook.dll is in your PATH variable? And to make sure you have restarted MSVS?

                                      Also, make sure that the v1.0beta CAL is in your PATH variable and that no v0.9alpha stuff is remaining in your path.
                                        • Brook+ Question to anyone
                                          ryta1203
                                          Michael,

                                          Thanks again, the problem is fixed. I added:

                                          C:\Program Files\AMD\BROOKPLUS SDK v1.00.0_beta\sdk\lib

                                          To the system variables "path" (at the end) and this works.

                                          However, this pretty much means that the "Add to Path" function isn't working for the brook lib folder (if it should be, I don't know).

                                          BROOKROOT and CALROOT and the CAL path were all added properly by the installer, apparently just not the Brook ..\sdk\lib
                              • Brook+ Question to anyone
                                ryta1203
                                Micah,

                                The only problem is that in your example you are setting the whole stream (if I am understanding correctly) to one value. I'm looking to initialize only part of the stream to an incremental value. For example:

                                1. Assume the stream size is 256
                                2. I want to initialze elements 1 to 128 to a value that is the index of that element

                                much like:

                                value[k] = k;


                                If I use:

                                float s<256>;
                                float range;

                                kernel:

                                if (indexof(s) > 0 && indexof(s) <= 128)
                                {
                                s = indexof(s); //this sets the whole stream right?
                                }

                                I would like to set each index from 1 to 128 equal to the values 1 to 128 each. Such that:

                                s[1] = 1;
                                s[2] = 2;
                                .....
                                s[128] = 128;
                              • Brook+ Question to anyone
                                MicahVillmow
                                The psuedo-kernel that you wrote should work, but you have to remember, your kernel is run over each element so unless you have some sort of flow control, it will write to every element. The code where you have s = indexof(s) doesn't set the whole stream to that value, it only sets the elements that evaluate to true for the if statement.
                                  • Brook+ Question to anyone
                                    ryta1203
                                    Micah,

                                    Thanks for your time. The "stream" thing is really new to me and I forgot that the kernel runs for each element of the stream. That was silly of me.

                                    This works fine ALTHOUGH it's still giving me the output errors I mentioned above.

                                    'MStack.exe': Loaded 'C:\Documents and Settings\admin\Desktop\MStack\release\MStack.exe', Symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\Program Files\AMD\CAL SDK v0.90.0_alpha\lib\xp32\amdcalrt.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\Program Files\AMD\CAL SDK v0.90.0_alpha\lib\xp32\amdcalcl.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcp80.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
                                    'MStack.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
                                    The program '[3472] MStack.exe: Native' has exited with code 0 (0x0).