public GpuSimiulation(IStockData stockData, int holding = 10, float ann = 5.0990f)
        {
            _stockData     = stockData;
            _holding       = holding;
            _ann           = ann;
            _programSource = File.ReadAllText("Kernels.cl");

            _env = "*AMD*".CreateCLEnvironment(DeviceType.Gpu, CommandQueueProperties.ProfilingEnable);

            _h_output           = new float[(stockData.QuotesPerStock - holding)];
            _d_stocksAndPrices  = Cl.CreateBuffer <float>(_env.Context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, _stockData.RawData, out ErrorCode err);
            _d_portfolioStockMv = Cl.CreateBuffer <float>(_env.Context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, _stockData.MarketValues, out err);
            _d_output           = Cl.CreateBuffer <float>(_env.Context, MemFlags.ReadWrite, stockData.StocksCount * (stockData.QuotesPerStock - holding), out err);
        }
Exemple #2
0
        static float[] MultiplyScalar(OpenCL.Net.Environment env, float[] A, float scalar)
        {
            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.MultiplyScalar(env.Context);

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

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

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

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

            return(results);
        }
        private static void Main(/* string[] args */)
        {
            ErrorCode errorCode;
            var platformIds = Cl.GetPlatformIDs(out errorCode);
            errorCode.Check("GetPlatformIDs");

            var platformNames = platformIds.Select(platformId =>
            {
                ErrorCode innerErrorCode;
                var platformName = Cl.GetPlatformInfo(platformId, PlatformInfo.Name, out innerErrorCode);
                innerErrorCode.Check("GetPlatformIDs");
                return platformName.ToString();
            });

            foreach (var platformName in platformNames)
            {
                var environment = new Environment(platformName);
                EnumerateDevices(environment.Context, environment.Devices);
            }
        }
Exemple #4
0
        static float[] MultiplyMatrixVector(OpenCL.Net.Environment env, float[] A, float[] b)
        {
            var len     = (uint)b.Length;
            var bufferA = env.Context.CreateBuffer(A, MemFlags.ReadOnly);
            var bufferB = env.Context.CreateBuffer(b, MemFlags.ReadOnly);
            var bufferC = env.Context.CreateBuffer(SourceZeroVector(), MemFlags.WriteOnly);

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

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

            kernel.Run(env.CommandQueues[0], bufferC, bufferA, bufferB, n, len);

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

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

            return(results);
        }
        private static void Main(/* string[] args */)
        {
            ErrorCode errorCode;
            var platformIds = Cl.GetPlatformIDs(out errorCode);
            errorCode.Check("GetPlatformIDs");

            foreach (var platformId in platformIds)
            {
                var platformName = Cl.GetPlatformInfo(platformId, PlatformInfo.Name, out errorCode).ToString();
                errorCode.Check("GetPlatformInfo(PlatformInfo.Name)");
                Console.WriteLine($"Platform name: {platformName}");

                var vendor = Cl.GetPlatformInfo(platformId, PlatformInfo.Vendor, out errorCode).ToString();
                errorCode.Check("GetPlatformInfo(PlatformInfo.Vendor)");
                Console.WriteLine($"Platform vendor: {vendor}");

                var version = Cl.GetPlatformInfo(platformId, PlatformInfo.Version, out errorCode).ToString();
                errorCode.Check("GetPlatformInfo(PlatformInfo.Version)");
                Console.WriteLine($"Platform version: {version}");

                var environment = new Environment(platformName);
                EnumerateDevices(environment.Devices);
            }
        }