@@ -54,9 +54,14 @@ public interface ComputeKernel extends AutoCloseable {
5454 * <li>Architecture-specific tuning: {@code "-D__GCN_REV__=2"}</li>
5555 * </ul>
5656 *
57+ * <p><b>Security Note:</b> Build options are passed directly to the backend compiler without
58+ * sanitization. Ensure options originate from trusted sources only to prevent compiler-based
59+ * denial-of-service or unexpected behavior.
60+ *
5761 * @param source Kernel source code (Metal or OpenCL)
5862 * @param entryPoint Kernel entry point function name
59- * @param buildOptions Compiler flags and preprocessor defines (null or empty for defaults)
63+ * @param buildOptions Compiler flags and preprocessor defines (null or empty for defaults).
64+ * Passed directly to the backend compiler without validation.
6065 * @throws KernelCompilationException if compilation fails
6166 * @see #recompile(String, String, String)
6267 */
@@ -69,8 +74,7 @@ default void compile(String source, String entryPoint, String buildOptions)
6974 * Recompile an already-compiled kernel with different build options.
7075 *
7176 * <p>Enables runtime GPU auto-tuning by recompiling kernels with different optimization
72- * parameters without clearing existing kernel state. Useful for performance experiments
73- * and adaptive optimization strategies.
77+ * parameters. Useful for performance experiments and adaptive optimization strategies.
7478 *
7579 * <h3>Recompilation Workflow:</h3>
7680 * <pre>{@code
@@ -83,8 +87,13 @@ default void compile(String source, String entryPoint, String buildOptions)
8387 * kernel.execute(globalSize); // Compare performance
8488 * }</pre>
8589 *
86- * <p><b>Note:</b> Recompilation creates a fresh kernel. The old kernel reference remains
87- * valid until explicitly closed, allowing multiple kernel variants to coexist.
90+ * <p><b>Note:</b> Recompilation releases the old kernel and program resources, then compiles
91+ * a fresh kernel. The kernel object itself remains valid and usable after recompilation.
92+ *
93+ * <p><b>Thread Safety:</b> During recompilation, {@link #isCompiled()} may briefly return false
94+ * as resources are released and replaced. Concurrent kernel execution from other threads during
95+ * recompilation will fail with IllegalStateException. Callers must ensure exclusive access to
96+ * the kernel object during recompilation.
8897 *
8998 * @param source Kernel source code (must match original source for consistency)
9099 * @param entryPoint Kernel entry point function name
0 commit comments