VS编译含[GpuManaged]属性代码时出现Fody/Alea: TODO Transform: ILLabel错误
Fody/Alea: TODO Transform: ILLabel Error with [GpuManaged] Attribute
我之前碰到过一模一样的编译错误,在Visual Studio里编译包含嵌套条件和continue语句的GPU托管方法时,Fody/Alea会抛出TODO Transform: ILLabel错误。
重现代码
static void Main(string[] args) { var gpu = Gpu.Default; gpu.For(0, 100, idx => Do(idx)); Console.ReadKey(); } [GpuManaged] public static void Do(int idx) { bool isTrue = false; bool one = true; bool two = true; for (int i = 0; i < 10; i++) { if (isTrue) { if (one) continue; isTrue = false; } else { if (two) continue; isTrue = true; } } }
触发条件
这个错误只会在Do方法添加[GpuManaged]属性时重现,如果移除该属性,代码可以正常编译通过。
排查方向
- 这个问题大概率和Alea的IL转换逻辑相关,嵌套
if搭配continue的结构可能让它的解析器无法正确处理IL标签(ILLabel) - 可以尝试扁平化
Do方法里的条件逻辑,比如合并嵌套的if语句,看看能否绕过这个转换错误 - 确认你使用的Alea和Fody版本是否为最新稳定版,这类IL转换的bug通常会在后续版本中得到修复
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

