private static HlGraphEntry GetHlGraph(MethodInfo Method, int GidParamCount, OpenCLNet.Device device) { HlGraphEntry CacheEntry; if (device == null) { device = OpenCLInterop.GetFirstGpu(); } if (device == null) { device = OpenCLInterop.GetFirstCpu(); } if (device == null) { throw new Exception("No OpenCL Compute Device found in the system!"); } if (hlGraphCache.TryGetValue(device.DeviceID, Method, out CacheEntry)) { return(CacheEntry); } CacheEntry = ConstructKernelHlGraphEntry(Method, GidParamCount); CacheEntry.Device = device; hlGraphCache.SetValue(device.DeviceID, Method, CacheEntry); return(CacheEntry); }
private static string getOpenCLSource(HighLevel.HlGraph HLgraph) { using (StringWriter Srcwriter = new StringWriter()) { OpenCLInterop.WriteOpenCL(HLgraph, Srcwriter); string OpenClSource = Srcwriter.ToString(); if (DumpCode > 2) { System.Console.WriteLine(OpenClSource); } return(OpenClSource); } }
private static void DoInvoke(int[] WorkSize, object Target, HlGraphEntry CacheEntry, InvokeContext ctx, OpenCLNet.Device device) { HighLevel.HlGraph HLgraph = CacheEntry.HlGraph; foreach (KeyValuePair <FieldInfo, HighLevel.ArgumentLocation> Entry in HLgraph.StaticFieldMap) { ctx.PutArgument(Entry.Value, Entry.Key.GetValue(null)); } SetArguments(ctx, Target, HLgraph.RootPathEntry); /* * foreach (KeyValuePair<FieldInfo, HighLevel.ArgumentLocation> Entry in HLgraph.ThisFieldMap) * { * ctx.PutArgument(Entry.Value, Entry.Key.GetValue(Target)); * } * foreach (KeyValuePair<FieldInfo, Dictionary<FieldInfo, HighLevel.ArgumentLocation>> Entry in HLgraph.OuterThisFieldMap) { * object RealThis = Entry.Key.GetValue(Target); * foreach (KeyValuePair<FieldInfo, HighLevel.ArgumentLocation> SubEntry in Entry.Value) { * ctx.PutArgument(SubEntry.Value, SubEntry.Key.GetValue(RealThis)); * } * }*/ foreach (KeyValuePair <HighLevel.ArgumentLocation, HighLevel.ArrayInfo> Entry in HLgraph.MultiDimensionalArrayInfo) { System.Diagnostics.Debug.Assert(Entry.Key.Index >= 0 && Entry.Key.Index < ctx.Arguments.Count); InvokeArgument BaseArrayArg = ctx.Arguments[Entry.Key.Index]; System.Diagnostics.Debug.Assert(BaseArrayArg != null && BaseArrayArg.Value != null && BaseArrayArg.Value.GetType() == Entry.Key.DataType); System.Diagnostics.Debug.Assert(Entry.Key.DataType.IsArray && Entry.Key.DataType.GetArrayRank() == Entry.Value.DimensionCount); System.Diagnostics.Debug.Assert(BaseArrayArg.Value is Array); Array BaseArray = (System.Array)BaseArrayArg.Value; long BaseFactor = 1; for (int Dimension = 1; Dimension < Entry.Value.DimensionCount; Dimension++) { int ThisDimensionLength = BaseArray.GetLength(Entry.Value.DimensionCount - 1 - (Dimension - 1)); BaseFactor *= ThisDimensionLength; ctx.PutArgument(Entry.Value.ScaleArgument[Dimension], (int)BaseFactor); } } ctx.Complete(); OpenCLInterop.CallOpenCLNet(WorkSize, CacheEntry, ctx, HLgraph, device); }
private static void writeOpenClStructs(Hybrid.MsilToOpenCL.HighLevel.HlGraph HLgraph, StringWriter Srcwriter) { Dictionary <Type, int> TypeMarks = new Dictionary <Type, int>(); foreach (HighLevel.ArgumentLocation Argument in HLgraph.Arguments) { if (HLgraph.ValueTypeMap.ContainsKey(Argument.DataType)) { TypeMarks[Argument.DataType] = 1; } else if ((Argument.DataType.IsByRef || Argument.DataType.IsPointer) && HLgraph.ValueTypeMap.ContainsKey(Argument.DataType.GetElementType())) { TypeMarks[Argument.DataType.GetElementType()] = 1; } } foreach (KeyValuePair <Type, int> Entry in TypeMarks) { OpenCLInterop.WriteOpenCL(HLgraph, Entry.Key, Srcwriter); } }
private static string getOpenCLSource(List <HighLevel.HlGraph> List) { using (StringWriter Srcwriter = new StringWriter()) { foreach (HighLevel.HlGraph HLgraph in List) { writeOpenClStructs(HLgraph, Srcwriter); } foreach (HighLevel.HlGraph HLgraph in List) { OpenCLInterop.WriteOpenCL(HLgraph, Srcwriter); } string OpenClSource = Srcwriter.ToString(); if (DumpCode > 2) { System.Console.WriteLine(OpenClSource); } return(OpenClSource); } }