- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题的根源很可能是我没有分配足够的内存。我会尝试考虑一下并正确地做,然后回答我的问题。傻我。 :-[ 它并没有解释 warp 没有出现在 stdout 中......
我在 CUDA 中创建了一个模板化内核,在其中迭代全局内存中的灰度图像数据部分(共享内存优化是在我开始工作时进行的)以实现具有圆盘形结构元素的形态学操作。每个线程对应于图像的一个像素。当数据类型为 char
时,一切都按预期工作,我的所有线程都在做它们应该做的事情。当我将它更改为 unsigned short
时,它开始运行并且只计算图像的上半部分。当我输入一些 printfs(我的设备有 2.0 CC)时,我发现一些应该运行的扭曲甚至没有被计算。
这是相关代码。
在我的 main.cpp 中,我调用了 gcuda::ErodeGpuGray8(img, radius);
和 gcuda::ErodeGpuGray16(img, radius);
以下函数:
// gcuda.h
…
i3d::Image3d<i3d::GRAY8> ErodeGpuGray8(i3d::Image3d<i3d::GRAY8> img, const unsigned int radius);
i3d::Image3d<i3d::GRAY16> ErodeGpuGray16(i3d::Image3d<i3d::GRAY16> img, const unsigned int radius);
…
// gcuda.cu
…
// call this from outside
Image3d<GRAY8> ErodeGpuGray8(Image3d<GRAY8> img, const unsigned int radius) {
return ErodeGpu<GRAY8>(img, radius);
}
// call this from outside
Image3d<GRAY16> ErodeGpuGray16(Image3d<GRAY16> img, const unsigned int radius) {
return ErodeGpu<GRAY16>(img, radius);
}
…
我使用的库将 GRAY8
定义为 char
并将 GRAY16
定义为 unsigned short
。
这是我调用内核的方式(blockSize
是一个在相关命名空间中设置为 128 的 const int
):
// gcuda.cu
template<typename T> Image3d<T> ErodeGpu(Image3d<T> img, const unsigned int radius) {
unsigned int width = img.GetWidth();
unsigned int height = img.GetHeight();
unsigned int w = nextHighestPower2(width);
unsigned int h = nextHighestPower2(height);
const size_t n = width * height;
const size_t N = w * h;
Image3d<T>* rslt = new Image3d<T>(img);
T *vx = rslt->GetFirstVoxelAddr();
// kernel parameters
dim3 dimBlock( blockSize );
dim3 dimGrid( ceil( N / (float)blockSize) );
// source voxel array on device (orig)
T *vx_d;
// result voxel array on device (for result of erosion)
T *vxr1_d;
// allocate memory on device
gpuErrchk( cudaMalloc( (void**)&vx_d, n ) );
gpuErrchk( cudaMemcpy( vx_d, vx, n, cudaMemcpyHostToDevice ) );
gpuErrchk( cudaMalloc( (void**)&vxr1_d, n ) );
gpuErrchk( cudaMemcpy( vxr1_d, vx_d, n, cudaMemcpyDeviceToDevice ) );
ErodeGpu<T><<<dimGrid, dimBlock>>>(vx_d, vxr1_d, n, width, radius);
gpuErrchk( cudaMemcpy( vx, vxr1_d, n, cudaMemcpyDeviceToHost ) );
// free device memory
gpuErrchk( cudaFree( vx_d ) );
gpuErrchk( cudaFree( vxr1_d ) );
// for debug purposes
rslt->SaveImage("../erodegpu.png");
return rslt;
}
我的测试图像的尺寸是 82x82,所以 n = 82*82 = 6724 和 N = 128*128 = 16384。
这是我的内核:
// gcuda.cu
// CUDA Kernel -- used for image erosion with a circular structure element of radius "erosionR"
template<typename T> __global__ void ErodeGpu(const T *in, T *out, const unsigned int n, const int width, const int erosionR)
{
ErodeOrDilateCore<T>(ERODE, in, out, n, width, erosionR);
}
// The core of erosion or dilation. Operation is determined by the first parameter
template<typename T> __device__ void ErodeOrDilateCore(operation_t operation, const T *in, T *out, const unsigned int n, const int width, const int radius) {
// get thread number, this method is overkill for my purposes but generally should be bulletproof, right?
int blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z;
int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z) + (threadIdx.z * (blockDim.x * blockDim.y)) + (threadIdx.y * blockDim.x) + threadIdx.x;
int tx = threadId;
if (tx >= n) {
printf("[%d > %d]", tx, n);
return;
} else {
printf("{%d}", tx);
}
… (erosion implementation, stdout is the same when this is commented out so it's probably not the root of the problem)
}
据我了解,此代码应将一组随机排序的 [X > N]
和 {X}
字符串写入标准输出,其中 X = 线程 ID 并且应该是 n
大括号数字(即索引为 <n
的线程的输出)和其余的 N - n
,但是当我运行它并使用正则表达式计算大括号内的数字,我发现我只得到其中的 256 个。此外,它们似乎出现在 32 个成员的组中,这告诉我有些 warp 在运行,有些没有。
我真的很困惑。当我不注释掉侵 eclipse 实现部分时,GRAY8 侵 eclipse 起作用而 GRAY16 侵 eclipse 不起作用,这无济于事,即使两种情况下的 stdout 输出完全相同(可能取决于输入,我只用 2 张图片试过)。
我错过了什么?这可能是什么原因造成的?我是否存在一些内存管理错误,或者某些扭曲不运行并且侵 eclipse 的东西可能只是图像库中的错误,只发生在 GRAY16 类型上?
最佳答案
所以这只是一个愚蠢的 malloc 错误。
代替
const size_t n = width * height;
const size_t N = w * h;
我用过
const int n = width * height;
const int N = w * h;
而不是错误的
gpuErrchk( cudaMalloc( (void**)&vx_d, n ) );
gpuErrchk( cudaMemcpy( vx_d, vx, n, cudaMemcpyHostToDevice ) );
gpuErrchk( cudaMalloc( (void**)&vxr1_d, n ) );
gpuErrchk( cudaMemcpy( vxr1_d, vx_d, n, cudaMemcpyDeviceToDevice ) );
…
gpuErrchk( cudaMemcpy( vx, vxr1_d, n, cudaMemcpyDeviceToHost ) );
我用过
gpuErrchk( cudaMalloc( (void**)&vx_d, n * sizeof(T) ) );
gpuErrchk( cudaMemcpy( vx_d, vx, n * sizeof(T), cudaMemcpyHostToDevice ) );
gpuErrchk( cudaMalloc( (void**)&vxr1_d, n * sizeof(T) ) );
gpuErrchk( cudaMemcpy( vxr1_d, vx_d, n * sizeof(T), cudaMemcpyDeviceToDevice ) );
…
gpuErrchk( cudaMemcpy( vx, vxr1_d, n * sizeof(T), cudaMemcpyDeviceToHost ) );
现在侵 eclipse 工作正常,这是我试图解决的主要问题。不过,我仍然没有得到我期望的 stdout 输出,所以如果有人可以阐明这一点,请这样做。
关于c++ - CUDA——简单的代码,但我的一些 warp 不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21220426/
当 SM 上正在运行的 warp 停滞时,必须在 SM 上安排另一个 warp 来交换停滞的 warp 以弥补延迟。但是替代品是否与停滞的扭曲来自同一个 block ,或者它必须属于另一个 block
我的问题是关于 warp 和调度的。我在这里使用 NVIDIA 费米术语。我的观察如下,它们正确吗? 一个。同一 warp 中的线程执行相同的指令。每个 warp 包含 32 个线程。 根据费米白皮书
我的问题是关于 warp 和调度的。我在这里使用 NVIDIA 费米术语。我的观察如下,它们正确吗? 一个。同一 warp 中的线程执行相同的指令。每个 warp 包含 32 个线程。 根据费米白皮书
注意:此问题特定于 nVIDIA 计算能力 2.1 设备。以下信息来自《CUDA 编程指南 v4.1》: In compute capability 2.1 devices, each SM has
假设我有一个函数来检查授权 header 是否有效以及身份验证是否正确。如何制作一个扭曲过滤器来丢弃所有带有无效 header 或虚假凭据的请求? 最佳答案 这是一个构建过滤器的函数示例,该过滤器完全
我一直在研究使用 Haskell Warp 构建的像素服务器,并且一直在努力研究如何在守护进程模式下运行它。 Warp 效果很好 - 我可以使用 run从 Network.Wai.Handler.Wa
我正在尝试构建一个不平凡的 warp将 REST 应用程序集成到模块中,同时优雅地处理错误和拒绝。它没有按我预期的方式工作。考虑这个简单的应用程序: 主要.rs use warp_sample::ro
我正在用 Rust 编写带有 warp 的服务。当服务收到 SIGTERM 信号时,我希望它正常关闭并可能进行一些日志记录或其他工作。 我已经尝试了很多例子,但没有任何效果。最有希望的似乎来自 thi
我正在考虑使用 wai/warp 进行一些自定义的进程间通信。这将有一个不寻常的要求,即我需要在进程中动态启动/停止扭曲实例。主要问题似乎是完全停止扭曲。这个问题在这里解决: How do I imp
我有一个使用 warp 的 Rust 应用程序.它实现了一个 RESTful CRUD API。我需要每个路由处理程序(即最终由 warp 过滤器调用的函数)来访问和(在大多数情况下)改变共享的应用程
我定义了一个路由和一个端点函数。我还注入(inject)了一些依赖项。 pub fn route1() -> BoxedFilter { warp::get() .and(wa
我想使用 Warp 创建一个网站Haskell 中的网络服务器。 由于我是 Haskell 初学者,因此 this one 等示例对我来说太复杂了。 谁能告诉我一个简单的、最小的如何使用 Warp 的
使用 warp.rs 0.2.2 ,让我们考虑一个基本的 Web 服务,它有一个路由 GET / : #[tokio::main] async fn main() -> Result { le
运行 warp 时应用程序使用 run ,它监听所有 IP 地址。 出于安全原因,我只想监听 localhost,使用反向代理处理远程访问。 我需要如何调用 run 才能仅监听特定主机/IP? 注意:
我有一个 HTTP 应用程序服务器,在特定条件下处理特定请求时需要退出(以便由主管重新启动)。 给定一个主要的: import Network.Wai.Handler.Warp (run) main
我使用 yesod init 创建了一个 yesod webapp。在开发过程中,我使用 yesod devel 在 Debug模式下运行 warp 服务器。现在我已经完成了初步版本,我想将其部署在
我有 GeForce GTX460 SE,所以它是:6 SM x 48 CUDA 核心 = 288 CUDA 核心。众所周知,一个Warp中包含32个线程,并且一个 block 中同时(一次)只能执行
我正试图找到一种方法在 iOS 上做类似的事情: 有谁知道一个简单的方法吗? 最佳答案 我不知道有一个 oneliner 可以做到这一点,但您可以使用 OpenGL 渲染带四边形的纹理网格,其纹理坐标
我正在尝试在 Warp 中设置可变路径。我试过这个: use uuid::Uuid; use warp::{self, Filter}; fn main() { let uuid = Uuid
我有一个关于 union cuda 访问的基本问题。 例如,我有一个包含 32 个元素和 32 个线程的数组,每个线程访问一个元素。 __global__ void co_acc ( int A[32
我是一名优秀的程序员,十分优秀!