Ejemplo n.º 1
0
        ErrorCode queue_scrypt_kernel(clState _clState, dev_blk_ctx blk)
        {
            //Scantime


            blk.work.midstate0 = new uint4(0);

            blk.work.midstate16 = new uint4(1);



            // unsigned char *midstate = blk->work->midstate;
            int    num = 0;
            uint16 le_target;

            le_target          = new uint16(Convert.ToUInt16(blk.work.device_target + 28));
            _clState.cldata    = blk.work.data;
            _clState.CLBuffer0 = new uint4(0);

            _clState.outputBuffer = new Mem();

            _clState.padbuffer8 = new uint4(0);


            OpenCL.Net.Event       clevent;
            OpenCL.Net.ImageFormat clImageFormat = new OpenCL.Net.ImageFormat(ChannelOrder.RGBA, ChannelType.Unsigned_Int8);
            ErrorCode err1;

            byte[] inputByteArray = new byte[1024];


            //buffer0 = (OpenCL.Net.Mem)OpenCL.Net.Cl.CreateImage2D(_clState.cl_context,                 OpenCL.Net.MemFlags.CopyHostPtr | OpenCL.Net.MemFlags.ReadOnly, clImageFormat,                                              (IntPtr)1024, (IntPtr)1,                                                  (IntPtr)0, inputByteArray, out err1);
            // buffer0 = (OpenCL.Net.Mem)inputByteArray;
            // byte[] byteSrcImage2DData = new byte[srcIMGBytesSize];
            Mem buffer0 = (Mem)OpenCL.Net.Cl.CreateBuffer(_clState.cl_context, MemFlags.ReadWrite, 1024, out err1);


            ErrorCode status = Cl.EnqueueWriteBuffer(_clState.cl_command_queue, buffer0, OpenCL.Net.Bool.True, (IntPtr)0, (IntPtr)1024, _clState.cldata, 0, null, out clevent);

            //
//      status = OpenCL.Net.Cl.SetKernelArg(_clState.Kernel,  num++, sizeof(var), (void *)&var)

            // CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)



            int intPtrSize = 0;

            intPtrSize = Marshal.SizeOf(typeof(IntPtr));



            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 0, (IntPtr)intPtrSize, _clState.CLBuffer0);


            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 1, _clState.outputBuffer);
            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 2, _clState.padbuffer8);
            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 3, blk.work.midstate0);
            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 4, blk.work.midstate16);
            //   CL_SET_VARG(4, &midstate[0]);
            //	CL_SET_VARG(4, &midstate[16]);
            OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 5, le_target);
            //error = Cl.SetKernelArg(kernel, 0, (IntPtr)intPtrSize, inputImage2DBuffer);
            CheckErr(status, "Cl.SetKernelArg");
            return(status);
        }
Ejemplo n.º 2
0
ErrorCode queue_scrypt_kernel(clState _clState, dev_blk_ctx blk)
{

    //Scantime
    

    blk.work.midstate0 = new uint4(0);

    blk.work.midstate16 = new uint4(1);



   // unsigned char *midstate = blk->work->midstate;
	int  num = 0;
	uint16 le_target;
  le_target = new uint16(Convert.ToUInt16(blk.work.device_target + 28));
    _clState.cldata = blk.work.data;
    _clState.CLBuffer0 = new uint4(0);

    _clState.outputBuffer = new Mem();

    _clState.padbuffer8 = new uint4(0);


    OpenCL.Net.Event clevent;
    OpenCL.Net.ImageFormat clImageFormat = new OpenCL.Net.ImageFormat(ChannelOrder.RGBA, ChannelType.Unsigned_Int8);
    ErrorCode err1;
    byte[] inputByteArray = new byte[1024];

              
    //buffer0 = (OpenCL.Net.Mem)OpenCL.Net.Cl.CreateImage2D(_clState.cl_context,                 OpenCL.Net.MemFlags.CopyHostPtr | OpenCL.Net.MemFlags.ReadOnly, clImageFormat,                                              (IntPtr)1024, (IntPtr)1,                                                  (IntPtr)0, inputByteArray, out err1);
   // buffer0 = (OpenCL.Net.Mem)inputByteArray;
   // byte[] byteSrcImage2DData = new byte[srcIMGBytesSize];
    Mem buffer0 = (Mem)OpenCL.Net.Cl.CreateBuffer(_clState.cl_context, MemFlags.ReadWrite, 1024,out err1);

              
	ErrorCode status =Cl.EnqueueWriteBuffer(_clState.cl_command_queue, buffer0, OpenCL.Net.Bool.True, (IntPtr)0, (IntPtr)1024, _clState.cldata, 0, null,out clevent);

    //
//      status = OpenCL.Net.Cl.SetKernelArg(_clState.Kernel,  num++, sizeof(var), (void *)&var)

  // CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)



    int intPtrSize = 0;
    intPtrSize = Marshal.SizeOf(typeof(IntPtr));



    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 0,(IntPtr)intPtrSize, _clState.CLBuffer0);


    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 1, _clState.outputBuffer);
    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 2, _clState.padbuffer8);
    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 3, blk.work.midstate0);
    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 4, blk.work.midstate16);
    //   CL_SET_VARG(4, &midstate[0]);
    //	CL_SET_VARG(4, &midstate[16]);
    OpenCL.Net.Cl.SetKernelArg(_clState.cl_kernel, 5,le_target);
    //error = Cl.SetKernelArg(kernel, 0, (IntPtr)intPtrSize, inputImage2DBuffer);
    CheckErr(status, "Cl.SetKernelArg");
