Beispiel #1
0
 public void RefreshDevice()
 {
     indices.RefreshDevice();
     data.RefreshDevice();
     rows.RefreshDevice();
 }
Beispiel #2
0
        public static IntResidentArray Solv(List <int[]> input_arr)
        {
            cudaDeviceProp prop;

            cuda.GetDeviceProperties(out prop, 0);
            //if .SetDistrib is not used, the default is .SetDistrib(prop.multiProcessorCount * 16, 128)
            HybRunner runner = HybRunner.Cuda("Hybrid_CUDA.dll").SetDistrib(prop.multiProcessorCount * 16, 256);

            // create a wrapper object to call GPU methods instead of C#
            dynamic wrapper = runner.Wrap(new Program());

            IntResidentArray pre_basis_main = new IntResidentArray(input_arr[0].Length * (input_arr[0].Length - 1));

            //int threadsperblock = 256;
            //int blockspergrid = (int)Math.Ceiling((double)(input_arr[0].Length - 1) / threadsperblock);

            int pre_basisLengthAxis0     = input_arr[0].Length - 1;
            int equationLength           = input_arr[0].Length;
            IntResidentArray inputArray0 = new IntResidentArray(equationLength);

            inputArray0.RefreshHost();
            for (int j = 0; j < equationLength; j++)
            {
                inputArray0[j] = input_arr[0][j];
            }

            inputArray0.RefreshDevice();
            pre_basis_main.RefreshDevice();
            wrapper.Create_pre_basis(inputArray0, pre_basis_main, equationLength); //create prebasis for the first equation
            for (int Li = 1; Li < input_arr.Count; Li++)                           //iterate through other equations
            {
                IntResidentArray substitution_result = new IntResidentArray(pre_basisLengthAxis0);

                //substitution_result.RefreshDevice();
                wrapper.Substitute(input_arr[Li], pre_basis_main, substitution_result, equationLength, pre_basisLengthAxis0); //substitute vectors of prebasis to equation Li

                IntResidentArray pre_basis_Y = new IntResidentArray((pre_basisLengthAxis0 - 1) * pre_basisLengthAxis0);       //also flattened array

                pre_basis_Y.RefreshDevice();
                wrapper.Create_pre_basis(substitution_result, pre_basis_Y, pre_basisLengthAxis0);  //create prebasis from result of substitution

                IntResidentArray mult_result = new IntResidentArray((pre_basisLengthAxis0 - 1) * equationLength);

                mult_result.RefreshDevice();
                wrapper.Multiply_pre_basis(pre_basis_main, pre_basis_Y, mult_result, equationLength, pre_basisLengthAxis0 - 1, pre_basisLengthAxis0);  //get new main prebasis

                pre_basis_main        = mult_result;
                pre_basisLengthAxis0 -= 1;

                pre_basis_main.RefreshHost();
                IntResidentArray gcds = new IntResidentArray(pre_basisLengthAxis0);
                Find_gcds(pre_basis_main, pre_basisLengthAxis0, equationLength, gcds);
                gcds.RefreshDevice();

                pre_basis_main.RefreshDevice();
                wrapper.Simplify(pre_basis_main, gcds, pre_basisLengthAxis0, equationLength);  //simplify vectors of prebasis if possible
            }

            pre_basis_main.RefreshHost();
            return(pre_basis_main);
        }