cutlass icon indicating copy to clipboard operation
cutlass copied to clipboard

[QST] Got cutlass error: Error Internal at: 500

Open ShqWW opened this issue 3 years ago • 10 comments

Describe the bug When i run the depthwise convolution example ./46_depthwise_simt_conv2dfprop , it report a bug: Got cutlass error: Error Internal at: 500

My GPU is Titan Xp, the cuda version is 11.8, and I compile the cutlass with -DCUTLASS_NVCC_ARCHS=80;

ShqWW avatar Jan 18 '23 11:01 ShqWW

Hi, @ShengqiWang.

I think there are two issues here.

My GPU is Titan Xp, the cuda version is 11.8, and I compile the cutlass with -DCUTLASS_NVCC_ARCHS=80;

Note that Titan Xp has compute capability of 6.1. Thus, you should use -DCUTLASS_NVCC_ARCHS=61

Even after making this change, I also saw an error when attempting to reproduce the issue on P100 (which is similar to Titan Xp, but has compute capability 6.0). By adding the following code here, one can determine that the error is being caused by the fact that the default configuration in example 46 uses more shared memory than is available on the P100:

    if (status != cudaSuccess) {
      std::cout << "CUDA ERROR: " << cudaGetErrorString(status) << std::endl;
      std::cout << "Smem size is: " << smem_size << std::endl;
      cudaDeviceProp properties;
      int device_idx;
      cudaError_t result = cudaGetDevice(&device_idx);
      result = cudaGetDeviceProperties(&properties, device_idx);
      std::cout << "Available smem is: " << properties.sharedMemPerBlockOptin << std::endl;
      return Status::kErrorInternal;
    }

This printed out:

CUDA ERROR: invalid argument
Smem size is: 59392
Available smem is: 49152
Got cutlass error: Error Internal at: 500

To reduce the amount of shared memory used by the kernel, you can reduce the NumStages parameter here. Changing this parameter to 2 caused the example to work for me.

I hope this helps!

jackkosaian avatar Jan 18 '23 17:01 jackkosaian

There are two more issues.

  1. I have changed the NumStges parameter to 2, and the output is normal. But when i changed the filter size to 7, ./46_depthwise_simt_conv2dfprop --n=1 --h=112 --w=112 --c=32 --k=32 --r=7 --s=7 --g=32 --splitk=108 the output is Got cutlass error: Error Invalid Problem at: 490

  2. In reality, I have tried -DCUTLASS_NVCC_ARCHS=60, 61 and 80. But when I compile with 61 and 61, there is another issue. When i run cmake .. -DCUTLASS_NVCC_ARCHS="60;61" -DCUTLASS_LIBRARY_OPERATIONS=conv2d

and ./tools/profiler/cutlass_profiler --operation=conv2d --n=8 --h=224 --w=224 --c=128 --k=128 --r=3 --s=3 there is no output. And there is a normal output with 80.

ShqWW avatar Jan 19 '23 04:01 ShqWW

./46_depthwise_simt_conv2dfprop --n=1 --h=112 --w=112 --c=32 --k=32 --r=7 --s=7 --g=32 --splitk=108

The error Error Invalid Problem at: 490 specifies that the error was raised on line 490 of the example. From this line, we see that the error is raised in the can_implement() method. This method is typically used by CUTLASS kernels to determine whether the provided problem size is supported by the kernel. The failure occurring here hints to us that there is some mismatch between the problem size you specify (i.e., --n=1 --h=112 --w=112 --c=32 --k=32 --r=7 --s=7 --g=32 --splitk=108) and the kernel that was declared.

In this case, the issue at hand is that DefaultDepthwiseDirect2dConvFprop has a template parameter FilterShape that must match the --r and --s values passed in to kernel. This is defined here in example 46 to be cutlass::MatrixShape<3, 3>. You will need to change FilterShape to be cutlass::MatrixShape<7, 7> if you would like to use --r=7 --s=7.

In reality, I have tried -DCUTLASS_NVCC_ARCHS=60, 61 and 80...

I have tried reproducing this error on a Titan Xp. The profiler is built and runs just fine for me. Could you please paste the contents of the directory build/tools/library/generated/conv2d/ after you have run cmake .. -DCUTLASS_NVCC_ARCHS="60;61" -DCUTLASS_LIBRARY_OPERATIONS=conv2d?

