Loading files
using Hast.Layer;
using Hast.Samples.SampleAssembly;
using System.Threading.Tasks;
namespace Hast.Samples.Consumer.SampleRunners
{
internal class ParallelAlgorithmSampleRunner : ISampleRunner
{
public void Configure(HardwareGenerationConfiguration configuration) =>
configuration.AddHardwareEntryPointType<ParallelAlgorithm>();
// Note that Hastlayer can figure out how many Tasks will be there to an extent (see comment in
// ParallelAlgorithm) but if it can't, use a configuration like below:
//// configuration.TransformerConfiguration().AddMemberInvocationInstanceCountConfiguration(
//// new MemberInvocationInstanceCountConfigurationForMethod<ParallelAlgorithm>(p => p.Run(null), 0)
//// {
//// MaxDegreeOfParallelism = ParallelAlgorithm.MaxDegreeOfParallelism
//// });
public async Task RunAsync(IHastlayer hastlayer, IHardwareRepresentation hardwareRepresentation, IProxyGenerationConfiguration configuration)
{
var parallelAlgorithm = await hastlayer.GenerateProxyAsync(hardwareRepresentation, new ParallelAlgorithm(), configuration);
_ = parallelAlgorithm.Run(234234, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
_ = parallelAlgorithm.Run(123, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
_ = parallelAlgorithm.Run(9999, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
var sw = System.Diagnostics.Stopwatch.StartNew();
_ = new ParallelAlgorithm().Run(234234, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
sw.Stop();
System.Console.WriteLine("On CPU it took " + sw.ElapsedMilliseconds + "ms.");
}
}
}
b36e59ce0This file is pinned to the selected release. Download the original to open it in your design tool.