Exemplo n.º 1
0
        public void Run()
        {
            var tmpWatch = DateTime.Now;
            if (_context == null)
            {
                var tmpDevices = PlatformHelper.Current().Devices;
                Log.Normal($"{tmpDevices.Count} Devices found.");

                _context = tmpDevices[0].CreateContext();
                _program = _context.CreateProgramWithSource(multiplayKernel);
            }
            var tmpKernel = _program.GetKernel("do_foreach");
            _program.GetKernel(nameof(ThreeParams.AddMul));

            var tmpKernelObjects = CreateParams(256);
            tmpKernel.AddTaskToQueue(tmpKernelObjects);

            tmpKernel.ReadFromQueue(tmpKernelObjects);

            Log.Normal($"Time: {(DateTime.Now - tmpWatch).Milliseconds}");
            for (int i = 0; i < 30; i++)
            {
                Log.Normal($"Result: {tmpKernelObjects[i].firstValue} * {tmpKernelObjects[i].secondValue} = {tmpKernelObjects[i].result}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create OpenCL Context from Devices
        /// </summary>
        /// <param name="inDevices"></param>
        /// <returns></returns>
        public static Context CreateContext(List<Device> inDevices)
        {
            OpenCLErrorCode tmpError;
            var tmpContextHandle = OpenCL_ContextInformation.CreateContext(null, (uint)inDevices.Count, inDevices.Select(inItem => inItem.Handle).ToArray(), null, IntPtr.Zero, out tmpError);
            if (tmpError != OpenCLErrorCode.Success)
            {
                Log.Error("Could not Create Context for Devices");
            }

            var tmpContext = new Context
            {
                Handle = tmpContextHandle,
                Devices = inDevices,
            };
            Log.Info("Content created");
            return tmpContext;
        }
Exemplo n.º 3
0
 internal void RemoveContext(Context inContext)
 {
     ContextList.Remove(inContext);
 }
Exemplo n.º 4
0
 internal void AddContext(Context inContext)
 {
     ContextList.Add(inContext);
 }
Exemplo n.º 5
0
        public void RunHighLevel()
        {
            var tmpWatch = DateTime.Now;
            if (_context == null)
            {
                var tmpDevices = PlatformHelper.Current().Devices;
                Log.Normal($"{tmpDevices.Count} Devices found.");

                _context = tmpDevices[0].CreateContext();
                _program = _context.CreateProgramWithSource(foreachKernel);
            }
            var tmpKernel = _program.GetKernel("do_foreach");

            var tmpKernelObjects = new List<BasicOperationKernelObject>
            {
                new BasicOperationKernelObject { FirstValue = 3},
                new BasicOperationKernelObject { FirstValue = 7},
                new BasicOperationKernelObject { FirstValue = 123},
            };
            tmpKernel.AddTaskToQueue(tmpKernelObjects);

            tmpKernel.ReadFromQueue(tmpKernelObjects);

            Log.Normal($"Time: {(DateTime.Now - tmpWatch).Milliseconds}");
            Log.Normal($"Result: {tmpKernelObjects[0].FirstValue},{tmpKernelObjects[1].FirstValue},{tmpKernelObjects[2].FirstValue}");
        }