1212# file gpu_param_header_generator.cmake
1313# author Gabriele Cimador
1414
15- function (generate_macros json_content output types arch_list)
15+ function (generate_macros json_content output types arch_list arch_list_output )
1616 foreach (arch IN LISTS arch_list)
17- set (${output} _ ${arch} "" )
17+ set (OUTPUT_TMP_ ${arch} "" )
1818 endforeach ()
19+ set (arch_list_output_tmp)
20+ list (FIND arch_list "ALL" do_all_architectures)
1921 foreach (TYPE IN LISTS types)
2022 string (JSON n_params LENGTH "${json_content} " "${TYPE} " )
2123 math (EXPR last "${n_params} - 1" )
@@ -28,7 +30,14 @@ function(generate_macros json_content output types arch_list)
2830 if (arch STREQUAL "default_cpu" AND NOT TYPE STREQUAL "PAR" )
2931 message (FATAL_ERROR "Bogus entry ${param_name} for ${arch} " )
3032 endif ()
31- list (FIND arch_list "${arch} " list_idx)
33+ if (do_all_architectures GREATER -1)
34+ if (arch_list_output AND NOT arch MATCHES ^default)
35+ list (APPEND arch_list_output_tmp "${arch} " )
36+ endif ()
37+ set (list_idx 0)
38+ else ()
39+ list (FIND arch_list "${arch} " list_idx)
40+ endif ()
3241 if (list_idx GREATER -1)
3342 string (JSON param_values GET "${JSON_CONTENT} " "${TYPE} " "${param_name} " "${arch} " )
3443 if (TYPE STREQUAL "LB" )
@@ -45,17 +54,22 @@ function(generate_macros json_content output types arch_list)
4554 set (MACRO_DEFINITION "#define ${MACRO_NAME} ${vals} " )
4655 if (arch MATCHES ^default)
4756 # fallback defaults are wrapped in #ifndef
48- string (APPEND ${output} _ ${arch} "#ifndef ${MACRO_NAME} \n ${MACRO_DEFINITION} \n #endif\n\n " )
57+ string (APPEND OUTPUT_TMP_ ${arch} "#ifndef ${MACRO_NAME} \n ${MACRO_DEFINITION} \n #endif\n\n " )
4958 else ()
50- string (APPEND ${output} _ ${arch} "${MACRO_DEFINITION} \n " )
59+ string (APPEND OUTPUT_TMP_ ${arch} "${MACRO_DEFINITION} \n " )
5160 endif ()
5261 endif ()
5362 endforeach ()
5463 endforeach ()
5564 endforeach ()
5665 foreach (arch IN LISTS arch_list)
57- set (${output} _${arch} "${${output} _ ${arch} }" PARENT_SCOPE)
66+ set (${output} _${arch} "${OUTPUT_TMP_ ${arch} }" PARENT_SCOPE)
5867 endforeach ()
68+ if (arch_list_output)
69+ list (REMOVE_DUPLICATES arch_list_output_tmp)
70+ list (SORT arch_list_output_tmp)
71+ set (${arch_list_output} "${arch_list_output_tmp} " PARENT_SCOPE)
72+ endif ()
5973endfunction ()
6074
6175function (generate_gpu_param_header GPU_ARCH OUT_HEADER)
@@ -78,7 +92,14 @@ function(generate_gpu_param_header GPU_ARCH OUT_HEADER)
7892 set (TYPES CORE LB PAR)
7993 # Per architecture definitions
8094 set (_first TRUE )
81- generate_macros("${JSON_CONTENT} " TMP_OUTPUT "${TYPES} " "${ARCH_LIST} ;default;default_cpu" )
95+ generate_macros("${JSON_CONTENT} " TMP_OUTPUT "${TYPES} " "${ARCH_LIST} ;default;default_cpu" "JSON_ARCHITECTURES" )
96+ list (FIND ARCH_LIST "ALL" do_all_architectures)
97+ if (ARGC GREATER 2)
98+ set (${ARGV2} "${JSON_ARCHITECTURES} " PARENT_SCOPE)
99+ endif ()
100+ if (do_all_architectures GREATER -1)
101+ set (ARCH_LIST ${JSON_ARCHITECTURES} )
102+ endif ()
82103 foreach (ARCH IN LISTS ARCH_LIST)
83104 if (_first)
84105 file (APPEND "${TMP_HEADER} " "#if defined(GPUCA_GPUTYPE_${ARCH} )\n\n " )
@@ -98,7 +119,7 @@ function(generate_gpu_param_header GPU_ARCH OUT_HEADER)
98119 file (APPEND "${TMP_HEADER} " "#endif // defined(GPUCA_GPUCODE) && !defined(GPUCA_GPUCODE_GENRTC) && !defined(GPUCA_GPUCODE_NO_LAUNCH_BOUNDS)\n\n " )
99120
100121 # CPU fallback
101- file (APPEND "${TMP_HEADER} " "#ifndef GPUCA_GPUCODE_GENRTC //Defaults for non-LB parameters also for CPU fallback\n\n " )
122+ file (APPEND "${TMP_HEADER} " "#ifndef GPUCA_GPUCODE_GENRTC // Defaults for non-LB parameters also for CPU fallback\n\n " )
102123 file (APPEND "${TMP_HEADER} " ${TMP_OUTPUT_default_cpu} )
103124 file (APPEND "${TMP_HEADER} " "\n #endif // GPUCA_GPUCODE_GENRTC\n " )
104125
0 commit comments