Comments (5)
from coriander.
Got it. Thanks!
from coriander.
I tried this code:
#include <stdio.h>
#define SIZE 1000
__global__ void kernel_matrix_add(float *input1, float *input2, float *output) {
const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
output[idx] = input1[idx] + input2[idx];
}
__global__ void kernel_matrix_multiply(float *input1, float *input2, float *output) {
const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
output[idx] = input1[idx] * input2[idx];
}
__global__ void kernel_matrix_divide(float *input1, float *input2, float *output) {
const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
output[idx] = input1[idx] / input2[idx];
}
__global__ void kernel_matrix_subtract(float *input1, float *input2, float *output) {
const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
output[idx] = input1[idx] - input2[idx];
}
int main() {
float * in1;
float * in2;
float * out;
cuMemHostAlloc((void**)&in1, SIZE*sizeof(float));
cuMemHostAlloc((void**)&in2, SIZE*sizeof(float));
cuMemHostAlloc((void**)&out, SIZE*sizeof(float));
for (int i = 0; i < SIZE; ++i) {
in1[i] = i;
in2[i] = i;
out[i] = 0;
}
float * d_in1;
float * d_in2;
float * d_out;
cudaMalloc(&d_in1, SIZE*sizeof(float));
cudaMalloc(&d_in2, SIZE*sizeof(float));
cudaMalloc(&d_out, SIZE*sizeof(float));
cudaMemcpy(d_in1, in1, SIZE*sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_in2, in2, SIZE*sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_out, out, SIZE*sizeof(float), cudaMemcpyHostToDevice);
kernel_matrix_multiply<<<SIZE / 1024 + 1, 1024>>>(d_in1, d_in2, d_out);
cudaMemcpy(out, d_out, SIZE*sizeof(float), cudaMemcpyHostToDevice);
printf("First 10 Results:\n");
for (int i = 0; i < 10; ++i) {
printf("%f\n", out[i]);
}
}
But now I get this:
OpenCL platform: Apple
OpenCL device: GeForce GTX 1070
Segmentation fault: 11
When I try to run with nvcc
:
cudatest.cu(32): error: identifier "cuMemHostAlloc" is undefined
1 error detected in the compilation of "/var/folders/5k/t9j2_ms918jgylxs810fmh8c0000gn/T//tmpxft_0000396d_00000000-9_cudatest.cpp1.ii".
Is there a way I can debug this?
Sorry! I'm just really new to this type of development!
from coriander.
I found it! This was the culprit: cudaMemcpy(out, d_out, SIZE*sizeof(float), cudaMemcpyHostToDevice);
!
For some reason, this line worked on CUDA, but not cocl
! It's supposed to be DeviceToHost
not HostToDevice
.
from coriander.
from coriander.
Related Issues (20)
- cocl_py cuda_sample.cu dont work HOT 3
- when run "make -j 8 tests", something went wrong,seems like the "PIE object" problem. HOT 5
- How much work would it be to update to OpenCL 3.0/Cuda 12...cuda has always been back wards compatable HOT 1
- CMake issues
- Cython Integration
- i.MX8M Vivante GPU not working (Sorry I messed up, delete this)
- i.MX8M Vivante GPU Not Working HOT 1
- MacOS installation error [Errno 2] No such file or directory HOT 3
- tests compilation problem HOT 1
- run install and get error HOT 1
- I'm extremely impressed by this project. HOT 2
- questions about cuda api HOT 1
- Windows installation HOT 1
- help with make run-tests HOT 1
- Issue installing on MacOS10.15.5 HOT 2
- Question about generating an executable with multiple source files HOT 1
- Success compiling and running cuda_example.cu on Apple M1 Big sur HOT 1
- diffs to compile for clang 9
- documenting fix for clang error: reference to host function from device HOT 1
- update on compiling with big sure and clang11: HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coriander.