1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// // // // // //CUDA Synchronization | A quick example of CUDA Device Memory | Cuda Education | Cuda Tutorial //Company: CUDA Education | cudaeducation.com | cudaeducation@gmail.com | Please donate at cudaeducation.com //YouTube Channel (please subscribe): https://www.youtube.com/channel/UCzpwNg0Ai8zCzbsEtozkfFQ //Twitter: @cudaeducation //Have questions? Comment on the YouTube channel https://www.youtube.com/channel/UCzpwNg0Ai8zCzbsEtozkfFQ or email cudaeducation@gmail.com //Donate: Visit cudaeducation.com to donate to the cause //DISCLAIMER: This code is for teaching purposes only! CUDA Education does not guarantee the accuracy of this code in any way. This code should not be used in a production or commercial environment. Any liabilities or loss resulting from the use of this code, in whole or in part, will not be the responsibility of CUDA Education. //All rights reserved. This code is the property of CUDA Education. Please contact CUDA Education at cudaeducation@gmail.com if you would like to use this code in any way, shape or form. //CODING ENVIRONMENT: //CUDA Toolkit 10.0 //Windows environment //Visual Studio 2017 Community Edition //nVidia GeForce 1050 ti Graphics Card //Compute Capability 6.5 //Install CUDA Toolkit: cudaeducation.com/howtoprogramcuda #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __device__ __managed__ int cuda_education_variable = 10; __global__ void printfromkernel() { printf("cuda_education_variable from device function: %d\n", cuda_education_variable); } int main() { printf("cuda_education_variable from host function: %d\n", cuda_education_variable); printfromkernel << <1, 5 >> > (); //do not recall the same kernel before the previous kernel is done executing cudaDeviceSynchronize(); printf("cuda_education_variable from host function: %d\n", cuda_education_variable); printfromkernel << <1, 1 >> > (); } |
Next: CUDA Synchronization