composable_kernel icon indicating copy to clipboard operation
composable_kernel copied to clipboard

Polymorphic function "IsSupportedArgument(const BaseArgument* p_base_arg): should check if pointer can be down-casted

Open asroy opened this issue 2 years ago • 0 comments

  • [ ] Have a PR that fix every Device Op class

Issue brought up by @j4yan https://github.com/ROCmSoftwarePlatform/composable_kernel/pull/128#discussion_r832736874

Example Fix (need to be applied for all Device Op:

--- a/include/ck/tensor_operation/gpu/device/device_gemm_xdl.hpp
+++ b/include/ck/tensor_operation/gpu/device/device_gemm_xdl.hpp
@@ -412,9 +412,17 @@ struct DeviceGemmXdl
     }

     // polymorphic
-    bool IsSupportedArgument(const BaseArgument* p_arg) override
+    bool IsSupportedArgument(const BaseArgument* p_base_arg) override
     {
-        return IsSupportedArgument(*dynamic_cast<const Argument*>(p_arg));
+        const Argument* p_arg = dynamic_cast<const Argument*>(p_base_arg);
+
+        // make sure p_base_arg can be downcasted
+        if(!p_arg)
+        {
+            return false;
+        }
+
+        return IsSupportedArgument(*p_arg);
     }

asroy avatar Mar 24 '22 02:03 asroy