를 입력하려고 할 때 malloc을에게 3906 오류이 당신이 볼 수 있듯이, 내가 CPU 측에 fillArray 기능을 내 배열을 채우기 내 코드난 내 배열을
using namespace std;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 8000
void fillArray(int *data, int count){
for(int i =0; i < count; i++)
data[i] = (int) rand()/((int) RAND_MAX);
}
__global__ void add(int* a, int *b){
int add = 0;
int tid = threadIdx.x + blockIdx.x * blockDim.x;
if(tid < N){
add = a[tid] + b[tid];
}
}
__global__ void subtract(int* a, int *b){
int subtract = 0;
int tid = threadIdx.x + blockIdx.x * blockDim.x;
if(tid < N){
subtract = a[tid] - b[tid];
}
}
float duration(int *devA, int *devB, int blocksPerGrid, int threadsPerBlock){
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaMalloc((void**) &devA, N * sizeof(int));
cudaMalloc((void**) &devB, N * sizeof(int));
add<<<blocksPerGrid, threadsPerBlock>>>(devA,devB);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime,start,stop);
cudaEventDestroy(start);
cudaEventDestroy(stop);
return elapsedTime;
}
int main(void) {
int *a = new int(N);
int *b = new int(N);
float dur = 0 ;
fillArray(a, N);
fillArray(b, N);
dur = duration(a,b,N,1);
cout << "Global memory version:\n";
cout << "Process completed in " << dur;
cout << "for a data set of " << N << " integers.";
return 0;
}
입니다. 여기
malloc.c 3906 : sYSMalloc: Assertion bla bla
를 누락 무엇 : 그러나 채우기 배열 함수는 에러를 준다? 배열을 채우려고합니다. 그게 내가 뭘 문제 야? 이벤트 기간 함수에서 내가이 오류가 발생 추가 기능을 제거하는 경우. 여기에 어떤 문제가 있습니까?
쓰기 예외가 완전히 그래서 사람들은 당신에게 도움이 될 수 있습니다. 리눅스에서 valgrind와 같은 타입 오류가 발생한다면 – qwr
[C malloc 어설 션 오류가 발생하는 이유는 무엇입니까?] (http://stackoverflow.com/questions/2987207/why-do-i-get-ac- – talonmies
이 질문은 CUDA와 관련이 없으므로 다시 질문해야합니다. – talonmies