return status;
}
Ejemplo n.º 3
0
        public void ScryptTest()
        {
            ErrorCode error;

            //Load and compile kernel source code.
            string programPath = System.Environment.CurrentDirectory + "/../../scrypt.cl";  //Cl

            if (!System.IO.File.Exists(programPath))
            {
                Console.WriteLine("Program doesn't exist at path " + programPath);                return;
            }

            string programSource = System.IO.File.ReadAllText(programPath);

            IntPtr[] sz      = new IntPtr[programSource.Length * 2];
            Program  program = Cl.CreateProgramWithSource(_context, 1, new[] { programSource }, null, out error);

            if (1 == 1)
            {
                CheckErr(error, "Cl.CreateProgramWithSource");

                //                status = clBuildProgram(clState->program, 1, &devices[gpu], ""-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d", NULL, NULL);
                //Compile kernel source
                error = Cl.BuildProgram(program, 1, new[] { _device }, "-D LOOKUP_GAP=1 -D CONCURRENT_THREADS=1 -D WORKSIZE=1", null, IntPtr.Zero);
                CheckErr(error, "Cl.BuildProgram");

                //Check for any compilation errors
                if (Cl.GetProgramBuildInfo(program, _device, ProgramBuildInfo.Status, out error).CastTo <BuildStatus>()
                    != BuildStatus.Success && 1 == 0)
                {
                    CheckErr(error, "Cl.GetProgramBuildInfo");
                    Console.WriteLine("Cl.GetProgramBuildInfo != Success");
                    Console.WriteLine(Cl.GetProgramBuildInfo(program, _device, ProgramBuildInfo.Log, out error));
                    return;
                }

                //Create the required kernel (entry function) [search]
                Kernel kernel = Cl.CreateKernel(program, "search", out error);

                CheckErr(error, "Cl.CreateKernel");
                int intPtrSize = 0;
                intPtrSize = Marshal.SizeOf(typeof(IntPtr));

                //Image's RGBA data converted to an unmanaged[] array
                byte[] inputByteArray;
                //OpenCL memory buffer that will keep our image's byte[] data.
                Mem inputImage2DBuffer;
                //Create a command queue, where all of the commands for execution will be added
                CommandQueue cmdQueue = Cl.CreateCommandQueue(_context, _device, (CommandQueueProperties)0, out error);
                CheckErr(error, "Cl.CreateCommandQueue");
                clState _clState = new clState();
                _clState.cl_command_queue = cmdQueue;
                _clState.cl_kernel        = kernel;
                _clState.cl_context       = _context;


                IntPtr buffersize = new IntPtr(1024);
                IntPtr blank_res  = new IntPtr(1024);
                Object thrdataRes = new Object();


                //int buffersize = 1024;
                OpenCL.Net.Event clevent;
                //                 status |= clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,  buffersize, blank_res, 0, NULL, NULL);
                dev_blk_ctx blk = new dev_blk_ctx();
                ErrorCode   err = queue_scrypt_kernel(_clState, blk);



                ErrorCode status = Cl.EnqueueWriteBuffer(_clState.cl_command_queue,
                                                         _clState.outputBuffer, OpenCL.Net.Bool.True, new IntPtr(0), buffersize, blank_res, 0, null, out clevent);

                IntPtr[] globalThreads = new IntPtr[0];
                IntPtr[] localThreads  = new IntPtr[0];

                //uint16 workdim = new uint16(1);
                uint workdim = 1;

                status = Cl.EnqueueNDRangeKernel(_clState.cl_command_queue, _clState.cl_kernel, workdim, null, globalThreads, localThreads, 0, null, out clevent);
                CheckErr(error, "Cl.EnqueueNDRangeKernel");

                IntPtr offset = new IntPtr(0);

                status = Cl.EnqueueReadBuffer(_clState.cl_command_queue, _clState.outputBuffer, OpenCL.Net.Bool.False, offset, buffersize, thrdataRes, 0, null, out clevent);

                //Wait for completion of all calculations on the GPU.
                error = Cl.Finish(_clState.cl_command_queue);

                CheckErr(error, "Cl.Finish");

                //Clean up memory
                Cl.ReleaseKernel(_clState.cl_kernel);
                Cl.ReleaseCommandQueue(_clState.cl_command_queue);
            }
        }
