gemini-code-assist[bot] commented on code in PR #374: URL: https://github.com/apache/tvm-ffi/pull/374#discussion_r2656128552
########## python/tvm_ffi/cpp/dtype.py: ########## @@ -0,0 +1,104 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Utilities for C++ dtype conversion.""" + +from __future__ import annotations + +import functools +from typing import Any, Literal + +CPU_DTYPE_MAP = { + "int8": "int8_t", + "int16": "int16_t", + "int32": "int32_t", + "int64": "int64_t", + "uint8": "uint8_t", + "uint16": "uint16_t", + "uint32": "uint32_t", + "uint64": "uint64_t", + "float32": "float", + "float64": "double", + "bool": "bool", +} + +CUDA_DTYPE_MAP = { + "float16": "__half", + "bfloat16": "__nv_bfloat16", + "float8_e4m3fn": "__nv_fp8_e4m3", + # "float8_e4m3fnuz": "__nv_fp8_e4m3", + "float8_e5m2": "__nv_fp8_e5m2", + # "float8_e5m2fnuz": "__nv_fp8_e5m2", + "float8_e8m0fnu": "__nv_fp8_e8m0", Review Comment:  The commented-out lines for `float8_e4m3fnuz` and `float8_e5m2fnuz` can be confusing. If these dtypes are not supported for the CUDA backend, it's cleaner to remove these lines entirely. This avoids ambiguity for future maintainers about whether this is an incomplete feature or an intentional omission. ```suggestion "float8_e4m3fn": "__nv_fp8_e4m3", "float8_e5m2": "__nv_fp8_e5m2", "float8_e8m0fnu": "__nv_fp8_e8m0", ``` ########## include/tvm/ffi/extra/dtype.h: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*! + * \file tvm/ffi/extra/dtype.h + * \brief Type traits to map C++ types to DLPack dtypes. + */ +#ifndef TVM_FFI_EXTRA_DTYPE_H_ +#define TVM_FFI_EXTRA_DTYPE_H_ + +#include <dlpack/dlpack.h> + +#include <type_traits> + +// Common for both CUDA and HIP +struct __half; + +// CUDA +struct __nv_fp8_e4m3; +struct __nv_bfloat16; +struct __nv_fp8_e5m2; +struct __nv_fp8_e8m0; +struct __nv_fp4_e2m1; +struct __nv_fp4x2_e2m1; + +// HIP +struct __hip_bfloat16; +struct hip_bfloat16; // i don't know why this is a struct instead of alias... Review Comment:  This comment appears to be a personal note and is a bit informal for source code. It would be best to remove it to maintain a professional tone in the codebase. ```suggestion struct hip_bfloat16; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
