diff --git a/torch/_inductor/codegen/cpp_wrapper_cpu.py b/torch/_inductor/codegen/cpp_wrapper_cpu.py index 08c6a586e986..1152bf4dce2c 100644 --- a/torch/_inductor/codegen/cpp_wrapper_cpu.py +++ b/torch/_inductor/codegen/cpp_wrapper_cpu.py @@ -1503,12 +1503,19 @@ class CppWrapperCpu(PythonWrapperCodegen): # This is why writeline needs to explicitly passed in as a parameter. var = f"int_array_{next(self.int_array_id)}" ctype = "int64_t" - if var not in self.declared_int_array_vars: - self.declared_int_array_vars.add(var) + if int_array == "{}": + # An array of unknown bound cannot be initialized with {}. if known_statically: - writeline(f"static constexpr {ctype} {var}[] = {int_array};") + writeline(f"static constexpr {ctype} *{var}=nullptr;") else: - writeline(f"const {ctype} {var}[] = {int_array};") + writeline(f"const {ctype} *{var}=nullptr;") + else: + if var not in self.declared_int_array_vars: + self.declared_int_array_vars.add(var) + if known_statically: + writeline(f"static constexpr {ctype} {var}[] = {int_array};") + else: + writeline(f"const {ctype} {var}[] = {int_array};") return var def make_buffer_allocation(self, buffer):