当前位置:网站首页>CUDA realizes efficient search - failed audit?
CUDA realizes efficient search - failed audit?
2022-06-10 17:47:00 【Wu lele~】
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
void __global__ bisearch(int *d, int *dval, int *pos, const int N);
void __global__ bisearch(int *d, int *dval, int *pos, const int N)
{
int tid = blockDim.x * blockIdx.x + threadIdx.x;
if(tid < N)
{
if(d[tid] == *dval)
{
*pos = tid;}
}
}
int main(int argc, char *arcv[])
{
if(argc<3)
{
printf("assignment is not enough!");
}
int N = atoi(arcv[1]);
int val = atoi(arcv[2]);
// host memory
int hpos = -1;
int a[N] = {
0,1,2};
vector<int> vec(a,a+N);
/* for(int i=0; i<N; i++) { vec.push_back(i); } cout<< vec[0] <<endl; cout<< vec[1] <<endl; cout<< vec[2] << endl; cout<< val<<endl; */
int *h;
h = (int *)&vec[0];
// device memory
int *d;
cudaMalloc(&d, sizeof(int)*N);
int *dval;
cudaMalloc(&dval, sizeof(int));
int *dpos;
cudaMalloc(&dpos, sizeof(int));
// host --> device
cudaMemcpy( d, h, sizeof(int)*N,cudaMemcpyHostToDevice);
cudaMemcpy( dval, &val, sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy( dpos, &hpos, sizeof(int), cudaMemcpyHostToDevice);
// threads and blocks
const int block_size = 128;
const int grid_size = (N + block_size -1) / block_size;
bisearch<<<grid_size,block_size>>>(d, dval, dpos, N);
// cuda to cpu
cudaMemcpy( &hpos, dpos, sizeof(int), cudaMemcpyDeviceToHost );
printf("Ans: %d\n", hpos);
// free memory
cudaFree(d);
cudaFree(dval);
cudaFree(dpos);
return 0;
}
summary
vector I don't know how to use it ;vector The definition requires the use of using namespace std;
边栏推荐
- Knowledge based bert: a method to extract molecular features like a computational chemist
- This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue
- 当v-if和v-for需要同时使用的时候
- Mapbox GL development tutorial (11): loading line layers
- It has become a unicorn since its establishment one year ago. Tencent didi is the "backer". This year's new unicorn is not simple
- 嘿!ONES 新星请看过来|师兄师姐说
- Leetcode String to integer(Atoi)
- 树、森林和二叉树的关系
- 基于Feign远程调用
- MMdetection之build_optimizer模块解读
猜你喜欢

【报表工具的第二次革命】基于SPL语言优化报表结构、提升报表运算性能

蓝桥杯_糊涂人寄信_递归

为什么 0.1+0.2=0.30000000000000004
![[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language](/img/53/d6f05e8050e27dc9d59f1196753512.png)
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language

A few misunderstandings about programmers are very harmful!

丢失的遗传力--Missing heritability

C#_串口通信项目

THE LOTTERY TICKET HYPOTHESIS: FINDING SPARSE, TRAINABLE NEURAL NETWORKS论文笔记

重庆第一个科创板IPO,来了
![[BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)](/img/75/a3336aa7314a2dfc9a7a32995793e7.png)
[BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
随机推荐
Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)
SOA architecture / test phase interface description language transformation scheme
Snabbdom virtual DOM (I)
蓝桥杯_糊涂人寄信_递归
自定义视图:图形与图像的处理(一):使用简单图片
Primekg: building a knowledge map to achieve precision medicine
成立1年便成独角兽,腾讯滴滴做「靠山」,今年新晋的独角兽不简单
为什么 0.1+0.2=0.30000000000000004
路由器实验之serial接口的静态路由配置(补充)
单片机底层通信协议① —— 同步和异步、并行和串行、全双工和半双工以及单工、电平信号和差分信号
[play with Huawei cloud] Kunpeng devkit migration practice
Mysql database implementation setting field length
What are the differences between domain name filing and ICP filing?
Station B doesn't want to be a "conscience aiyouteng"
Numpy numpy中np.set_printoptions()的用法——控制输出方式
2022年茶艺师(中级)操作证考试题库及模拟考试
mmcv之Registry类解读
Is the fund of futures account safe?
Redis general instruction
How will you integrate into the $20trillion "project economy" in five years