# Cublas function call from within the kernel ? is it possible ?

**URL:** <https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167>\
**Category:** CUDA Programming and Performance\
**Created:** [March 29, 2008, 2:15pm UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167 "2008-03-29T14:15:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maringanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@maringanti](https://forums.developer.nvidia.com/u/maringanti)\
**Post date:** [March 29, 2008, 2:15pm UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167/1 "2008-03-29T14:15:49Z")

</div>

Is it possible to call cublas functions/api from within the kernel code ? like

```auto
__global__ kernel(....) {

// some declarations

cublasSgemm(....);

//

.

}

```

---

<div class="post-metadata">

**Author:** ![bashflyng](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bashflyng](https://forums.developer.nvidia.com/u/bashflyng)\
**Post date:** [April 2, 2008, 12:48am UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167/2 "2008-04-02T00:48:39Z")

</div>

I would say no. That function is a wrapper to a kernel call, and you can’t call a kernel from within a kernel.  
Also, a function must have the **device** modifier for it to be able to be called from a kernel, and AFAIK that’s not the case with cublas and cufft functions.

---

<div class="post-metadata">

**Author:** ![maringanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@maringanti](https://forums.developer.nvidia.com/u/maringanti)\
**Post date:** [April 2, 2008, 9:41am UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167/3 "2008-04-02T09:41:56Z")

</div>

> [@](#):
>
> I would say no. That function is a wrapper to a kernel call, and you can’t call a kernel from within a kernel.
> 
> Also, a function must have the **device** modifier for it to be able to be called from a kernel, and AFAIK that’s not the case with cublas and cufft functions.
> 
> [snapback]355090[/snapback]

Thanks.

I have another question, say I have a code like the following

```auto
void function (input, output) {

float abc;

float xyz;

cublasInit();

abc = cublasSdot(.....);

xyz = cublasSdot(....);

}

```

will the above code be valid ? What i mean to ask is will the floats i have declared, be on the host or the gpu ?

Is the only way to declare variables on the gpu from the host be via cudaMalloc and cublasAlloc functions ?

---

<div class="post-metadata">

**Author:** ![jordyvaneijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jordyvaneijk](https://forums.developer.nvidia.com/u/jordyvaneijk)\
**Post date:** [April 2, 2008, 9:49am UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167/4 "2008-04-02T09:49:44Z")

</div>

> [@](#):
>
> Thanks.
> 
> I have another question, say I have a code like the following
> 
> ```auto
> void function (input, output) {
> 
> float abc;
> 
> float xyz;
> 
> cublasInit();
> 
> abc = cublasSdot(.....);
> 
> xyz = cublasSdot(....);
> 
> }
> 
> ```
> 
> will the above code be valid ? What i mean to ask is will the floats i have declared, be on the host or the gpu ?
> 
> Is the only way to declare variables on the gpu from the host be via cudaMalloc and cublasAlloc functions ?
> 
> [snapback]355290[/snapback]

These floats you have are on the host. I think you can also declare host variables and give them to the kernel then the kernel will allocate space for it in shared mem. But I’m not sure about that.

What about the first question you did. I read somewhere that the cufft and cublas source had been released. maybe you can translate the kernel that is used to a device function.

---

<div class="post-metadata">

**Author:** ![maringanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@maringanti](https://forums.developer.nvidia.com/u/maringanti)\
**Post date:** [April 2, 2008, 10:58am UTC](https://forums.developer.nvidia.com/t/cublas-function-call-from-within-the-kernel-is-it-possible/3167/5 "2008-04-02T10:58:35Z")

</div>

> [@](#):
>
> What about the first question you did. I read somewhere that the cufft and cublas source had been released. maybe you can translate the kernel that is used to a device function.

I just got my hands on the source code. I did not think of this. I will see what I can do and get back.
