当前位置: 首页>>代码示例>>C#>>正文


C# GThread类代码示例

本文整理汇总了C#中GThread的典型用法代码示例。如果您正苦于以下问题:C# GThread类的具体用法?C# GThread怎么用?C# GThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GThread类属于命名空间,在下文中一共展示了GThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyKernel

        public static void ApplyKernel(GThread thread, int[] outputData)
        {
            //int[,] cache = thread.AllocateShared<int>("cache", X_SIZE, Y_SIZE);
            int targetX = thread.blockIdx.x;
            int targetY = 0;

            float value = 0;

            while(targetY < Y_SIZE)
            {
                for (int kernelX = KERNEL_SIZE / -2; kernelX <= KERNEL_SIZE / 2; kernelX++)
                    for (int kernelY = KERNEL_SIZE / -2; kernelY <= KERNEL_SIZE / 2; kernelY++)
                    {
                        int realX = targetX + kernelX;
                        int realY = targetY + kernelY;

                        if (realX >= 0 && realX < X_SIZE &&
                            realY >= 0 && realY < Y_SIZE)
                            value += MemoryKernel[kernelX + KERNEL_SIZE / 2, kernelY + KERNEL_SIZE / 2] * MemoryMain2D[realX, realY];

                        //Debug.WriteLine(String.Format("hoge: {0}",kernelX));
                    }

                //cache[targetX, targetY] = (int)value;
                //outputData[targetX + targetY * X_SIZE] = cache[targetX, targetY];
                outputData[targetX + targetY * X_SIZE] = (int)value;
                targetY++;
                value = 0;
            }
        }
开发者ID:yanoshi,项目名称:opencl-with-csharp-4test,代码行数:30,代码来源:KernelCalculator.cs

示例2: calc_e

 public static void calc_e(GThread thread, int n, int[] dx, int[] dy, int[] e)
 {
     for (int i = 0; i < n; i++)
     {
         e[i] = 2 * dy[i] - dx[i];
     }
 }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:7,代码来源:Timing.cs

示例3: MuxArray

        public static void MuxArray(GThread thread, int[] a, int[] b, int[] c)
        {
            int tid = thread.blockIdx.x;

            if (tid < N)
                c[tid] = a[tid] * b[tid];
        }
开发者ID:yanoshi,项目名称:opencl-with-csharp-4test,代码行数:7,代码来源:OpenCLTest.cs

示例4: Product

        public static void Product(GThread thread, int[] a, int[] b, int[] c)
        {
            int tid = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
            int[] cache = thread.AllocateShared<int>("cache", 4);
            int temp = 0;
            int cacheIndex=thread.threadIdx.x;
            while (tid < N)
            {
                temp = temp + a[tid] * b[tid];
                tid += thread.blockDim.x * thread.gridDim.x;
            }
            cache[thread.threadIdx.x] = temp;

            thread.SyncThreads();

            int i = thread.blockDim.x / 2;
            while (i != 0)
            {
                if (cacheIndex < i)
                {
                    cache[cacheIndex] += cache[cacheIndex + i];
                }
                thread.SyncThreads();

                i /= 2;
            }
            if (cacheIndex == 0)
            {
                c[thread.blockIdx.x] = cache[0];
            }
        }
开发者ID:vivekmurli,项目名称:customerinfo,代码行数:31,代码来源:dotProduct.cs

示例5: thekernel

        public static void thekernel(GThread thread, SphereOpenCL[] s, byte[] ptr)
        {
            int x = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
            int y = thread.threadIdx.y + thread.blockIdx.y * thread.blockDim.y;
            int offset = x + y * thread.blockDim.x * thread.gridDim.x;
            float ox = (x - ray_gui.DIM / 2);
            float oy = (y - ray_gui.DIM / 2);

            float r = 0, g = 0, b = 0;
            float maxz = -INF;
            for (int i = 0; i < SPHERES; i++)
            {
                float n = 0;                
                float t = hit(s[i], ox, oy, ref n);
                if (t > maxz)
                {
                    float fscale = n;
                    r = s[i].r * fscale;
                    g = s[i].g * fscale;
                    b = s[i].b * fscale;
                    maxz = t;
                }
            }

            ptr[offset * 4 + 0] = (byte)(r * 255);
            ptr[offset * 4 + 1] = (byte)(g * 255);
            ptr[offset * 4 + 2] = (byte)(b * 255);
            ptr[offset * 4 + 3] = 255;
        }
开发者ID:JustasB,项目名称:cudafy,代码行数:29,代码来源:ray_opencl.cs

示例6: Dot

        public static void Dot(GThread thread, float[] a, float[] b, float[] c)
        {
            float[] cache = thread.AllocateShared<float>("cache", threadsPerBlock);

            int tid = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
            int cacheIndex = thread.threadIdx.x;

            float temp = 0;
            while (tid < N)
            {
                temp += a[tid] * b[tid];
                tid += thread.blockDim.x * thread.gridDim.x;
            }

            // set the cache values
            cache[cacheIndex] = temp;

            // synchronize threads in this block
            thread.SyncThreads();

            // for reductions, threadsPerBlock must be a power of 2
            // because of the following code
            int i = thread.blockDim.x / 2;
            while (i != 0)
            {
                if (cacheIndex < i)
                    cache[cacheIndex] += cache[cacheIndex + i];
                thread.SyncThreads();
                i /= 2;
            }

            if (cacheIndex == 0)
                c[thread.blockIdx.x] = cache[0];
        }
