@@ -273,9 +273,53 @@ function compile(@nospecialize(job::CompilerJob))
273
273
push! (ptxas_opts, " --compile-only" )
274
274
end
275
275
276
+ ptx = job. config. params. ptx
276
277
cap = job. config. params. cap
277
278
arch = " sm_$(cap. major)$(cap. minor) "
278
279
280
+ # validate use of parameter memory
281
+ argtypes = filter ([KernelState, job. source. specTypes. parameters... ]) do dt
282
+ ! isghosttype (dt) && ! Core. Compiler. isconstType (dt)
283
+ end
284
+ param_usage = sum (sizeof, argtypes)
285
+ param_limit = 4096
286
+ if cap >= v " 7.0" && ptx >= v " 8.1"
287
+ param_limit = 32764
288
+ end
289
+ if param_usage > param_limit
290
+ msg = """ Kernel invocation uses too much parameter memory.
291
+ $(Base. format_bytes (param_usage)) exceeds the $(Base. format_bytes (param_limit)) limit imposed by sm_$(cap. major)$(cap. minor) / PTX v$(ptx. major) .$(ptx. minor) ."""
292
+
293
+ try
294
+ details = " \n\n Relevant parameters:"
295
+
296
+ source_types = job. source. specTypes. parameters
297
+ source_argnames = Base. method_argnames (job. source. def)
298
+ while length (source_argnames) < length (source_types)
299
+ # this is probably due to a trailing vararg; repeat its name
300
+ push! (source_argnames, source_argnames[end ])
301
+ end
302
+
303
+ for (i, typ) in enumerate (source_types)
304
+ if isghosttype (typ) || Core. Compiler. isconstType (typ)
305
+ continue
306
+ end
307
+ name = source_argnames[i]
308
+ details *= " \n [$(i- 1 ) ] $name ::$typ uses $(Base. format_bytes (sizeof (typ))) "
309
+ end
310
+ details *= " \n "
311
+
312
+ if cap >= v " 7.0" && ptx < v " 8.1" && param_usage < 32764
313
+ details *= " \n Note: use a newer CUDA to support more parameters on your device.\n "
314
+ end
315
+
316
+ msg *= details
317
+ catch err
318
+ @error " Failed to analyze kernel parameter usage; please file an issue with a reproducer."
319
+ end
320
+ error (msg)
321
+ end
322
+
279
323
# compile to machine code
280
324
# NOTE: we use tempname since mktemp doesn't support suffixes, and mktempdir is slow
281
325
ptx_input = tempname (cleanup= false ) * " .ptx"
0 commit comments