gpgpu - 在 Alea.Gpu.Default.For 中访问 IList<T>

标签 gpgpu aleagpu

我正在尝试访问 System.Collections.Generic.IList<T> 的值在Alea.Gpu.Default.For 之外声明.

[GpuManaged]
private void Evaluate_Caching(IList<TGenome> genomeList)
{
    var gpu = Gpu.Default;

    gpu.For(0, genomeList.Count - 1, i =>
    {
        TGenome genome = genomeList[i];
        TPhenome phenome = (TPhenome)genome.CachedPhenome;
        if (null == phenome)
        {   // Decode the phenome and store a ref against the genome.
            phenome = _genomeDecoder.Decode(genome);
            genome.CachedPhenome = phenome;
        }

        if (null == phenome)
        {   // Non-viable genome.
            genome.EvaluationInfo.SetFitness(0.0);
            genome.EvaluationInfo.AuxFitnessArr = null;
        }
        else
        {
            FitnessInfo fitnessInfo = _phenomeEvaluator.Evaluate(phenome);
            genome.EvaluationInfo.SetFitness(fitnessInfo._fitness);
            genome.EvaluationInfo.AuxFitnessArr = fitnessInfo._auxFitnessArr;
        }
    });
}

引用之前提出的问题之一 iterate-over-a-collection-of-custom-classes-with-alea-gpu我还启用了 <memory allowNonBlittableMemoryTransfer="true"/>App.config .

但是我得到了一个错误

"Cannot get field "genomeList".
Possible reasons:
-> The field type is not supported.
-> In closure class, the field doesn't have [GpuParam] attribute.
Diagnostics:
-> Struct: ref(dyn{ i32 }(m:<Evaluate_Caching>b__0)):_O_
-> FieldName: genomeList
Source location stack:
-> in E:\_turingProjects\_csProjects\Gpu_Project\GpuParallelGenomeListEvaluator.cs(183,17-183,48)
-> at Evaluators.GpuParallelGenomeListEvaluator`2+<>c__DisplayClass17_0[SharpNeat.Genomes.Neat.NeatGenome,SharpNeat.Phenomes.IBlackBox].[Void <Evaluate_Caching>b__0(Int32)]
-> at Alea.Parallel.Device.DeviceFor.[Void Kernel(Int32, Int32, System.Action`1[System.Int32])]
-> at defining runtime64 (sm50,64bit)
Loading method as kernel:
-> Method: Alea.Parallel.Device.DeviceFor.[Void Kernel(Int32, Int32, System.Action`1[System.Int32])]
-> InstanceOpt: <None>
-> Argument.#0: 0
-> Argument.#1: 1999
-> Argument.#2: System.Action`1[System.Int32]

错误的可能原因是什么?在 Gpu.For 中使用值的正确方法是什么?

最佳答案

目前,AleaGPU 仅适用于数组。 List 通常需要动态分配内存,例如添加元素,这在 GPU 中效率不高。

关于gpgpu - 在 Alea.Gpu.Default.For 中访问 IList<T>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885135/

相关文章:

c# - aleagpu 抛出的 TypeInitializationException

c# - AleaGPU C# 中的高阶函数

cuda - 为什么NVENC示例同时使用cuMemcpyHtoD和cuMemcpy2D复制YUV数据?

python - 了解tensorflow中的设备分配、并行性(tf.while_loop)和tf.function

c++ - 如何在 GPU(最好是 CUDA)上对两个数据容器执行关系连接?

cuda - 在 NVIDIA GPU 中,warp 如何跨内核进行分区?

c++ - 基于 GPU 的 N^2 比较

c# - 在 Alea.GPU 中传递超过 16 个内核参数