开发者ID:JustasB,项目名称:cudafy,代码行数:34,代码来源:PinnedAsyncIO.cs

示例7: histo_kernel

        public static void histo_kernel(GThread thread, byte[] buffer, int size, uint[] histo) 
        {
            // clear out the accumulation buffer called temp
            // since we are launched with 256 threads, it is easy
            // to clear that memory with one write per thread
            uint[] temp = thread.AllocateShared<uint>("temp", 256);
            temp[thread.threadIdx.x] = 0;
            thread.SyncThreads();

            // calculate the starting index and the offset to the next
            // block that each thread will be processing
            int i = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
            int stride = thread.blockDim.x * thread.gridDim.x;
            while (i < size) 
            {
                thread.atomicAdd(ref temp[buffer[i]], 1 );
                i += stride;
            }
            // sync the data from the above writes to shared memory
            // then add the shared memory values to the values from
            // the other thread blocks using global memory
            // atomic adds
            // same as before, since we have 256 threads, updating the
            // global histogram is just one write per thread!
            thread.SyncThreads();

            thread.atomicAdd(ref (histo[thread.threadIdx.x]), temp[thread.threadIdx.x]);
        }
开发者ID:JustasB,项目名称:cudafy,代码行数:28,代码来源:hist_gpu_shmem_atomics.cs

示例8: calc_e_v2

 public static void calc_e_v2(GThread thread, int n, int[] dx, int[] dy, int[] e)
 {
     int i = thread.blockDim.x * thread.blockIdx.x + thread.threadIdx.x;
     while(i < n)
     {
         e[i] = 2 * dy[i] - dx[i];
         i += (thread.blockDim.x * thread.gridDim.x);
     }
 }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:9,代码来源:Timing.cs

示例9: SetValueGPUDouble

        public static void SetValueGPUDouble(GThread thread, int n, double[] vector, double value)
        {
            int tid = thread.blockIdx.x;

            if (tid < n)
            {
                vector[tid] = value;
            }
        }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:9,代码来源:Solver.cs

示例10: SetValueGPUSingle

        public static void SetValueGPUSingle(GThread thread, int n, float[] vector, float value)
        {
            int tid = thread.blockIdx.x;

            if (tid < n)
            {
                vector[tid] = value;
            }
        }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:9,代码来源:Solver.cs

示例11: add

 public static void add(GThread thread, int[] a, int[] b, int[] sum)
 {
     int index = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
     while (index < N)
     {
         sum[index] = sum[index] + a[index] + b[index];
         index = index + thread.blockDim.x * thread.gridDim.x;
     }
 }
开发者ID:vivekmurli,项目名称:customerinfo,代码行数:9,代码来源:add_type2.cs

示例12: add_0

 public static void add_0(GThread thread, int[] a, int[] b, int[] c)
 {
     int tid = thread.blockIdx.x;
     while (tid < N)
     {
         c[tid] = a[tid] + b[tid];
         tid += thread.gridDim.x;
     }
 }
开发者ID:constructor-igor,项目名称:TechSugar,代码行数:9,代码来源:ArrayBasicIndexing.cs

示例13: parentKernel

 public static void parentKernel(GThread thread, int[] a, int[] c, short coeff)
 {
     //childKernel(thread, a, c, coeff);
     int rc;
     //BROKEN thread.Launch(N / 2, numberYouFirstThoughtOf() * coeff, "childKernel", a, c, numberYouFirstThoughtOf() * coeff + 23 * a[0]);
     thread.Launch(N, 1, "childKernel", a, c, coeff * numberYouFirstThoughtOf());//a[0]);//numberYouFirstThoughtOf() * coeff + 23 * 
     rc = thread.SynchronizeDevice();
     int count = 0;
     rc = thread.GetDeviceCount(ref count);
 }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:10,代码来源:Compute35Features.cs

示例14: SyncThreadCountKernel

        public static void SyncThreadCountKernel(GThread thread, int[] input, int[] output)
        {
            var tid = thread.threadIdx.x;

            int value = input[tid];
            bool predicate = value == 1;
            var count = thread.SyncThreadsCount(predicate);

            if (tid == 0)
                output[0] = count;
        }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:11,代码来源:SyncThreadCount.cs

示例15: add

        public static void add(GThread thread, int[] a, int[] b, int[] c, int[] d, int[] e, int[] sum)
        {
            //To get Array Index for each Thread
            int index = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;

            while (index < N)
            {
                sum[index] = a[index] + b[index] + c[index] + d[index] + e[index];
                index = index + thread.blockDim.x * thread.gridDim.x;
            }
        }
开发者ID:vivekmurli,项目名称:customerinfo,代码行数:11,代码来源:add_type1.cs


注:本文中的GThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。