@@ -329,6 +329,10 @@ def get_cutlass_build_flags():
329329 )
330330
331331
332+ def bool_to_on_off (value ):
333+ return "ON" if value else "OFF"
334+
335+
332336# BuildExtension is a subclass of from setuptools.command.build_ext.build_ext
333337class TorchAOBuildExt (BuildExtension ):
334338 def __init__ (self , * args , ** kwargs ) -> None :
@@ -353,16 +357,19 @@ def build_extensions(self):
353357 def build_cmake (self , ext ):
354358 extdir = os .path .abspath (os .path .dirname (self .get_ext_fullpath (ext .name )))
355359
356- if not os .path .exists (self .build_temp ):
357- os .makedirs (self .build_temp )
360+ # Use a unique build directory per CMake extension to avoid cache conflicts
361+ # when multiple extensions use different CMakeLists.txt source directories
362+ ext_build_temp = os .path .join (self .build_temp , ext .name .replace ("." , "_" ))
363+ if not os .path .exists (ext_build_temp ):
364+ os .makedirs (ext_build_temp )
358365
359366 # Get the expected extension file name that Python will look for
360367 # We force CMake to use this library name
361368 ext_filename = os .path .basename (self .get_ext_filename (ext .name ))
362369 ext_basename = os .path .splitext (ext_filename )[0 ]
363370
364371 print (
365- "CMAKE COMMANG " ,
372+ "CMAKE COMMAND " ,
366373 [
367374 "cmake" ,
368375 ext .cmake_lists_dir ,
@@ -384,9 +391,9 @@ def build_cmake(self, ext):
384391 "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir ,
385392 "-DTORCHAO_CMAKE_EXT_SO_NAME=" + ext_basename ,
386393 ],
387- cwd = self . build_temp ,
394+ cwd = ext_build_temp ,
388395 )
389- subprocess .check_call (["cmake" , "--build" , "." ], cwd = self . build_temp )
396+ subprocess .check_call (["cmake" , "--build" , "." ], cwd = ext_build_temp )
390397
391398
392399class CMakeExtension (Extension ):
@@ -772,9 +779,6 @@ def get_extensions():
772779 if build_macos_arm_auto or os .getenv ("BUILD_TORCHAO_EXPERIMENTAL" ) == "1" :
773780 build_options = BuildOptions ()
774781
775- def bool_to_on_off (value ):
776- return "ON" if value else "OFF"
777-
778782 from distutils .sysconfig import get_python_lib
779783
780784 torch_dir = get_python_lib () + "/torch/share/cmake/Torch"
@@ -799,6 +803,21 @@ def bool_to_on_off(value):
799803 )
800804 )
801805
806+ if build_options .build_experimental_mps :
807+ ext_modules .append (
808+ CMakeExtension (
809+ "torchao._C_mps" ,
810+ cmake_lists_dir = "torchao/experimental/ops/mps" ,
811+ cmake_args = (
812+ [
813+ f"-DCMAKE_BUILD_TYPE={ 'Debug' if use_debug_mode () else 'Release' } " ,
814+ f"-DTORCHAO_BUILD_MPS_OPS={ bool_to_on_off (build_options .build_experimental_mps )} " ,
815+ "-DTorch_DIR=" + torch_dir ,
816+ ]
817+ ),
818+ )
819+ )
820+
802821 return ext_modules
803822
804823
0 commit comments