/// <summary> /// Casts the supplied value to the specified type /// </summary> /// <param name="value">the value casted to the required type for the parameter</param> /// <returns></returns> public object CastToType(object value) { if (IsArray) { object[] data = (object[])value; return(CLAPI.CreateBuffer(Array.ConvertAll(data, x => CastToType(Converters[(int)DataType], x)), Converters[(int)DataType], MemoryFlag.CopyHostPointer | MemoryFlag.ReadOnly)); } return(CastToType(Converters[(int)DataType], value)); }
/// <summary> /// Loads the source and initializes the CLProgram /// </summary> private void Initialize() { int vnum = GetVectorNum(_genType); string[] lines = TextProcessorAPI.GenericIncludeToSource(".cl", _filePath, _genType, vnum == 0 || vnum == 1 ? "float" : "float" + vnum); Dictionary <string, bool> defs = new Dictionary <string, bool> { { "V_" + vnum, true } }; string source = TextProcessorAPI.PreprocessSource(lines, _filePath, defs); string[] kernelNames = FindKernelNames(source); ClProgramHandle = CLAPI.CreateCLProgramFromSource(source); foreach (string kernelName in kernelNames) { Kernel k = CLAPI.CreateKernelFromName(ClProgramHandle, kernelName); int kernelNameIndex = source.IndexOf(" " + kernelName + " ", StringComparison.InvariantCulture); kernelNameIndex = kernelNameIndex == -1 ? source.IndexOf(" " + kernelName + "(", StringComparison.InvariantCulture) : kernelNameIndex; KernelParameter[] parameter = KernelParameter.CreateKernelParametersFromKernelCode(source, kernelNameIndex, source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1); if (k == null) { ContainedKernels.Add(kernelName, new CLKernel(null, kernelName, parameter)); } else { ContainedKernels.Add(kernelName, new CLKernel(k, kernelName, parameter)); } } }
/// <summary> /// Reinitializes the CL API /// Used by The unit tests when requireing actual CL api calls(e.g. not in NO_CL mode) /// </summary> public static void Reinitialize() { _instance = new CLAPI(); }