# cudaMallocArray Bug CUDA error: invalid argument

**URL:** <https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647>\
**Category:** CUDA Programming and Performance\
**Created:** [April 28, 2007, 9:01pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647 "2007-04-28T21:01:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [April 28, 2007, 9:01pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/1 "2007-04-28T21:01:20Z")

</div>

so here is the bug I got,

```auto
#define CUERR { cudaError_t err; \

  if ((err = cudaGetLastError()) != cudaSuccess) { \

  printf("CUDA error: %s, line %d\n", cudaGetErrorString(err), __LINE__ ); return NULL; }}

texture<float, 2, cudaReadModeElementType> text;

extern "C"

int bug(unsigned int x, unsigned int y)

{

  cudaArray* cu_array;

  printf("malloc  Array:(%d,%d)\n",x,y);

  CUDA_SAFE_CALL( cudaMallocArray( &cu_array, &text.channelDesc, x, y));

  CUERR 

  CUDA_SAFE_CALL(cudaFreeArray(cu_array));

  printf("Succes\n");

  return 1;

}

```

can anybody try to reproduce it, to know if it’s just me…

I got an invalid argument error with x or y greater than 13345.

is this the limitation size with cudaArray ?

I have the 8800GTX under linux

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [April 28, 2007, 9:21pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/2 "2007-04-28T21:21:01Z")

</div>

On an internal build, I cannot replicate your bug (so if it was there, it has been fixed).

[fatica@dhcp ~]$ ./a.out  
malloc Array:(128,128)  
Succes  
fatica@dhcp ~]$ ./a.out  
malloc Array:(12800,128)  
Succes  
fatica@dhcp ~]$ ./a.out  
malloc Array:(22800,128)  
Succes  
[fatica@dhcp- ~]$ ./a.out  
malloc Array:(22800,22800)  
CUDA error: out of memory, line 15

There will be a new release in few weeks.

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [April 30, 2007, 4:22pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/3 "2007-04-30T16:22:18Z")

</div>

> [@](#):
>
> On an internal build, I cannot replicate your bug (so if it was there, it has been fixed).
> 
> [fatica@dhcp ~]$ ./a.out
> 
> malloc&nbsp; Array:(128,128)
> 
> Succes
> 
> fatica@dhcp ~]$ ./a.out
> 
> malloc&nbsp; Array:(12800,128)
> 
> Succes
> 
> fatica@dhcp ~]$ ./a.out
> 
> malloc&nbsp; Array:(22800,128)
> 
> Succes
> 
> [fatica@dhcp- ~]$ ./a.out
> 
> malloc&nbsp; Array:(22800,22800)
> 
> CUDA error: out of memory, line 15
> 
> There will be a new release in few weeks.
> 
> [snapback]190698[/snapback]

Ok, but if you do malloc Array:(14400,1)

you get : CUDA error: invalid argument, line 15

why this ? I guess I should be allowed to have the second dimension equal to 1 no ?

also, I found out why I was having such limitation, the reason was I had another openGl process running in the same time on the device which was taking memory.

Now my other question, what is the limitation of the cudaymallocArray, is it the 768 mb of the device minus some runtime memory usage ?

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [April 30, 2007, 6:16pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/4 "2007-04-30T18:16:51Z")

</div>

I guess I also have a memory problem,

if I create two textures :  
texture\<float4, 2, cudaReadModeElementType\> t1;  
texture\<float, 2, cudaReadModeElementType\> t2;

I allocate/bind them :  
malloc t1:(248,31)  
Succes  
malloc t2:(30752,4)  
Succes

all the elements of t2 are presumably such that texfetch(t2, i, 0…3) = i;

however, when I do texfetch(t2, 0, 0…3)  
I get 16384.0 (where I should get 0)  
and texfetch(t2, 1, 0…3)  
I get 16385.0 (where I should get 1)  
then if I do texfetch(t2, 16384, 0…3) I get something random. same for other value beyond that.

So why is that ? is my two textures too big or something ? I really don’t understand…

and of course if I use smaller cudaArray like :  
malloc textInput:(168,21)  
malloc textFilter:(14112,4)

everything works fine…

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [April 30, 2007, 9:20pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/5 "2007-04-30T21:20:27Z")

</div>

In the current release, if the second dimension is equal to 1, the first dimension has to be smaller than 8192. There is a 8K limit for 1D Texture arrays and CUDA views a 2D array Nx1 as a 1D array of length N.

