/// <summary> /// PTXs for configuration. /// </summary> /// <param name="compiler">The compiler.</param> /// <param name="config">The configuration.</param> /// <returns>System.Byte[].</returns> /// <exception cref="InvalidOperationException"> /// All config arguments must be provided. Required: " + allRequired /// or /// Config provides some unnecessary arguments. Required: " + allRequired /// </exception> public byte[] PtxForConfig(CudaCompiler compiler, KernelConfig config) { byte[] cachedResult; if (ptxCache.TryGetValue(config, out cachedResult)) { return(cachedResult); } if (!requiredConfigArgs.All(config.ContainsKey)) { var allRequired = string.Join(", ", requiredConfigArgs); throw new InvalidOperationException("All config arguments must be provided. Required: " + allRequired); } // Checking this ensures that there is only one config argument that can evaluate to the same code, // which ensures that the ptx cacheing does not generate unnecessary combinations. Also, a mismatch // occurring here probably indicates a bug somewhere else. if (!config.Keys.All(requiredConfigArgs.Contains)) { var allRequired = string.Join(", ", requiredConfigArgs); throw new InvalidOperationException("Config provides some unnecessary arguments. Required: " + allRequired); } //return new DeviceKernelCode(config.ApplyToTemplate(templateCode), requiredHeaders.ToArray()); var finalCode = config.ApplyToTemplate(templateCode); var result = compiler.CompileToPtx(finalCode, requiredHeaders.ToArray()); ptxCache.Add(config, result); return(result); }
public override bool Equals(object obj) { KernelConfig o = obj as KernelConfig; if (o == null) { return(false); } if (values.Count != o.values.Count) { return(false); } foreach (KeyValuePair <string, string> kvp in values) { if (values.TryGetValue(kvp.Key, out string oValue)) { if (!kvp.Value.Equals(oValue)) { return(false); } } else { return(false); } } return(true); }
public byte[] PtxForConfig(CudaCompiler compiler, KernelConfig config) { if (ptxCache.TryGetValue(config, out byte[] cachedResult))