jackkosaian avatar Jan 19 '23 18:01 jackkosaian

@ShqWW has your issue been resolved?

mnicely avatar Feb 03 '23 14:02 mnicely

@jackkosaian I had the same problem. I followed this issue by setting filtershape to 5, 5 and changing numstages to 2 to avoid insufficient smem. It works well. But when I enlarge the kernel size to 7, even numstages 2 is not sufficient for me (with Nvidia V100). Setting numstages to 1 leads to incorrect and random results so I think the least number of numstages is 2. How can I solve the insufficient smem problem? I want to test the performance of larger kernels such as 17 or 13.

Gaffey avatar Feb 14 '23 07:02 Gaffey

Hi, @Gaffey. I am unable to reproduce this. When I run the example with a 7x7 filter using 2 stages, I see ~61 KB of shared memory being used, whereas the V100 has 96 KB of shared memory.

Could you please paste the diff of your changes to example 46 that is causing you to hit this error?

jackkosaian avatar Feb 14 '23 15:02 jackkosaian

Hi, @Gaffey. I am unable to reproduce this. When I run the example with a 7x7 filter using 2 stages, I see ~61 KB of shared memory being used, whereas the V100 has 96 KB of shared memory.

Could you please paste the diff of your changes to example 46 that is causing you to hit this error?

I changed the data format from float32 to float16, and then I make it to run the example with a 7x7 filter. However, it is impossible to run a 17x17 filter. I try to modify the var groups_per_cta to 32 and find that the performance is harmed. Is there any better methods? @jackkosaian

Gaffey avatar Feb 15 '23 01:02 Gaffey

Thank you for clarifying.

I try to modify the var groups_per_cta to 32

You're on the right track by reducing parameters like this. To reduce the shared memory used, one must reduce either the activation size or filter size (see how shared memory used is calculated from these parameters here). Since you are fixing filter size, your best bet will be to try to reduce activation size. You can see the parameters that go into this component here.

and find that the performance is harmed

What is the baseline you are comparing against when you state that performance is "harmed?" You are right that it is typically preferable to use larger thread block shapes. However, in this case, reducing thread block shape is necessary for the kernel to run at all.

jackkosaian avatar Feb 15 '23 02:02 jackkosaian

A general way to reduce the smem usage is to reduce the threadBlockOutputShape size , filterShape size, or group_per_cta. If none of these settings work, then try the kAnalytic version which uses conv2d algorithm.

However, it is impossible to run a 17x17 filter. I try to modify the var groups_per_cta to 32 and find that the performance is harmed.

Group_per_cta could be 16 as well. With below settings, the smem usage is around 46KB for float16,

// This code section describes the groups a thread block will compute
constexpr int groups_per_cta = 16;

// This code section describes the output tile <N, O, P, Q> a thread block will compute
using ThreadBlockOutputShape = cutlass::conv::TensorNHWCShape<1, 8, 8, groups_per_cta>;

// This code section describes the filter shape <R, S>
using FilterShape = cutlass::MatrixShape<17, 17>;

// Number of pipelines you want to use
constexpr int NumStages = 2;

If without splitK, the perf of Group_per_cta =16 is better than Group_per_cta =32 on my local ampere GPU.

# Group_per_cta =16
Layer,N,H,W,C,K,R,S,G,stride_h,stride_w,dilation_h,dilation_w,splitK,Runtime,GFLOPs
conv_1,1,128,128,32,32,17,17,32,1,1,1,1,1,14.7565,20.5359

# Group_per_cta =32
Layer,N,H,W,C,K,R,S,G,stride_h,stride_w,dilation_h,dilation_w,splitK,Runtime,GFLOPs
conv_1,1,128,128,32,32,17,17,32,1,1,1,1,1,17.0999,17.7216

To improve the perf, splitK option is a big hammer. Here is the result on my local ampere GPU. With Group_per_cta =16, if I enable the splitK, the perf would be much better than w/o splitK. --splitk=108

Layer,N,H,W,C,K,R,S,G,stride_h,stride_w,dilation_h,dilation_w,splitK,Runtime,GFLOPs
conv_1,1,128,128,32,32,17,17,32,1,1,1,1,108,0.45568,665.025

Ethan-Yan27 avatar Feb 15 '23 09:02 Ethan-Yan27

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Mar 17 '23 10:03 github-actions[bot]