Friday, 15 July 2011

c - Cuda function pointers -


I was trying to make such somtehing (actually I need to write some integration tasks) in Sida < / P>

Enter image details here

I tried to do this But he did not work - this is the only reason.

Error: Function Pointer and Function Template parameters are not supported in sm_1x.

  float F1 (float x) {return x; } __ Global D minus tablet (float low, float top, float Pi_fnkshn (float), float * Results) to {(Low, Lower, Left, Lower, Lower ++) {* result = Result * + Pi_fnkshn (Bottom) ; }} Int main () {float res; Float * dev_res; CudaMalloc ((void **) & dev_res, sizeof (float)); Tablet & lt; & Lt; & Lt; 1,1 & gt; & Gt; & Gt; (0.0, 5.0, F1, dev_res); CudaMemcpy (& amp; res, dev_res, sizeof (float), cudaMemcpyDeviceToHost); Printf ("% f \ n", ridge); / *************************************************************************************************** ** ********** return 0; }    

To get rid of your compilation error, you should see -Janod arch = compute_20, code = sm_20 are compiled when your code as a compiler argument but then you will have some runtime problems:

Siudia went from the programming Guide

__ global __ function pointer is supported in the host code, but not in the device code. Function Points for the __ device __ function are only supported in compute device code for compute capability 2.x and higher devices.

It is not allowed to detect __ device __ function in host code.

If you can do something like that ( "customize Fnkshnpointrs" samples):

  // Your function pointer type - unsigned char returns, Type takes the unsigned four types of parameters and float type is notified four (* pointFunction_t) (unsigned char, float); // Some devices function unsigned char thresholds (in unsigned char, float correction) {to be pointed __device__ ...} // pComputeThreshold __device__ pointFunction_t pComputeThreshold = Threshold side function pointer as a tool to work your __device__ Is, // your __device__ function point at the host-side function pointer function_t h_pointFunction; // host code: cudaMemcpyFromSymbol your host equivalent (& amp; h_pointFunction, pComputeThreshold, sizeof (pointFunction_t)) to function pointers Copy   

you h_pointFunction __ device __ to have a parameter for your kernel, which can use it.

  // Your parameter is calling __global__ as zero kernel to call your __device__ function indicator (PointFunction_t pPointOperation) {unsigned char tmp; ... tmp = (* pPointOperation) (TMP, 150.0) ...} Calling the kernel in the host code, your host-party __device__ function pointer returns to the kernel & lt; & Lt; & Lt; ... & gt; & Gt; & Gt; ; (H_pointFunction);   

Hopefully something made in everyone, it changes your f1 function to be a __ device __ function and to follow a similar process (Typedefs are not necessary, but they do the code well) To get your kernel looks like it is to get a functional function on the host-side as a function pointer, I function the Pineers CUDA sample

No comments:

Post a Comment