gpgpualeagpu

Accessing IList<T> inside Alea.Gpu.Default.For


I am trying to access values of System.Collections.Generic.IList<T> which is declared outside 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;
        }
    });
}

With reference to one of the questions asked earlier iterate-over-a-collection-of-custom-classes-with-alea-gpu I have also enabled <memory allowNonBlittableMemoryTransfer="true"/> in App.config.

However I am getting an error as

"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]

What could be the possible reason of error? What is the correct way to use values inside Gpu.For ?


Solution

  • Currently, AleaGPU only works with array. List usually require dynamic memory allocation, such as add element, which is not efficient in GPU.