No Result - zero outputed

  • Brian

    Brian - 2012-03-30

    I have a 2d float array and a 3d double array,  I am trying to output 1 one the first element of the 3D array.  This should be pretty simple, but I am obviously doing something really wrong.  Any help?

     public static void  RunRecon ()
                string[] Platforms = ImageViewer.PythonScripting.Projection.DoSliceBackProjectionSiddonEffect2.AvailablePlatforms();
                double[, ,] Data = new double[100, 100, 100];
                ImageViewer.PythonScripting.Projection.DoSliceBackProjectionSiddonEffect2.ReadResult(ref Data);
            static ComputeProgram program;
            #region GPU Code
            static string FBPcode = @"
    #pragma OPENCL EXTENSION cl_amd_fp64 : enable 
    __kernel void DO_Projection(  global  float * input, global double * volume)
            static IList<ComputeDevice> devices;
            static ComputePlatform platform;
            static ComputeContext context;
            public static string[] AvailablePlatforms()
                // Populate OpenCL Platform ComboBox
                string[] availablePlatforms = new string[ComputePlatform.Platforms.Count];
                for (int i = 0; i < availablePlatforms.Length; i++)
                    availablePlatforms[i] = ComputePlatform.Platforms[i].Name;
                return availablePlatforms;
            public static bool SetupGPU(string Platform)
                devices = new List<ComputeDevice>();
                if (ComputePlatform.Platforms.Count == 0)
                    return false;
                foreach (ComputePlatform cp in ComputePlatform.Platforms)
                    if (cp.Name == Platform)
                        platform = cp;
                if (devices.Count == 0)
                    return false;
                ComputeContextPropertyList properties = new ComputeContextPropertyList(platform);
                context = new ComputeContext(devices, properties, null, IntPtr.Zero);
                // Create and build the opencl program.
                program = new ComputeProgram(context, FBPcode);
                program.Build(null, null, null, IntPtr.Zero);
                // Create the kernel function and set its arguments.
                kernel = program.CreateKernel("DO_Projection");
                // Create the event wait list. An event list is not really needed for this example but it is important to see how it works.
                // Note that events (like everything else) consume OpenCL resources and creating a lot of them may slow down execution.
                // For this reason their use should be avoided if possible.
                eventList = new ComputeEventList();
                // Create the command queue. This is used to control kernel execution and manage read/write/copy operations.
                commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
                return true ;
            static ComputeKernel kernel;
            static ComputeBuffer<double> b;
            static ComputeCommandQueue commands;
            static ComputeEventList eventList;
            public static void Set3DBuffer(double[,,] Data)
                b = new ComputeBuffer<double>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer  , Data);
                 kernel.SetMemoryArgument(1, b);
            public static void DoProjections(DataEnvironment dataEnvironment )
                // Create the arrays and fill them with random data.
                int count = 10;
                //float[,,] Image = dataEnvironment.AllImages[0].ImageData;
                float[] Image = new float[100];
                // Create the input buffers and fill them with data from the arrays.
                // Access modifiers should match those in a kernel.
                // CopyHostPointer means the buffer should be filled with the data provided in the last argument.
                ComputeBuffer<float> a = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, Image);
                kernel.SetMemoryArgument(0, a);
                // Execute the kernel "count" times. After this call returns, "eventList" will contain an event associated with this command.
                // If eventList == null or typeof(eventList) == ReadOnlyCollection<ComputeEventBase>, a new event will not be created.
                commands.Execute(kernel, null, new long[] { 10 }, null, eventList);
                // A blocking "ReadFromBuffer" (if 3rd argument is true) will wait for itself and any previous commands
                // in the command queue or eventList to finish execution. Otherwise an explicit wait for all the opencl commands 
                // to finish has to be issued before "arrC" can be used. 
                // This explicit synchronization can be achieved in two ways:
                // 1) Wait for the events in the list to finish,
                // 2) Or simply use
            public static void ReadResult(ref double[,,] Data)
                // Read back the results. If the command-queue has out-of-order execution enabled (default is off), ReadFromBuffer 
                // will not execute until any previous events in eventList (in our case only eventList[0]) are marked as complete 
                // by OpenCL. By default the command-queue will execute the commands in the same order as they are issued from the host.
                // eventList will contain two events after this method returns.
                commands.ReadFromBuffer(b, ref Data, false, new SysIntX3(0,0,0), new SysIntX3(0,0,0),new SysIntX3(Data.GetLength(0),Data.GetLength(1), Data.GetLength(2)), eventList);
                double s = Data.SumArray();
  • Brian

    Brian - 2012-03-30

    Got it.  blocking must be set to true


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks