예제 #1
0
        /// <summary>
        /// Access a specific slice of either a column 'c' or row 'r' of this vector
        /// </summary>
        /// <param name="gpu"></param>
        /// <param name="row_col_index"></param>
        /// <param name="row_col"></param>
        /// <returns></returns>
        public Vector _AccessSlice(int row_col_index, char row_col)
        {
            if (this.Columns == 1)
            {
                throw new Exception("Input Vector cannot be 1D");
            }

            int[] ChangeSelectLength;
            int   OutPutVectorLength;

            switch (row_col)
            {
            case 'r':
                //ChangeSelectLength = new int[5] { 0, 1, row_col_index, 0, vector.Columns };
                //OutPutVectorLength = vector.Columns;
                return(this._AccessRow(this, row_col_index));

            case 'c':
                ChangeSelectLength = new int[5] {
                    1, 0, 0, row_col_index, this.Columns
                };
                OutPutVectorLength = this.Value.Length / this.Columns;
                break;

            default:
                throw new Exception("Invalid slice char selector, choose 'r' for row or 'c' for column");
            }

            //this is bad and I should feel bad
            Accelerator       gpu    = this.gpu.accelerator;
            AcceleratorStream Stream = gpu.CreateStream();

            var kernelWithStream = gpu.LoadAutoGroupedKernel <Index1, ArrayView <float>, ArrayView <float>, ArrayView <int> >(AccessSliceKernal);

            var buffer  = gpu.Allocate <float>(OutPutVectorLength);
            var buffer2 = gpu.Allocate <float>(this.Value.Length);
            var buffer3 = gpu.Allocate <int>(5);

            buffer.MemSetToZero(Stream);
            buffer2.MemSetToZero(Stream);
            buffer3.MemSetToZero(Stream);

            buffer2.CopyFrom(Stream, this.Value, 0, 0, this.Value.Length);
            buffer3.CopyFrom(Stream, ChangeSelectLength, 0, 0, ChangeSelectLength.Length);

            kernelWithStream(Stream, OutPutVectorLength, buffer.View, buffer2.View, buffer3.View);

            Stream.Synchronize();

            float[] Output = buffer.GetAsArray(Stream);

            buffer.Dispose();
            buffer2.Dispose();
            buffer3.Dispose();

            Stream.Dispose();

            return(new Vector(this.gpu, Output));
        }
예제 #2
0
        public async void Dispose()
        {
            _disposing = true;
            _isActive  = false; // do not allow any new computation.

            // the host will dispose of this stream
            _host?.ReturnSession(this);
            _host = null;

            bool computeFinished = await ComputeFinished();

            _stream?.Dispose();
            _stream = null;
            _display?.Dispose();
            _display = null;

            _area?.Dispose();
            _area = null;
            _output?.Dispose();
            _output           = null;
            mandelbrot_kernel = null;
        }