@@ -110,6 +110,60 @@ public static string GetModelVariantPath(string executableFolder, ModelVariant v
110110 return modelPath ;
111111 }
112112
113+ /// <summary>
114+ /// Generate a device-specific compiled model path.
115+ /// Encodes EP policy/name, device type, and performance mode into the filename
116+ /// so that compiled models for different device configurations don't collide.
117+ /// </summary>
118+ public static string GenerateCompiledModelPath ( string modelPath , string executableFolder , Options options )
119+ {
120+ // If user explicitly specified --compiled_output, use it as-is
121+ if ( ! string . IsNullOrEmpty ( options . OutputPath ) )
122+ {
123+ return options . OutputPath . Contains ( Path . DirectorySeparatorChar ) ?
124+ options . OutputPath : Path . Combine ( executableFolder , options . OutputPath ) ;
125+ }
126+
127+ string baseName = Path . GetFileNameWithoutExtension ( modelPath ) ;
128+ string suffix = BuildDeviceSuffix ( options ) ;
129+
130+ string fileName = $ "{ baseName } _ctx{ suffix } .onnx";
131+ Console . WriteLine ( $ "Compiled model path: { Path . Combine ( executableFolder , fileName ) } ") ;
132+ return Path . Combine ( executableFolder , fileName ) ;
133+ }
134+
135+ /// <summary>
136+ /// Build a device-identifying suffix for the compiled model filename.
137+ /// </summary>
138+ private static string BuildDeviceSuffix ( Options options )
139+ {
140+ var parts = new List < string > ( ) ;
141+
142+ if ( options . EpPolicy . HasValue )
143+ {
144+ parts . Add ( options . EpPolicy . Value . ToString ( ) ) ;
145+ }
146+ else if ( ! string . IsNullOrEmpty ( options . EpName ) )
147+ {
148+ parts . Add ( options . EpName ) ;
149+
150+ // Try to determine device type
151+ string ? deviceType = options . DeviceType ;
152+
153+ if ( ! string . IsNullOrEmpty ( deviceType ) )
154+ {
155+ parts . Add ( deviceType ) ;
156+ }
157+ }
158+
159+ if ( options . PerfMode != PerformanceMode . Default )
160+ {
161+ parts . Add ( options . PerfMode . ToString ( ) ) ;
162+ }
163+
164+ return parts . Count > 0 ? "_" + string . Join ( "_" , parts ) : "" ;
165+ }
166+
113167 /// <summary>
114168 /// Resolve model paths with intelligent variant selection
115169 /// </summary>
@@ -192,8 +246,7 @@ public static string GetModelVariantPath(string executableFolder, ModelVariant v
192246 modelPath = GetModelVariantPath ( executableFolder , variant ) ;
193247 }
194248
195- string compiledModelPath = options . OutputPath . Contains ( Path . DirectorySeparatorChar ) ?
196- options . OutputPath : Path . Combine ( executableFolder , options . OutputPath ) ;
249+ string compiledModelPath = GenerateCompiledModelPath ( modelPath , executableFolder , options ) ;
197250
198251 if ( ! File . Exists ( labelsPath ) )
199252 {
@@ -225,8 +278,7 @@ public static (string modelPath, string compiledModelPath, string labelsPath) Re
225278 modelPath = GetModelVariantPath ( executableFolder , options . Variant ) ;
226279 }
227280
228- string compiledModelPath = options . OutputPath . Contains ( Path . DirectorySeparatorChar ) ?
229- options . OutputPath : Path . Combine ( executableFolder , options . OutputPath ) ;
281+ string compiledModelPath = GenerateCompiledModelPath ( modelPath , executableFolder , options ) ;
230282
231283 string labelsPath = Path . Combine ( executableFolder , "SqueezeNet.Labels.txt" ) ;
232284
0 commit comments