private string GetSpecific(KernelMethodInfo kmi) { StringBuilder sb = new StringBuilder(); if (kmi != null) { sb.AppendLine("Parameters : " + kmi.GetParametersString()); } return sb.ToString(); }
private void lbFunctions_SelectedIndexChanged(object sender, EventArgs e) { KernelMethodInfo item = lbFunctions.SelectedItem as KernelMethodInfo; if (item != null) { string text = GetCommon(item as KernelMemberInfo); tbFunctions.Text = text; text = GetSpecific(item); tbFunctions.AppendText(text); } }
/// <summary> /// Does the launch. /// </summary> /// <param name="gridSize">Size of the grid.</param> /// <param name="blockSize">Size of the block.</param> /// <param name="streamId">Stream id, or -1 for non-async.</param> /// <param name="gpuMethodInfo">The gpu method info.</param> /// <param name="arguments">The arguments.</param> protected override void DoLaunch(dim3 gridSize, dim3 blockSize, int streamId, KernelMethodInfo gpuMethodInfo, params object[] arguments) { if (streamId > -1 && !_streams.ContainsKey(streamId)) { _streams.Add(streamId, streamId); } MethodInfo mi = gpuMethodInfo.Method; if (mi == null) { throw new CudafyHostException(CudafyHostException.csX_NOT_SET, gpuMethodInfo.Name); } object instance = mi.IsStatic ? null : Activator.CreateInstance(mi.DeclaringType); if (gpuMethodInfo.IsDummy) { object[] argsCopy = new object[arguments.Length]; for (int i = 0; i < arguments.Length; i++) { if (arguments[i].GetType().IsArray) { var v = TryGetDeviceMemory(arguments[i]) as EmuDevicePtrEx; if (v != null) { if (v.Offset == 0) { argsCopy[i] = v.DevPtr; } else { throw new CudafyHostException(CudafyHostException.csX_NOT_CURRENTLY_SUPPORTED, "Offsets in arrays passed to dummy functions"); } } else { argsCopy[i] = arguments[i]; } } else { argsCopy[i] = arguments[i]; } } mi.Invoke(instance, argsCopy); return; } GGrid grid = new GGrid(gridSize); Dictionary <Array, EmuDevicePtrEx> dic; object[] pList = BuildParameterList2(mi, arguments, out dic); //object[] pListCopy = new object[0]; if (gridSize.z > 1) { throw new CudafyHostException(CudafyHostException.csX_NOT_SUPPORTED, "3D grid sizes"); } if (blockSize.z > 1) { throw new CudafyHostException(CudafyHostException.csX_NOT_SUPPORTED, "3D block sizes"); } for (int x = 0; x < gridSize.x; x++) { for (int y = 0; y < gridSize.y; y++) { int totalSize = blockSize.x * blockSize.y * blockSize.z; Thread[] threads = new Thread[totalSize]; GBlock blk2lnch = new GBlock(grid, blockSize, x, y); int tCtr = 0; int pListLen = pList.Length; for (int tx = 0; tx < blockSize.x; tx++) { for (int ty = 0; ty < blockSize.y; ty++) { GThread ht = new GThread(tx, ty, blk2lnch); object[] pListCopy = new object[pListLen]; for (int pc = 0; pc < pListLen; pc++) { if (pList[pc] is GThread) { pListCopy[pc] = ht; } else { pListCopy[pc] = pList[pc]; } } #warning OPTIMIZATION if there is no synchronize then start and join threads in multiple of processor count - check this in disassembly and put flag in gpuMethodInfo threads[tCtr] = new Thread(() => { mi.Invoke(instance, pListCopy); }); threads[tCtr].Name = string.Format("Grid_{0}_{1}_Thread_{2}_{3}", x, y, tx, ty); threads[tCtr].Start(); //if (ctr % 16 == 0) // Console.WriteLine("Ctr=" + ctr.ToString()); //ctr++; tCtr++; } } for (int i = 0; i < totalSize; i++) { threads[i].Join(); //Console.WriteLine("Thread {0} exited.", threads[i].Name); } } } int iArgs = 0; ParameterInfo[] piArray = mi.GetParameters(); for (int iParams = 0; iParams < piArray.Length; iParams++) { ParameterInfo pi = piArray[iParams]; if (pi.ParameterType == typeof(GThread)) { continue; } else if (iArgs < pList.Length) { object o = pList[iArgs++]; if (!(o is GThread)) { if (o.GetType().IsArray) { if (dic.ContainsKey(o as Array)) { EmuDevicePtrEx ptrEx = dic[o as Array]; DoCopy(o as Array, 0, ptrEx.DevPtr, ptrEx.Offset, ptrEx.TotalSize, pi.ParameterType.GetElementType()); } } } else { iParams--; } } } }