Exemplo n.º 1
0
        //static float[] SourceMatrix(Func<int, int, float> init) => Source(n * n, i => init(i%n, i));

        static float[] Transpose(OpenCL.Net.Environment env, float[] A, int w, int h)
        {
            var len = (uint)A.Length;
            var bufferA = env.Context.CreateBuffer(A, MemFlags.ReadOnly);            
            var bufferB = env.Context.CreateBuffer(Source(A.Length, _ => 0f), MemFlags.WriteOnly);

            var kernel = new Kernel.Transpose(env.Context);
            kernel.Compile("-cl-opt-disable");

            kernel.Run(env.CommandQueues[0], bufferB, bufferA, w, h, len);

            // WTF: We should wait for run
            var results = new float[A.Length];
            env.CommandQueues[0].ReadFromBuffer(bufferB, results);

            return results;
        }
Exemplo n.º 2
0
        //static float[] SourceMatrix(Func<int, int, float> init) => Source(n * n, i => init(i%n, i));

        static float[] Transpose(OpenCL.Net.Environment env, float[] A, int w, int h)
        {
            var len     = (uint)A.Length;
            var bufferA = env.Context.CreateBuffer(A, MemFlags.ReadOnly);
            var bufferB = env.Context.CreateBuffer(Source(A.Length, _ => 0f), MemFlags.WriteOnly);

            var kernel = new Kernel.Transpose(env.Context);

            kernel.Compile("-cl-opt-disable");

            kernel.Run(env.CommandQueues[0], bufferB, bufferA, w, h, len);

            // WTF: We should wait for run
            var results = new float[A.Length];

            env.CommandQueues[0].ReadFromBuffer(bufferB, results);

            return(results);
        }