@@ -32,30 +32,30 @@ def _test_multiply(self, shape_x, shape_y, dtype, rtol=1e-5, atol=1e-8):
3232 else :
3333 x_np = np .random .uniform (- 1 , 1 , size = shape_x ).astype (dtype .as_numpy_dtype )
3434 y_np = np .random .uniform (- 1 , 1 , size = shape_y ).astype (dtype .as_numpy_dtype )
35-
35+
3636 x = tf .constant (x_np , dtype = dtype )
3737 y = tf .constant (y_np , dtype = dtype )
38-
38+
3939 # Test on CPU
4040 with tf .device ('/CPU:0' ):
4141 cpu_result = tf .multiply (x , y )
42-
42+
4343 # Test on MUSA
4444 with tf .device ('/device:MUSA:0' ):
4545 musa_result = tf .multiply (x , y )
46-
46+
4747 # Compare results
4848 if dtype in [tf .float16 , tf .bfloat16 ]:
4949 cpu_result_f32 = tf .cast (cpu_result , tf .float32 )
5050 musa_result_f32 = tf .cast (musa_result , tf .float32 )
51- self .assertAllClose (cpu_result_f32 .numpy (),
51+ self .assertAllClose (cpu_result_f32 .numpy (),
5252 musa_result_f32 .numpy (),
53- rtol = rtol ,
53+ rtol = rtol ,
5454 atol = atol )
5555 else :
56- self .assertAllClose (cpu_result .numpy (),
56+ self .assertAllClose (cpu_result .numpy (),
5757 musa_result .numpy (),
58- rtol = rtol ,
58+ rtol = rtol ,
5959 atol = atol )
6060
6161 def testMultiplyBasic (self ):
@@ -102,12 +102,12 @@ def testMultiplyZeroValues(self):
102102 y_data = [[1.0 , 0.0 ], [0.0 , 3.0 ]]
103103 x = tf .constant (x_data , dtype = tf .float32 )
104104 y = tf .constant (y_data , dtype = tf .float32 )
105-
105+
106106 expected = [[0.0 , 0.0 ], [0.0 , 0.0 ]]
107-
107+
108108 with tf .device ('/device:MUSA:0' ):
109109 result = tf .multiply (x , y )
110-
110+
111111 self .assertAllClose (result .numpy (), expected )
112112
113113
@@ -125,6 +125,19 @@ def testMultiplyFastPathHotShapes(self):
125125 with self .subTest (shape_x = shape_x , shape_y = shape_y , dtype = dtype ):
126126 self ._test_multiply (shape_x , shape_y , dtype , rtol = rtol , atol = atol )
127127
128+ def testMultiplyFloat64StaysOnMusa (self ):
129+ x = tf .constant ([2.0 ], dtype = tf .float64 )
130+ y = tf .constant ([3.0 ], dtype = tf .float64 )
131+
132+ with tf .device ('/device:MUSA:0' ):
133+ result = tf .multiply (x , y )
134+
135+ self .assertIn (
136+ 'MUSA' , result .device ,
137+ msg = f"Mul(float64) output landed on { result .device !r} instead of MUSA" )
138+ self .assertEqual (result .dtype , tf .float64 )
139+ self .assertAllClose (result .numpy (), [6.0 ], rtol = 1e-12 , atol = 1e-12 )
140+
128141
129142if __name__ == "__main__" :
130- tf .test .main ()
143+ tf .test .main ()
0 commit comments