我正在运行一些使用的C#代码,System.Numerics.Vector<T>但据我所知,我没有得到SIMD内在函数的全部好处.我正在使用Visual Studio Community 2015和Update 1,而我的clrjit.dll是v4.6.1063.1.
我正在使用英特尔酷睿i5-3337U处理器,它实现了AVX指令集扩展.因此,我想,我应该能够在256位寄存器上执行大多数SIMD指令.例如,拆卸中应包含的指令vmovups,vmovupd,vaddups,等...,并且Vector<float>.Count应该返回8,Vector<double>.Count应该是4,等等......但是,这不是我所看到的.
相反,我的拆卸包含指令等movups,movupd,addups等...以下代码:
WriteLine($"{Vector<byte>.Count} bytes per operation");
WriteLine($"{Vector<float>.Count} floats per operation");
WriteLine($"{Vector<int>.Count} ints per operation");
WriteLine($"{Vector<double>.Count} doubles per operation");
Run Code Online (Sandbox Code Playgroud)
生产:
16 bytes per operation
4 floats per operation
4 ints per operation
2 doubles per operation
Run Code Online (Sandbox Code Playgroud)
我哪里错了?要查看所有项目设置等,可在此处获得该项目.
我有一个用于部署Azure Function应用程序的ARM模板(包括在下面)。我用以下方法部署它:
az group deployment create --resource-group my-group --template-file my-function-app.json
Run Code Online (Sandbox Code Playgroud)
这可行,然后我可以使用VS Code插件或Azure Functions Core工具成功部署我的功能。
但是,如果我随后重新部署ARM模板(例如,更新应用程序设置),则会丢失我的功能,需要再次重新部署它们。这是预期的行为吗?通过ARM模板部署Web应用程序时,这不是我观察到的。为功能应用程序部署ARM模板以保留我已部署的功能时,我可以做些特定的事情吗?
my-function-app.json:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
...
},
"variables": {
...
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('collectorFunctionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"siteConfig": {
"appSettings": [
{
...
}
]
}
}
}
],
"outputs": {}
}
Run Code Online (Sandbox Code Playgroud) 我已经注意到,如果有一个List<T>(或其他几种类型),然后按下.我得到的智能感知建议Length
如果我选择Length那么实际键入的是什么Count
我可以看出为什么会发生这种情况,没有Length属性List<T>,如果我正在寻找它,我可能想要Count.我的问题是,Visual Studio如何知道这样做?我在List<T>类中或其他任何编码Length为别名的地方都看不到任何东西Count.
我正在测试使用SIMU指令和RyuJIT可以得到什么样的加速,我看到了一些我不期望的反汇编指令.我立足代码这个博客帖子从RyuJIT队的凯文·弗雷,以及相关的帖子在这里.这是功能:
static void AddPointwiseSimd(float[] a, float[] b) {
int simdLength = Vector<float>.Count;
int i = 0;
for (i = 0; i < a.Length - simdLength; i += simdLength) {
Vector<float> va = new Vector<float>(a, i);
Vector<float> vb = new Vector<float>(b, i);
va += vb;
va.CopyTo(a, i);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在查询的反汇编部分将数组值复制到Vector<float>.大部分的反汇编与Kevin和Sasha的帖子类似,但我强调了一些额外的指令(以及我的混淆注释),这些指令没有出现在他们的反汇编中:
;// Vector<float> va = new Vector<float>(a, i);
cmp eax,r8d ; <-- Unexpected - Compare a.Length to i?
jae 00007FFB17DB6D5F ; <-- Unexpected - Jump to …Run Code Online (Sandbox Code Playgroud) Why does the first call to Foo below compile but the second one results in an ambiguous invocation compiler error?
(using c# 7.2)
private static void AmbiguousAsyncOverload() {
Foo(() => Bar()); // This is OK
//Foo(Bar); // Error, ambiguous overload
}
private static void Foo(Func<int> func) {
func();
}
private static void Foo(Func<string> func) {
func();
}
private static int Bar() {
return 4;
}
Run Code Online (Sandbox Code Playgroud)
如果我删除的first(Func<int>)实现Foo,并因此消除了歧义的可能性,则编译器(正确)报告Bar没有正确的签名要传递给Foo,这意味着它具有足够的信息来解决歧义。
我会理解,如果编译器没有在重载解析期间查看返回值,因此两个调用都失败了,但是我的问题是,为什么一个调用编译正常,而另一个调用没有编译正常?
我有一个10000个随机数(mod 100)的向量,我想计算两个数字中有多少对加起来等于100。我编写了以下内容:
auto noPairsSumTo100 = 0;
const auto itEnd = end(myNums);
for (auto it1 = begin(myNums); it1 != itEnd ; ++it1) {
for (auto it2 = it1; it2 != itEnd ; ++it2) {
if (*it1 + *it2 == 100) {
noPairsSumTo100 ++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的机器上,以调试模式运行大约需要21.6秒。如果我将_ITERATOR_DEBUG_LEVEL = 0设置(将_SECURE_SCL和_HAS_ITERATOR_DEBUGGING都设置为0),则执行时间将减少到9.5秒。更换!=比较用<进一步减少了的时间到〜8.5秒。
如果我通过对向量进行索引来实现相同的算法,如下所示:
auto noPairsSumTo100 = 0;
const auto itEnd = end(myNums);
for (auto index1 = 0; index1 < noTerms; ++index1) {
for (auto index2 = index1; index2 < noTerms; …Run Code Online (Sandbox Code Playgroud) 我一直在研究SIMD算法在C#和C++中的优势,发现在很多情况下,在AVX处理器上使用128位寄存器比在AVX2处理器上使用256位寄存器提供了更好的改进,但我不知道明白为什么.
通过改进,我的意思是SIMD算法相对于同一台机器上的非SIMD算法的加速.
如何编写 JOOQ 查询来连接“with”子句中的字段?
例如,我尝试过:
create.with("a").as(select(
val(1).as("x"),
val("a").as("y")
))
.select()
.from(tableByName("a")
.join(ANOTHER_TABLE)
.on(ANOTHER_TABLE.ID.eq(tableByName("a").field("x")))
.fetch();
Run Code Online (Sandbox Code Playgroud)
但是,由于编译器不知道 tableByName("a").field("x") 的类型,因此无法解析要使用哪个 eq() 方法。鉴于我知道类型,有没有办法可以明确提供它?或者我应该采取另一种方法从“with”子句加入字段?
我有一个double小数点后的17位数,即:
double myDouble = 0.12345678901234567;
Run Code Online (Sandbox Code Playgroud)
如果我把它转换成decimal这样的:
decimal myDecimal = Convert.ToDecimal(myDouble);
Run Code Online (Sandbox Code Playgroud)
然后根据文档将值myDecimal四舍五入为Convert.ToDecimal15位数(即0.0123456789012345).我的问题是,为什么要进行这种舍入?
我明白,如果我的原始数字可以准确地表示在基数10中并且我试图将其存储为a double,那么我们只能对前15位数有信心.最后两位数将受到舍入误差的影响.但是,这是一个基础10偏见的观点.我的数字可以用a更准确地表示double,我希望将其转换decimal为尽可能保持尽可能准确的数字.
不应Convert.ToDecimal旨在尽量减少之间的区别myDouble和(double)Convert.ToDecimal(myDouble)?