当前位置: 首页 > news >正文

杭州网站开发培训青岛网站建设开发外包

杭州网站开发培训,青岛网站建设开发外包,罗琳做的网站,公司网站服务器维护CUDA程序错误检测 所有CUDA的API函数都有一个类型为cudaError_t的返回值#xff0c;代表了一种错误信息#xff1b;只有返回cudaSuccess时#xff0c;才是成功调用。 cudaGetLastError()用来检测核函数的执行是否出错cudaGetErrorString()输出错误信息 #include stdi…CUDA程序错误检测 所有CUDA的API函数都有一个类型为cudaError_t的返回值代表了一种错误信息只有返回cudaSuccess时才是成功调用。 cudaGetLastError()用来检测核函数的执行是否出错cudaGetErrorString()输出错误信息 #include stdio.h #include cuda_runtime.h #include device_launch_parameters.h #includemath.h #include malloc.h #include opencv2/opencv.hpp #include stdlib.h#define BLOCK_SIZE 1//图像卷积 GPU __global__ void sobel_gpu(unsigned char* in, unsigned char* out, const int Height, const int Width) {int x blockDim.x * blockIdx.x threadIdx.x;int y blockDim.y blockIdx.y threadIdx.y;int index y * Width x;int Gx 0;int Gy 0;unsigned char x0, x1, x2, x3, x4, x5, x6, x7, x8;if (x0 x(Width-1) y0 y(Height-1)){x0 in[(y - 1)*Width (x - 1)];x1 in[(y - 1)*Width (x)];x2 in[(y - 1)*Width (x 1)];x3 in[(y)*Width (x - 1)];x5 in[(y)*Width (x 1)];x6 in[(y 1)*Width (x - 1)];x7 in[(y 1)*Width (x)];x8 in[(y 1)*Width (x 1)];Gx (x0 2 * x3 x6) - (x2 2 * x5 x8);Gy (x0 2 * x1 x2) - (x6 2 * x7 x8);out[index] (abs(Gx) abs(Gy)) / 2;} }int main() {cv::Mat src;src cv::imread(complete004.jpg);cv::Mat grayImg,gaussImg;cv::cvtColor(src, grayImg, cv::COLOR_BGR2GRAY);cv::GaussianBlur(grayImg, gaussImg, cv::Size(3,3), 0, 0, cv::BORDER_DEFAULT);int height src.rows;int width src.cols;//输出图像cv::Mat dst_gpu(height, width, CV_8UC1, cv::Scalar(0));//GPU存储空间int memsize height * width * sizeof(unsigned char);//输入 输出unsigned char* in_gpu;unsigned char* out_gpu;cudaMalloc((void**)in_gpu, memsize);cudaMalloc((void**)out_gpu, memsize);cudaError_t error_code;dim3 threadsPreBlock(BLOCK_SIZE, BLOCK_SIZE);dim3 blocksPreGrid((width threadsPreBlock.x - 1)/threadsPreBlock.x, (height threadsPreBlock.y - 1)/threadsPreBlock.y);cudaMemcpy(in_gpu, gaussImg.data, memsize, cudaMemcpyHostToDevice);sobel_gpu blocksPreGrid, threadsPreBlock (in_gpu, out_gpu, height, width);error_code cudaGetLastError();printf(Error: %s\n, cudaGetErrorString(error_code));printf(FILE: %s\n, __FILE__);printf(LINE: %d\n, __LINE__);printf(Error code: %d\n, error_code);cudaMemcpy(dst_gpu.data, out_gpu, memsize, cudaMemcpyDeviceToHost);cv::imwrite(dst_gpu_save.png, dst_gpu);//cv::namedWindow(src, cv::WINDOW_NORMAL);cv::imshow(src, src);cv::imshow(dst_gpu, dst_gpu);cv::waitKey();cudaFree(in_gpu);cudaFree(out_gpu);return 0; } 樊哲勇大牛的检测CUDA运行时错误的宏函数 #pragma once #includestdio.h#define CHECK(call) \ do \ { \const cudaError_t error_code call; \if (error_code ! cudaSuccess) \{ \printf(CUDA Error:\n); \printf( File: %s\n, __FILE__); \printf( Line: %d\n,__LINE__); \printf( Error code: %d\n,error_code); \printf( Error text: %s\n, cudaGetErrorString(error_code)); \exit(1); \} \ } while (0) 采用检测CUDA运行时错误的宏函数 #include stdio.h #include cuda_runtime.h #include device_launch_parameters.h #includemath.h #include malloc.h #include opencv2/opencv.hpp #include stdlib.h#include error.cuh#define BLOCK_SIZE 1//图像卷积 GPU __global__ void sobel_gpu(unsigned char* in, unsigned char* out, const int Height, const int Width) {int x blockDim.x * blockIdx.x threadIdx.x;int y blockDim.y blockIdx.y threadIdx.y;int index y * Width x;int Gx 0;int Gy 0;unsigned char x0, x1, x2, x3, x4, x5, x6, x7, x8;if (x0 x(Width-1) y0 y(Height-1)){x0 in[(y - 1)*Width (x - 1)];x1 in[(y - 1)*Width (x)];x2 in[(y - 1)*Width (x 1)];x3 in[(y)*Width (x - 1)];x5 in[(y)*Width (x 1)];x6 in[(y 1)*Width (x - 1)];x7 in[(y 1)*Width (x)];x8 in[(y 1)*Width (x 1)];Gx (x0 2 * x3 x6) - (x2 2 * x5 x8);Gy (x0 2 * x1 x2) - (x6 2 * x7 x8);out[index] (abs(Gx) abs(Gy)) / 2;} }int main() {cv::Mat src;src cv::imread(complete004.jpg);cv::Mat grayImg,gaussImg;cv::cvtColor(src, grayImg, cv::COLOR_BGR2GRAY);cv::GaussianBlur(grayImg, gaussImg, cv::Size(3,3), 0, 0, cv::BORDER_DEFAULT);int height src.rows;int width src.cols;//输出图像cv::Mat dst_gpu(height, width, CV_8UC1, cv::Scalar(0));//GPU存储空间int memsize height * width * sizeof(unsigned char);//输入 输出unsigned char* in_gpu;unsigned char* out_gpu;cudaMalloc((void**)in_gpu, memsize);cudaMalloc((void**)out_gpu, memsize);dim3 threadsPreBlock(BLOCK_SIZE, BLOCK_SIZE);dim3 blocksPreGrid((width threadsPreBlock.x - 1)/threadsPreBlock.x, (height threadsPreBlock.y - 1)/threadsPreBlock.y);cudaMemcpy(in_gpu, gaussImg.data, memsize, cudaMemcpyHostToDevice);sobel_gpu blocksPreGrid, threadsPreBlock (in_gpu, out_gpu, height, width);CHECK(cudaMemcpy(dst_gpu.data, out_gpu, memsize*10, cudaMemcpyDeviceToHost));//增大size值 引起报错cv::imwrite(dst_gpu_save.png, dst_gpu);//cv::namedWindow(src, cv::WINDOW_NORMAL);cv::imshow(src, src);cv::imshow(dst_gpu, dst_gpu);cv::waitKey();cudaFree(in_gpu);cudaFree(out_gpu);return 0; }
http://www.pierceye.com/news/410367/

