- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一个小的测试函数,它的行为与我想要的不一样。
基本上,它应该读取一个数组并写回它的内容(稍后,当它起作用时,它应该做更多,但现在即使这样也会失败)。
调试 GPU 代码时,我看到前几次迭代(以某种方式并行执行......这对 GPU 来说可能有意义,但在调试时让我感到惊讶)工作正常......但是,在 1-2 之后Debug-Continues (F5),一些先前正确设置的值被 0 覆盖。我不太明白.. 当我再次在 CPU 上时,许多值是 0,即使它们不应该是 0(基本上,它们应该有原始数据,这是一个简单的测试序列)。
#include "stdafx.h"
#include <amp.h>
typedef unsigned char byte;
using namespace concurrency;
void AMPChangeBrightnessContrastWrapper2(byte* a, int len, float brightness, float contrast)
{
array_view<unsigned int> dst(len/4, (unsigned int*)a);
//dst.discard_data();
parallel_for_each(dst.extent, [=](index<1> idx) restrict(amp)
{
// split into bytes (in floats)
float temp1 = (dst[idx]) - (dst[idx] >> 8) * 256;
// this completely fails! float temp1 = dst[idx] & 0xFF;
float temp2 = (dst[idx] >> 8) - (dst[idx] >> 16) * 256;
float temp3 = (dst[idx] >> 16) - (dst[idx] >> 24) * 256;
float temp4 = (dst[idx] >> 24);
// convert back to int-array
dst[idx] = (int)(temp1 + temp2 * 256 + temp3 * 65536 + temp4 * 16777216);
});
//dst.synchronize();
}
int _tmain(int argc, _TCHAR* argv[])
{
const int size = 30000;
byte* a = new byte[size];
// generate some unique test sequence.. first 99 numbers are just 0..98
for (int i = 0; i < size; ++i)
a[i] = (byte)((i + i / 99) % 256);
AMPChangeBrightnessContrastWrapper2(a, size, -10.0f, 1.1f);
for (int i = 0; i < 50; ++i)
printf("%i, ", a[i]);
char out[20];
scanf_s("%s", out);
return 0;
}
如此简单(计划)的步骤:
如果您想知道..那应该是颜色值..
结果是:
输出是(但应该只是从 0 开始递增的数字):
0, 1, 2, 3, 0, 5, 6, 7, 0, 9, 10, 11, 16, 13, 14, 15, 0, 17, 18, 19, 32, 21, 22, 23, 32, 25, 26, 27, 32, 29, 30, 31, 0, 33, 34, 35, 64, 37, 38, 39, 64, 41, 42, 43, 64, 45, 46, 47, 64, 49,
问题:
最佳答案
•I suppose I cannot create an array_view of bytes, I have to use ints or floats?
您不能创建字节数组或数组 View 。 C++ AMP 仅支持有限的 C++ 类型子集。您可以使用纹理而不是数组 View 。对于图像处理,这有几个优点,尤其是打包和解包要快得多,因为它是由 GPU 的硬件实现的。请参阅下面的完整示例。
•commenting out the .synchronize in the end did not change anything - how come?
您不需要 dst.synchronize()
,因为 dst array_view
超出范围,这会导致数据隐式同步回 CPU 内存。顺便说一下,你不应该在函数的开头调用 dst.discard_data()
因为如果你这样做将意味着来自 a
的数据不会被复制到 GPU .
这是一个使用纹理<>的实现。注意事项:
还有代码...
void AMPChangeBrightnessContrastWrapper3(const byte* a, const int len,
const float brightness, const float contrast)
{
const int pixel_len = len / 4;
graphics::texture<graphics::uint_4, 1> inputTx(pixel_len, a, len, 8u);
graphics::texture<graphics::uint_4, 1> outputTx(pixel_len, 8u);
graphics::writeonly_texture_view<graphics::uint_4, 1> outputTxVw(outputTx);
parallel_for_each( outputTxVw.extent, [=, &inputTx, &outputTx](index<1> idx)
restrict(amp)
{
const graphics::uint_4 v = inputTx[idx];
float tmp = static_cast<float>(v.r);
tmp = (tmp - 128) * contrast + brightness + 128;
tmp = direct3d::clamp(tmp, 0.0f, 255.0f);
const unsigned int temp1_ = static_cast<unsigned int>(tmp);
tmp = static_cast<float>(v.g);
tmp = (tmp - 128) * contrast + brightness + 128;
tmp = direct3d::clamp(tmp, 0.0f, 255.0f);
const unsigned int temp2_ = static_cast<unsigned int>(tmp);
tmp = static_cast<float>(v.b);
tmp = (tmp - 128) * contrast + brightness + 128;
tmp = direct3d::clamp(tmp, 0.0f, 255.0f);
const unsigned int temp3_ = static_cast<unsigned int>(tmp);
tmp = static_cast<float>(v.a);
tmp = (tmp - 128) * contrast + brightness + 128;
tmp = direct3d::clamp(tmp, 0.0f, 255.0f);
const unsigned int temp4_ = static_cast<unsigned int>(tmp);
outputTxVw.set(idx, graphics::uint_4(temp1_, temp2_, temp3_, temp4_));
});
copy(outputTx, (void*)a, len);
}
您可以在 AMP Book 中找到更多 C++ AMP 示例
关于C++ AMP : array_view and index behaving strangely (unexpected values stored),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17478632/
一旦在 qconsole Marklogic 中运行以下代码,我就会遇到以下错误 XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax err
我已经在我的包中编写了这个函数。 def partitionIntoDays(ls, number, lookupKey=None): ''' Partitions the location
我只是一个 android 初学者,我已经安装了 Android Studio(版本是 1.0.2),并创建了一个新的空白应用程序,按照名为“构建你的第一个应用程序”的官方教程,我学习到这个页面' h
这只是前几天工作,但我刚刚将我的代码更新到运行乘客 2.2.4 的审查服务器,而我的 2.3.4 rails 应用程序现在无法在那个盒子上启动。 乘客报告: Passenger encountered
我正在尝试使用带有 Angular 2的整页, 将其导入我的 app.module.ts 时出现以下错误。 "(SystemJS) Unexpected token ) at Obje
TFS2015 vNext 构建失败并出现记录器错误(下面附有错误消息)。根据我的调查,这看起来与 CentralLogger - "Microsoft.TeamFoundation.Distribu
计算机科学学校项目。我需要编写一个程序,其中用户声明数组的大小,然后以数字、非递减顺序填充数组,然后声明一个值 x。然后将 X 分配到适当的位置,以便整个数组按数字、非递减顺序排列。然后输出该数组。
在这 2 个方法中,inspect1 显示编译错误“Unexpected bound”而 inspect2 工作正常,为什么? public void inspect1(List u){ S
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在尝试运行以下代码,但遇到了“此时意外”错误。 (echo COPY (SELECT ta.colA as name, ta.colB as user_e, ta.colC as user_n,
我有以下查询: select u.UserName, count(*) as total from Voting v join User u using (UserID) where unique (
我们有以下查询在 MSSQL 中完美运行但在 MySQL 中无法运行: select CONVERT(datetime, dateVal) as DateOccurred, itemID, COUNT
我的代码中存在缩进错误问题。它看起来是正确的...有人能指出我做错了什么吗?我的查询行不断收到错误。 def invoice_details(myDeliveryID): conn = pym
我有以下代码: int a , b , sum; cin>>a>>b; sum=a+b; cout>a>>b>>c; cout<
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我在一个批处理文件上运行这个命令: for %I in (*.txt *.doc) do copy %I c:\test2 ...它不断返回: I was unexpected at this tim
创建查询时出现错误: 'from' unexpected 我的代码如下: @Override public Admin findByAdmin(Admin admin) {
我正在尝试运行此 python 代码,但我不断收到错误消息“意外缩进”。我不确定怎么了。间距似乎很好。有什么想法吗? services = ['Service1'] for service in
我在名为“circular_dependency”的目录中有一些 python 文件: 导入文件_1.py: from circular_dependency.import_file_2 import
我正在尝试使用 gcc 编译代码并运行可执行文件,但它抛出错误: gcc somefile.c -o somefile 编译成功。但是,当我尝试执行它时: $sh somefile 它导致:语法错误:
我是一名优秀的程序员,十分优秀!