# (Template kernel) VERSUS (Driver API)

**URL:** <https://forums.developer.nvidia.com/t/template-kernel-versus-driver-api/2820>\
**Category:** CUDA Programming and Performance\
**Created:** [February 28, 2008, 5:03pm UTC](https://forums.developer.nvidia.com/t/template-kernel-versus-driver-api/2820 "2008-02-28T17:03:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hochman](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Hochman](https://forums.developer.nvidia.com/u/Hochman)\
**Post date:** [February 28, 2008, 5:03pm UTC](https://forums.developer.nvidia.com/t/template-kernel-versus-driver-api/2820/1 "2008-02-28T17:03:59Z")

</div>

Hi everyone, i have a problem in using templates with driver API. How should i call the kernel if it contains a template. And where should i exactly put CUdeviceptr (kernel, host or both of them)???

template \<class T, CUDPPOperator op\>  
**global** void compactData(T \*oData,  
const unsigned int \*iValidFlags,  
const T \*iData)  
{

…

}

runTest()  
{

…

```
CU_SAFE_CALL( cuFuncSetBlockShape( transform, numThreads, 1, 1 ));
CU_SAFE_CALL( cuFuncSetSharedSize( transform, sizeSharedMemory) );

int offset = 0;
CU_SAFE_CALL(cuParamSeti(transform, offset, outArray)); offset += sizeof(outArray);
CU_SAFE_CALL(cuParamSeti(transform, offset, isValid); offset += sizeof(isValid);
CU_SAFE_CALL(cuParamSeti(transform, offset, const inArray); offset += sizeof(inArray);
CU_SAFE_CALL(cuParamSetSize(transform, offset));
CU_SAFE_CALL( cuLaunchGrid( transform, numBlocks, 1) );

```

…  
}

Any help is appreciated… Thanx…

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [May 21, 2009, 1:46pm UTC](https://forums.developer.nvidia.com/t/template-kernel-versus-driver-api/2820/2 "2009-05-21T13:46:27Z")

</div>

You need to instantiate a template first in any function.

int main()  
{  
// instantiate template functions  
max\_r\<512\> \<\<\< 0, 0, 0\>\>\>(0, 0, 0);  
max\_r\<256\> \<\<\< 0, 0, 0\>\>\>(0, 0, 0);  
max\_r\<128\> \<\<\< 0, 0, 0\>\>\>(0, 0, 0);  
max\_r\<64\> \<\<\< 0, 0, 0\>\>\>(0, 0, 0);  
max\_r\<32\> \<\<\< 0, 0, 0\>\>\>(0, 0, 0);

return 0;  
}

Paste this code into your \*.cu file. Then look into resulting cubin or linkinfo file to get mangled names for functions.

And your CUdeviceptr goes to context creation function if I got your question right.
