@@ -63,7 +63,7 @@ def compile_cuda_script( # # noqa: C901
6363 arch: Architecture to compile for. If None, uses `native`
6464 include_dirs: additional include directories to supply to nvcc
6565 verbose: whether to print progress or be silent
66-
66+ seed: Seed value to use for generating test cases
6767 Returns:
6868 A `CompileResult` that summarizes the compilation process.
6969
@@ -125,11 +125,12 @@ def compile_cuda_script( # # noqa: C901
125125 )
126126
127127
128- def run_program (args : list [str ]) -> RunResult :
128+ def run_program (args : list [str ], seed : int ) -> RunResult :
129129 # set up a pipe so the tester can communicate its verdict with us
130130 env = os .environ .copy ()
131131 pipe_read , pipe_write = os .pipe ()
132132 env ["POPCORN_FD" ] = str (pipe_write )
133+ env ["POPCORN_SEED" ] = str (seed )
133134
134135 execution_start_time = time .perf_counter ()
135136 run_process = subprocess .run (
@@ -173,6 +174,7 @@ def run_cuda_script( # # noqa: C901
173174 headers : dict [str , str ] = None ,
174175 arch : int = None ,
175176 include_dirs : list [str ] = None ,
177+ seed : int = 42 ,
176178) -> tuple [CompileResult , RunResult ]:
177179 """
178180 Executes the provided CUDA kernel in an isolated environment
@@ -184,6 +186,7 @@ def run_cuda_script( # # noqa: C901
184186 compile command.
185187 arch: The arch code for the compute/sm versions. If None, native arch is used.
186188 include_dirs: Additional include directories, e.g., for thunderkittens/cutlass etc
189+ seed: Random seed to initialize the RNG for testing
187190
188191 Returns:
189192 tuple[CompileResult, RunResult]: CUDA compile/eval result information
@@ -218,9 +221,6 @@ def run_cuda_script( # # noqa: C901
218221 result = {},
219222 )
220223
221- run_result = run_program (["./eval.out" ])
222- return compile_result , run_result
223-
224224 # cleaning up all source files _before_ we let the user code run, just in
225225 # case there's something in there that the user isn't supposed to snoop
226226 finally :
@@ -229,25 +229,15 @@ def run_cuda_script( # # noqa: C901
229229 if os .path .exists (f ):
230230 os .remove (f )
231231
232- if not compile_result .success :
233- return compile_result , RunResult (
234- success = False ,
235- command = "" ,
236- stdout = "" ,
237- stderr = "" ,
238- exit_code = - 1 ,
239- duration = 0.0 ,
240- result = {},
241- )
242-
243- run_result = run_program (["./eval.out" ])
232+ run_result = run_program (["./eval.out" ], seed = seed )
244233 return compile_result , run_result
245234
246235
247236def run_pytorch_script ( # noqa: C901
248237 sources : dict [str , str ],
249238 main : str ,
250239 arch : int = None ,
240+ seed : int = 42 ,
251241) -> RunResult :
252242 """
253243 Executes the provided PyTorch GPU kernel in an isolated environment
@@ -256,6 +246,7 @@ def run_pytorch_script( # noqa: C901
256246 sources: Files to generate
257247 main: Which file to run. Must be one of the keys in sources.
258248 arch: The arch code for the compute/sm versions.
249+ seed: Random seed to initialize the RNG for testing
259250
260251 Returns:
261252 RunResult
@@ -266,7 +257,7 @@ def run_pytorch_script( # noqa: C901
266257 # Write submission files to directory
267258 for source , content in sources .items ():
268259 Path (source ).write_text (content )
269- return run_program (["python" , main ])
260+ return run_program (["python" , main ], seed = seed )
270261
271262 finally :
272263 for f in sources .keys ():
0 commit comments