相关文章:

  • 南宁做网站外包公众号二次开发
  • 中国做网站最好的公司郑州网站建设目标
  • 各大网站平台发布信息企业官网模板免费源码
  • 第一次做网站怎么样下手威联通如何做网站
  • 网站有哪几种类型郑州建设信息网可以领证书吗
  • wordpress 百度网盘网站semseo先做哪个
  • 中企动力网站策划小程序开发平台软件
  • 做网站的公司创业泉州网页设计制作
  • 做网站一定要服务器吗做响应式网站
  • 做网站建设涉及哪些算法呼和浩特网站建设电话
  • 网站流量统计 设计做seo需要会网站开发吗
  • 网站前台用什么开发襄阳谷城网站建设
  • 网站icp备案号怎么查北京 网站建设 SEO
  • 西安做网站哪里好wordpress用户前端化
  • 宁波网站优化如何免费加速器
  • 一佰互联自助建站网站公司建设网站价格
  • 外贸网站模板免费下载wordpress英文显示改中文字体
  • 长春电商网站建设公司电话微博内容放到wordpress
  • 网站销售怎么样的商务网站模块设计时前台基础设施建设
  • 进空间的网站吗帝国建站教程
  • 做网站 业务流程图如何选择丹阳网站建设
  • 金属东莞网站建设技术支持开放平台产品经理
  • 全网营销型的网站苏州网站设计多少钱
  • 河南教育平台网站建设北京市工程建设信息交易网站
  • 正规品牌网站设计推荐如何上传自己的做的网站
  • 企业网站优化甲薇g71679做同等效果下拉词制作手机网站哪家好
  • 物流运输做网站的素材多用户商城系统价格
  • 营销型网站建设流程电脑怎么建网站
  • 郑州市汉狮做网站360免费建站
  • 安阳哪里有学做网站的学校做个公众号需要多少钱