We will improve the documentation.

> [@](#):
>
> Ok, but if you do malloc&nbsp; Array:(14400,1)
> 
> you get : CUDA error: invalid argument, line 15
> 
> why this ? I guess I should be allowed to have the second dimension equal to 1 no ?

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [April 30, 2007, 9:37pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/6 "2007-04-30T21:37:43Z")

</div>

> [@](#):
>
> In the current release, if the second dimension is equal to 1, the first dimension has to be smaller than 8192. There is a 8K limit for 1D Texture arrays and CUDA views a 2D array Nx1 as a 1D array of length N.
> 
> We will improve the documentation.
> 
> [snapback]191545[/snapback]

Ok, it makes more sense,

I guess if I want to use more than 8192, I’ll put y equal 2. would it be ok?

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [April 30, 2007, 9:49pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/7 "2007-04-30T21:49:12Z")

</div>

Yes, for now that is a good solution.

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [May 1, 2007, 12:30am UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/8 "2007-05-01T00:30:00Z")

</div>

> [@](#):
>
> Yes, for now that is a good solution.
> 
> [snapback]191554[/snapback]

But actually it doesn’t solve my problem.

I still can’t use texture where any dimension is bigger than 16834.

I have no idea where this number come from, but if I have a 2d texture like this :

malloc Array:(16834,x) with x \>= 1

my values are messed up in the texture as I described above

why ?

---

<div class="post-metadata">

**Author:** ![BARRACUDA](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BARRACUDA](https://forums.developer.nvidia.com/u/BARRACUDA)\
**Post date:** [May 31, 2007, 3:49pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/9 "2007-05-31T15:49:39Z")

</div>

Yes, I have the same problem… As soon as I attempt to allocate an array larger than 32768 I get the invalid argument error. Even if I increase my second dimension to an arbitrary number greater than one, I cannot go above this limit.

What’s going on here?

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [June 1, 2007, 2:58pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/10 "2007-06-01T14:58:20Z")

</div>

> [@](#):
>
> Yes, I have the same problem… As soon as I attempt to allocate an array larger than 32768 I get the invalid argument error. Even if I increase my second dimension to an arbitrary number greater than one, I cannot go above this limit.
> 
> What’s going on here?
> 
> [snapback]203764[/snapback]

Well what I ended up doing was to use texture up to the max size and if it was bigger then split into several…

I know Cuda is still beta but for the next release they should definitely give the specifications of texture/CudaArray.

---

<div class="post-metadata">

**Author:** ![BARRACUDA](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BARRACUDA](https://forums.developer.nvidia.com/u/BARRACUDA)\
**Post date:** [June 1, 2007, 5:50pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/11 "2007-06-01T17:50:54Z")

</div>

And, if you do that, can you use up to the maximum device memory (theoretically)? And, if you can use all that memory, I wonder what kind of overhead that implies. Aka, I wonder if it’s worth it in the end…

---

<div class="post-metadata">

**Author:** ![benoit](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@benoit](https://forums.developer.nvidia.com/u/benoit)\
**Post date:** [June 1, 2007, 6:01pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/12 "2007-06-01T18:01:02Z")

</div>

> [@](#):
>
> And, if you do that, can you use up to the maximum device memory (theoretically)? And, if you can use all that memory, I wonder what kind of overhead that implies. Aka, I wonder if it’s worth it in the end…
> 
> [snapback]204185[/snapback]

well yeah you can malloc as many cudaarray as you want (up to memory available)

and then use you unique texture to bind them all, one by one.

Although keep in mind you’re gonna have to run several kernels since you can only bind the texture from the host.

---

<div class="post-metadata">

**Author:** ![BARRACUDA](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BARRACUDA](https://forums.developer.nvidia.com/u/BARRACUDA)\
**Post date:** [June 1, 2007, 7:06pm UTC](https://forums.developer.nvidia.com/t/cudamallocarray-bug-cuda-error-invalid-argument/647/13 "2007-06-01T19:06:50Z")

</div>

> [@](#):
>
> well yeah you can malloc as many cudaarray as you want (up to memory available)
> 
> and then use you unique texture to bind them all, one by one.
> 
> Although keep in mind you’re gonna have to run several kernels since you can only bind the texture from the host.
> 
> [snapback]204191[/snapback]

Couldn’t you bind them all up front and then just texfetch the appropriate one from within one kernel?
