0

I am allocating memory in the Jetson TX2. It has 8GB of RAM. I need to specify the maximun GPU memory size available for TensorRT.

max_workspace_size_bytes = (has to be an integer)

I have seen some examples using these "values":

1<<20 = 1048576 (decimal)
      = 0001 0000 0000 0000 0000

1<<30 = 1073741824
      = 0001 0000 0000 0000 0000 0000 0000

But if I have 8GB of RAM, how can "1048576" or "1073741824" represent a part of RAM?

I have used this to allocate 3GB:

3*(10**9)

But I would like to understand the other way of representing a number.

Aizzaac
  • 3,146
  • 8
  • 29
  • 61
  • 1
    The example values are a bit off, 65536 = 1<<16 and 16777216 = 1 <<24 (you can see that easily in the binary representation by counting the trailing zeroes) – harold Mar 11 '20 at 22:06
  • ok. I will check the calculator that I have used. – Aizzaac Mar 12 '20 at 13:55

3 Answers3

2

Perhaps you're having a "Gb vs Gib" problem. Usually, 3 Gigas of RAM refers to 3,221,225,472 bytes instead of 3,000,000,000.

The first value is 3 * (2^10)*(2^10)*(2^10), a nice 3 (11) followed by 30 zeros in binary representation, while the second is 3 * (10^3)*(10^3)*(10^3), which is a mess in binary.

This convention of using powers of 2 instead of powers of 10 is the reason why you'll see people writing a 3Gb as 3 << 30:

3 << 30 == 3 * (1 << 10) * (1 << 10) * (1 << 10)
        == 3 * (2**10 * 2**10 * 2**10)
        == 3 * (2**30)

There's a related question and a good Wikipedia article about this issue if you want to learn more.

ArthurW
  • 21
  • 1
  • 2
1

You can sum them up.

((1<<30)+(1<<31))

Or bitwise OR them.

((1<<30) | (1<<31))

Or shift a larger value than 1, e.g. 3.

(3<<30)
Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
0
3GB = 3,221,225,472
      1100 0000 0000 0000 0000 0000 0000 0000

3<<30 = 3GB
Aizzaac
  • 3,146
  • 8
  • 29
  • 61