Ejemplo n.º 4
0
        public void ScryptTest()
        {
            ErrorCode error;

            //Load and compile kernel source code.
            string programPath = System.Environment.CurrentDirectory + "/../../scrypt.cl";  //Cl
            if (!System.IO.File.Exists(programPath))
            {                Console.WriteLine("Program doesn't exist at path " + programPath);                return;
            }

            string programSource = System.IO.File.ReadAllText(programPath);
            IntPtr[] sz = new IntPtr[programSource.Length*2];
            Program program =Cl.CreateProgramWithSource(_context, 1, new[] { programSource }, null, out error);
            if (1==1)
            {
                CheckErr(error, "Cl.CreateProgramWithSource");

                //                status = clBuildProgram(clState->program, 1, &devices[gpu], ""-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d", NULL, NULL);
                //Compile kernel source
                error = Cl.BuildProgram(program, 1, new[] { _device },"-D LOOKUP_GAP=1 -D CONCURRENT_THREADS=1 -D WORKSIZE=1", null, IntPtr.Zero);
                CheckErr(error, "Cl.BuildProgram");

                //Check for any compilation errors
                if (Cl.GetProgramBuildInfo(program, _device, ProgramBuildInfo.Status, out error).CastTo<BuildStatus>()
                    != BuildStatus.Success && 1 == 0)
                {
                    CheckErr(error, "Cl.GetProgramBuildInfo");
                    Console.WriteLine("Cl.GetProgramBuildInfo != Success");
                    Console.WriteLine(Cl.GetProgramBuildInfo(program, _device, ProgramBuildInfo.Log, out error));
                    return;
                }

                //Create the required kernel (entry function) [search]
                Kernel kernel = Cl.CreateKernel(program, "search", out error);
                
                CheckErr(error, "Cl.CreateKernel");
                int intPtrSize = 0;
                intPtrSize = Marshal.SizeOf(typeof(IntPtr));

                //Image's RGBA data converted to an unmanaged[] array
                byte[] inputByteArray;
                //OpenCL memory buffer that will keep our image's byte[] data.
                Mem inputImage2DBuffer;
                //Create a command queue, where all of the commands for execution will be added
                CommandQueue cmdQueue = Cl.CreateCommandQueue(_context, _device, (CommandQueueProperties)0, out error);
                CheckErr(error, "Cl.CreateCommandQueue");
                clState _clState = new clState();
                _clState.cl_command_queue = cmdQueue;
                _clState.cl_kernel = kernel;
                _clState.cl_context = _context;


                IntPtr buffersize = new IntPtr(1024);
                IntPtr blank_res = new IntPtr(1024);
                Object thrdataRes = new Object();

                
                //int buffersize = 1024;
                OpenCL.Net.Event clevent;
                 //                 status |= clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,  buffersize, blank_res, 0, NULL, NULL);
                dev_blk_ctx blk = new dev_blk_ctx();
                ErrorCode err =  queue_scrypt_kernel(_clState,blk);



                ErrorCode status = Cl.EnqueueWriteBuffer(_clState.cl_command_queue,
                    _clState.outputBuffer, OpenCL.Net.Bool.True, new IntPtr(0), buffersize, blank_res, 0, null, out clevent);

                IntPtr[] globalThreads = new IntPtr[0];
                IntPtr[] localThreads = new IntPtr[0];

                //uint16 workdim = new uint16(1);
                uint workdim = 1;

                status = Cl.EnqueueNDRangeKernel(_clState.cl_command_queue,_clState.cl_kernel, workdim, null, globalThreads, localThreads, 0, null, out clevent);
                CheckErr(error, "Cl.EnqueueNDRangeKernel");

                IntPtr offset = new IntPtr(0);

                status = Cl.EnqueueReadBuffer(_clState.cl_command_queue,_clState.outputBuffer,OpenCL.Net.Bool.False,offset,buffersize,thrdataRes, 0,null, out clevent);

                //Wait for completion of all calculations on the GPU.
                error = Cl.Finish(_clState.cl_command_queue);

                CheckErr(error, "Cl.Finish");

                //Clean up memory
                Cl.ReleaseKernel(_clState.cl_kernel);
                Cl.ReleaseCommandQueue(_clState.cl_command_queue);

            }


        }