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

外贸网站谷歌优化徐州市 两学一做网站

外贸网站谷歌优化,徐州市 两学一做网站,wordpress 树形页面,国内做的比较好的网站事件计时 CUDA事件是直接在GPU上实现的,因此它们不适用于对同时包含设备代码和主机代码的混合代码计时。 cudaEventCreate 创建一个事件cudaEventRecord 记录一个事件cudaEventElapsedTime 计算两个事件之间经历的时间,第一个参数为某个浮点变量的地址…
事件计时

CUDA事件是直接在GPU上实现的,因此它们不适用于对同时包含设备代码和主机代码的混合代码计时。

  • cudaEventCreate 创建一个事件
  • cudaEventRecord 记录一个事件
  • cudaEventElapsedTime 计算两个事件之间经历的时间,第一个参数为某个浮点变量的地址,在这个参数中将包含两次事件之间经历的时间,单位是毫秒
#include <stdio.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include<math.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 (x>0 && x<(Width-1) && y>0 && 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);cudaEvent_t start, stop_gpu;cudaEventCreate(&start);//创建事件cudaEventCreate(&stop_gpu);//创建事件cudaEventRecord(start);//记录事件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);cudaEventRecord(stop_gpu);//记录事件cudaError_t  error_code = cudaGetLastError();if (error_code != cudaSuccess){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);float time_gpu;cudaEventElapsedTime(&time_gpu, start, stop_gpu);//事件计时printf("GPU time: %.3f ms \n", time_gpu);cudaEventDestroy(start);//销毁事件cudaEventDestroy(stop_gpu);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.yayakq.cn/news/974942/

相关文章:

  • 英雄联盟网站建设军事新闻最新头条
  • 中小企业网站多大空间酷网站欣赏
  • 十堰网站建设_网站制作_软件开发_网店培训 优易厦门有什么网站制作公司
  • 万峰科技著.asp.net网站开发四酷全书电子工业出版社手机评测哪个网站做的好点
  • 做那种网站受欢迎优秀文创产品设计案例及分析
  • 如何维护公司网站如何做美食网站设计
  • 网站运营专员郑州推广网站
  • 门户网站建设情况网站金融模版
  • 网站开发我嵌入式开发广州番禺区天气预报
  • 怎么做企业曝光引流网站网站定制站
  • 西宁网站建设报价cu君博規范红色企业网站源码
  • 网站推广专家十年乐云seo王也图片高清头像
  • 网站建设项目的生命周期wordpress 文章透明
  • 江门网站建设推荐设计logo公司
  • 秀米网站怎么做推文优化网站用什么软件好
  • 图片做记录片的是哪个网站网站中点击链接怎么做的
  • 建筑设计网站排行榜响应式网站设计尺寸
  • 郑州网站推广招聘产品推广策划书
  • 网站 多语wordpress 导入网页
  • 源码建网站创建一个网站的项目体现项目完成速度因素的
  • 长尾关键词爱站网自建电商平台
  • 成品网站源码多少钱东莞市公司网站建设
  • 男女做暖暖网站php网站建设英文文献
  • 爱站网关键词挖掘查询工具本地网站后台管理建设
  • 网站开发的内容和特点如何开展网络营销活动
  • 聊城制作手机网站seo诊断优化专家
  • 免费公司网站模板网站后台无法审核
  • 365建站器专业品牌网站建设价格
  • linux做网站推荐企业门户网站建设
  • 网页空间免费申请河北seo优化