Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result when running the README example #320

Closed
rubenjr0 opened this issue May 16, 2024 · 11 comments
Closed

Incorrect result when running the README example #320

rubenjr0 opened this issue May 16, 2024 · 11 comments

Comments

@rubenjr0
Copy link

Hello! I think I've encountered a bug. When running this example from the readme:

def sum(depth, x):
  switch depth:
    case 0:
      return x
    case _:
      fst = sum(depth-1, x*2+0) # adds the fst half
      snd = sum(depth-1, x*2+1) # adds the snd half
      return fst + snd
    
def main:
  return sum(30, 0)

The output is 0. I've tried bend run, bend run-c, and bend gen-cu (bend run-cu says cuda is not available, so I manually compile it with nvcc).

The output on my machine when running sum(24, 0) is 8388608, but on equivalent Haskell and Python programs the programs return 140737479966720. The results start to diverge when depth>=13.

I was wondering what could be causing these issues, both the incorrect result when depth>=13, and the result=0 when depth>=25.

My computer specs:

  • OS: Pop_OS 22.04
  • CPU: AMD Ryzen 5 2600x (12 cores)
  • GPU: NVIDIA RTX 4060 ti (16GB)
@VictorTaelin
Copy link
Member

This is not a bug, but a limitation: Bend only has 24-bit numbers, so, results are always mod 2^24. We will, not in a far future, add u32 and u64. Thanks for reporting!

@kings177
Copy link
Member

kings177 commented May 16, 2024

re-openning the issue regarding this problem:

(bend run-cu says cuda is not available, so I manually compile it with nvcc)

can you please tell me which version of the cuda toolkit you're using?

@pema99
Copy link

pema99 commented May 17, 2024

I'm facing the same issue, FWIW - run-cu says CUDA not available, but I do have CUDA and nvcc installed.

$ nvidia-smi
Fri May 17 02:10:24 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.103                Driver Version: 537.13       CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 2070 ...    On  | 00000000:01:00.0  On |                  N/A |
| 28%   55C    P0              70W / 215W |   5308MiB /  8192MiB |     38%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

Interestingly, if I manually compile the output of gen-cu (same program as OP), I get an error:

$ nvcc -O3 foo.cu -o x && ./x
...
Failed to launch kernels (error code invalid argument)!

I'm using WSL

@kings177
Copy link
Member

kings177 commented May 17, 2024

@pema99 oh sorry, can you try installing a newer version of the cuda toolkit to see if it works? (not the one from apt, apt's one is pretty old and lacks a lot of features)

@pema99
Copy link

pema99 commented May 17, 2024

@pema99 oh sorry, can you try installing a newer version of the cuda toolkit to see if it works? (not the one from apt, apt's one is pretty old and lacks a lot of features)

Installed 12.4, same thing

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
Fri May 17 03:12:29 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.76.01              Driver Version: 552.44         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 2070 ...    On  |   00000000:01:00.0  On |                  N/A |
|  0%   58C    P0             55W /  215W |     684MiB /   8192MiB |      1%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

@pema99
Copy link

pema99 commented May 17, 2024

And still the same Failed to launch kernels (error code invalid argument)! error if I try to use gen-cu and nvcc manually.

@kings177
Copy link
Member

kings177 commented May 17, 2024

@pema99 can you try decreasing the number of TPB and/or BPG on src/hvm.cu to see if it works please? maybe start with the TPB to 6, and if it doesn't work you do kinda of binary search on it to see which values work.
image

(i'm assuming this is the root cause of the problem, considering we only catered to the 4090, since that is the best GPU there is currently, and the one we have)

@rubenjr0
Copy link
Author

re-openning the issue regarding this problem:

(bend run-cu says cuda is not available, so I manually compile it with nvcc)

can you please tell me which version of the cuda toolkit you're using?

Currently using cuda 12.4, and the 550.67 NVIDIA drivers.

@kings177
Copy link
Member

@rubenjr0 not the driver, but the cuda compiler itself, can you type nvcc --version and tell me the output please?

@rubenjr0
Copy link
Author

@rubenjr0 not the driver, but the cuda compiler itself, can you type nvcc --version and tell me the output please?

Sure, my bad. Here's the output:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

@kings177
Copy link
Member

kings177 commented May 17, 2024

Closing this and continuing on the HVM repo, considering this is an HVM issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants