- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我认为这与此处报告的问题不同:
CUDA 1D texture fetch always return 0
在我的 CUDA 应用程序中,我注意到 tex1Dfetch 没有返回预期值,超过了缓冲区中的某个索引。应用程序中的初步观察是可以正确读取索引 0 处的值,但在 12705625 处读取的值为 0。我制作了一个小测试程序来调查这个问题,如下所示。结果让我有点莫名其妙。我正在尝试探查哪些索引值不再被正确读取。但是随着值 arraySize 的改变,“firstBadIndex”也会改变。即使 arraySize =2,第二个值也读错了!随着 arraySize 变大,firstBadIndex 变大。当绑定(bind)到 float、float2 或 float4 数组时会发生这种情况。如果数据是从设备缓冲区读取的(切换 FetchTextureData 中的注释行),那么一切都很好。这是在 Tesla c2075 上使用 CUDA 6.5。感谢您提供任何见解或建议。
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#define FLOATTYPE float4
texture<FLOATTYPE,cudaTextureType1D,cudaReadModeElementType> texture1D;
const unsigned int arraySize = 1000;
FLOATTYPE* host;
FLOATTYPE* device;
FLOATTYPE* dTemp;
FLOATTYPE hTemp[1];
__global__ void FetchTextureData(FLOATTYPE* data,FLOATTYPE* arr,int idx)
{
data[0] = tex1Dfetch(texture1D, idx);
//data[0] = arr[idx];
}
bool GetTextureValues(int idx){
FetchTextureData<<<1,1>>>(dTemp,device,idx);
// copy to the host
cudaError_t err = cudaMemcpy(hTemp,dTemp,sizeof(FLOATTYPE),cudaMemcpyDeviceToHost);
if (err != cudaSuccess) {
throw "cudaMemcpy failed!";
}
if (cudaDeviceSynchronize() != cudaSuccess) {
throw "cudaDeviceSynchronize failed!";
}
return hTemp[0].x == 1.0f;
}
int main()
{
try{
host = new FLOATTYPE[arraySize];
cudaError_t err = cudaMalloc((void**)&device,sizeof(FLOATTYPE) * arraySize);
cudaError_t err1 = cudaMalloc((void**)&dTemp,sizeof(FLOATTYPE));
if (err != cudaSuccess || err1 != cudaSuccess) {
throw "cudaMalloc failed!";
}
// make some host data
for(unsigned int i=0; i<arraySize; i++){
FLOATTYPE data = {1.0f, 0.0f, 0.0f, 0.0f};
host[i] = data;
}
// and copy it to the device
err = cudaMemcpy(device,host,sizeof(FLOATTYPE) * arraySize,cudaMemcpyHostToDevice);
if (err != cudaSuccess){
throw "cudaMemcpy failed!";
}
// set up the textures
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<FLOATTYPE>();
texture1D.addressMode[0] = cudaAddressModeClamp;
texture1D.filterMode = cudaFilterModePoint;
texture1D.normalized = false;
cudaBindTexture(NULL, texture1D, device, channelDesc, arraySize);
// do a texture fetch and find where the fetches stop working
int lastGoodValue = -1, firstBadValue = -1;
float4 badValue = {-1.0f,0.0f,0.0f,0.0f};
for(unsigned int i=0; i<arraySize; i++){
if(i % 100000 == 0) printf("%d\n",i);
bool isGood = GetTextureValues(i);
if(firstBadValue == -1 && !isGood)
firstBadValue = i;
if(isGood)
lastGoodValue = i;
else
badValue = hTemp[0];
}
printf("lastGoodValue %d, firstBadValue %d\n",lastGoodValue,firstBadValue);
printf("Bad value is (%.2f)\n",badValue.x);
}catch(const char* err){
printf("\nCaught an error : %s\n",err);
}
return 0;
}
最佳答案
问题出在纹理设置上。这:
cudaBindTexture(NULL, texture1D, device, channelDesc, arraySize);
应该是:
cudaBindTexture(NULL, texture1D, device, channelDesc,
arraySize * sizeof(FLOATTYPE));
根据 documentation , size 参数是以字节为单位的内存区域的大小,而不是元素的数量。我原以为在钳位寻址模式下,代码仍能按预期工作。使用边界模式,您应该得到一个零值,这看起来会触发您的错误值检测。我实际上并没有运行你的代码,所以也许我在某处遗漏了一个微妙的地方。对于这样一个简单的复现案例,您的代码结构相当复杂且难以理解(至少在我正在阅读的手机屏幕上)。
编辑添加,在我开始写这篇文章和完成这段时间之间,@njuffa 在评论中指出了同样的错误
关于c++ - tex1Dfetch 意外返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508502/
我的意思是整篇论文,而不仅仅是其中的文本区域。 我希望 dvi 输出在查看器中看起来 1 厘米 x 10 米,如果 我在 tex 文件中设置了这些尺寸。 而且我不想为此通过 LaTeX。 最佳答案 在
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我在需要数值的参数中使用自动生成的 Tex 字符串时遇到问题(例如,在 ifthenelse 比较中)。这是一个示例最小代码: \newcommand\testC{123} \ifthenelse{\
我用的是 Mac。但我也有一台装有 Windows 7 的 PC。所以当我想开始使用 TeX 为 LaTeX 编程功能时,我的起点是什么?是否有 SDK 和文档?我找不到任何关于 TeX 编程的书。
在Xymostech的帮助下,已解决了将Bash中的&&转换为Python的问题,非常感谢其帮助-谢谢! 有争议的命令行(来自Bash终端)是:latexmk file.tex && latexmk
[编辑以提供更多信息] 我正在使用以下 R markdown 文件生成以下 Tex 文件。我在我的 .rmd header 中包含了 amsthm,它正在生成一个没有 amsthm 的 Tex 文件。
我有以下 Hello World 代码来尝试在我的 Mac 上使用 matplotlib 进行 TeX 渲染。 import matplotlib.pyplot as plt from matplot
如何使用命令行脚本下载背页项目的源代码?我想定期备份源文件,如果我可以自动下载而不是每次都通过 Web 界面进行下载会更好。我不知道任何允许我这样做的 API,有吗? 我知道一个理想的解决方案可能会使
我正在尝试打开.tex文件。 我不确定我是否已经深入到了(可能)令人惊讶的复杂过程。有人告诉我可以用Notepad++做到这一点,然后继续下载。结果如下: %sample file for Model
我想在 TeX 方程中使用包含破折号的变量名。但是,破折号被解释为减号。任何人都知道如何逃避角色? 最佳答案 使用\textrm{-} 不起作用? 关于在 TeX 方程中转义一个字符?,我们在Stac
在 TEX 中,如何分割字符串,例如 \mana{X1 2W/UB R /G}分成几部分并将它们提供给另一个宏(在这种情况下,用类似 \m{X}\m{12}\m{W/U}\m{B}\m{R/G} 的东
我目前正在写我的学士论文,我的大学想要一份单面打印。打印和装订将由专业打印公司完成。他们只接受双面手稿。 因此,我需要在每一页内容后添加一个空白页。我不想使用 \newpage 手动执行此操作或 \c
我想在 .vimrc 中运行一个命令,以防文件是 latex 文件。我想我有一些语法问题,它不起作用。有什么线索吗? if &filetype=='tex' set spell endif 最
我正在使用在 XeLaTeX 之上编写的包。该包使用fontspec为文本的不同部分指定字体:拉丁语、非拉丁语、数学模式…… 该软件包附带了几个示例文件。我能够 xelatex 其中大多数依赖于常规
在 mathworks.com 的在线文档中,哪里有 MATLAB 支持的 TeX 字符子集表? 我习惯于轻松找到它,但我却找不到:在此页面上 http://www.mathworks.com/hel
我正在编写一个 Python 脚本,它将纯文本作为输入并生成LaTeX 代码作为输出。在某些时候,脚本必须引用所有在 TeX 中有特殊含义的字符,如 %、&、\ 等上。 这比我想象的要难。目前我有这个
我正在使用 Firebase 将内容放到网站上。类似“获取多项选择题/选项并将它们插入 div 标签”之类的东西。其中一些问题使用数学/化学方程,我认为 TeX 将是一个很好的渲染工具。 基本上,如果
假设我有一个文本文件 something.txt。写着4062,2016-12-31 我想在脚本中的一个命令中发送“4062”,在另一个命令中将“2016-12-31”作为字符串发送。可以用 BASH
在 MediaWiki 中,如果您在公式中添加非英语文本,它会剪切。例如,如果您编写 \text{щfбb}(щ 和 б 俄语(西里尔)符号)输出将是 fb 不是 щfбb。 最佳答案 首先,如果您的
我正在运行 CUDA 5.0,使用 670 设置了 compute_30、sm_30。 我通过以下方式创建一个 mipmapped 数组: cudaExtent size; size.width =
我是一名优秀的程序员,十分优秀!