C#中的CUDA问题 [英] CUDA question in C#

查看:122
本文介绍了C#中的CUDA问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个论坛的新手..错误地更新为新帖子..对不起..

你好

我知道一些基本的C#,并且编写了一个程序.
由于大量的计算,程序会消耗CPU.
我用的是i7-2600K,但仍然需要花费几年的时间才能完成处理..

一位朋友告诉我,我可以向GPU发送大量计算.在网上阅读有关内容后,我意识到这是唯一可行的解​​决方案.
我选择了NVIDIA 470,并尝试将其与多个DLL一起使用,但对它的完成方式了解不多.

基本上,我有一个foreach循环,需要发送到GPU
多核时很简单-我只是将语法更改为
parallel.Foreach,但是对于GPU来说-我真的不明白如果没有
它是如何完成的 更改整个代码-我只想说说它,所以只是一部分
将被发送到GPU.

有什么想法吗?

请记住,我是新手,请像我一样智障:)

非常感谢,
Zvi

I''m new to this forum.. Updated as a new post by mistake.. sorry..

Hello

I know some basic C# and I wrote a program.
The program consumes the CPU due to a lot of calculations.
I took an i7-2600K and it still would take me several years to finish processing..

A friend told me that I can send massive calc to the GPU. After reading about it online I realized that this is the only possible solution for me.
I took an NVIDIA 470 and tried to use it with several DLL''s with not much of understanding in how it''s done.

Basically, I have a foreach loop that I need to send to the GPU
When it was multicored it was simple - I just changed the syntax to
parallel.Foreach, but to the GPU - I don''t really understand how it''s done without
changing the entire code - I just want to rap it so just part of it
will be send to the GPU.

Any thoughts ??

Please remember I''m new in this - explain me like I''m retarded :)

Many thanks,
Zvi

推荐答案

您好,您是否尝试过阅读 [
Hi, have you tried to read this Cudafy[^] or any of the other exelent articles on CodeProject?

One more thing; if your calculation would take years, i''d take a good look at the calculation itself. If you e.g. are doing matrix calculations and you are creating a new matix every time to store intermediate results you''ll gain very little. The issue would be that the amount of memory allocations is just taking to much time.

Hope this helps,

Cheers, AT


再次问好
抱歉,OriginalGriff和其他人..
我已附加了要发送到GPU的循环.
至于Cudafy,我偶然发现了它,还有其他dll,.microsoft,nvidia,cuda.net等,却一无所知.
我实现了内部循环:foreach(QuotesList中的十进制Quote)占用了大部分处理时间..但是其中的功能写得无懈可击.
回到我的问题,如果我将Parallel.ForEach循环划分给GPU,它将运行得更快吗?如果是这样,它是怎么做的?

请原谅我的新病,非常感谢您的帮助


Hello again
Sorry OriginalGriff, and others..
I''ve attached the loop I would like to send to the GPU.
As for Cudafy, I''ve stumbled upon it, and other dll''s.. microsoft''s, nvidia, cuda.net etc.. and didn''t understand nothing.
I realized the inner loop: foreach (decimal Quote in QuotesList) takes most of the processing time.. but the functions in there are written impeccable.
So back to my question, f I''ll divide the Parallel.ForEach loop to the GPU - would it run faster? and if so, how it''s done ??

Please forgive my newbidity and many thanks for your help


Parallel.ForEach<params10>(Params10List, parallelOptions, Prm10 =>     
{
    SectionParams T1 = new SectionParams();
    T1.TempWeek = TempWeek;
    T1.Counter = -1;
    StrategyData StrategyDataTempT1 = new StrategyData();
    StrategyDataTempT1.WeekResults = new List<decimal>();
    StrategyDataTempT1.Prm10 = Prm10;
    StrategyDataTempT1.Symbol = Symbol;
    StrategyDataTempT1.StrNumber = StrategyNumber;
    StrategyDataTempT1.SubStrNumber = Prm10.SubStrategyNum;
    Strategys StrategyT1 = new Strategys(Point, Spread, Prm10);   //Creates the Strategy here each time with different 'Prm10'.                                                           
    foreach (decimal Quote in QuotesList)  
    {
        T1.Counter++;                                      
        #region //Save weekly results:
        if (T1.TempWeek < DateTimeList[T1.Counter])  //sum of weeks Results :
        {
            SaveWeekResults(StrategyDataTempT1, T1.LastWeekSum);
            T1.LastWeekSum = StrategyDataTempT1.TotalGain;
            T1.TempWeek = T1.TempWeek.AddDays(7);                      
        }
        #endregion //(Save weekly results)
        T1.StrategyRequest = StrategyT1.OperateStrategy(Quote, StrategyNumber);
        #region//Strategy analysis:
        if (T1.StrategyRequest != 0)
        {
            CalculateClosedDeals(Quote, ref Spread, ref T1, T1.StrategyRequest);                                         
            BuySellWithOrCounterDirection(ref StrategyDataTempT1, ref T1, ref QuotesList);
        }
        T1.OpenDealsSum = CalculateOpenDeals(Quote, ref Spread, ref T1);                                              
        StrategyDataTempT1.TotalGain = T1.CloseDralsSum + T1.OpenDealsSum;
        CalcMaxDD(ref T1, StrategyDataTempT1);
        #endregion//(Strategy analysis)
    }
    SaveWeekResults(StrategyDataTempT1, T1.LastWeekSum);
    T1.TempWeek = FirstSaturday;
    StrategyDataTempT1.TotalGain = Math.Round(StrategyDataTempT1.TotalGain, PointRound);   
    StrategyDataTempT1.MaxSizeDeal = T1.MaxSizeDeal;
    StrategyDataTempT1.DealSends = T1.DealSends;
    if (StrategyDataTempT1.MaxDD != 0)
        StrategyDataTempT1.GainToMaxDD = StrategyDataTempT1.TotalGain / StrategyDataTempT1.MaxDD;
    else
        StrategyDataTempT1.GainToMaxDD = 0;

    #region //Calc STDEV:
    if (StrategyDataTempT1.TotalGain != 0)
    {

        T1.Avg = StrategyDataTempT1.WeekResults.Average();
        foreach (decimal WResult in StrategyDataTempT1.WeekResults)
        {
            T1.Value = WResult - T1.Avg;
            T1.sumOfDerivation += ((T1.Value) * (T1.Value));
        }
        T1.DsumOfDerivation = (double)T1.sumOfDerivation;
        StrategyDataTempT1.STDEV = Math.Sqrt((1.0 / (double)StrategyDataTempT1.WeekResults.Count()) * T1.DsumOfDerivation);

    }
    else
        StrategyDataTempT1.STDEV = 0;

    #endregion //(Calc STDEV)

    #region //Save results to List :
    lock (StrategyDataList)
    {
        StrategyDataList.Add(StrategyDataTempT1);
    }
    #endregion //(Save results to List)

});//End of parallel section of T1!   
</decimal></params10>


这篇关于C#中的CUDA问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