```python
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline

# Custom CUDA kernel for matrix-scalar multiplication (C = A * s).
# Uses float4 vectorized loads/stores for maximum memory bandwidth,
# with a scalar fallback path for tensors whose size is not divisible by 4.
scalar_mul_source = """
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda_runtime.h>

__global__ void scalar_mul_vec4_kernel(const float4* __restrict__ A,
                                       float4* __restrict__ C,
                                       float s,
                                       long n4) {
    long idx = blockIdx.x * (long)blockDim.x + threadIdx.x;
    if (idx < n4) {
        float4 a = A[idx];
        a.x *= s;
        a.y *= s;
        a.z *= s;
        a.w *= s;
        C[idx] = a;
    }
}

__global__ void scalar_mul_kernel(const float* __restrict__ A,
                                  float* __restrict__ C,
                                  float s,
                                  long n) {
    long idx = blockIdx.x * (long)blockDim.x + threadIdx.x;
    if (idx < n) {
        C[idx] = A[idx] * s;
    }
}

torch::Tensor scalar_mul_cuda(torch::Tensor A, double s) {
    auto C = torch::empty_like(A);
    const long n = A.numel();
    if (n == 0) {
        return C;
    }

    const float sf = static_cast<float>(s);
    const int block_size = 256;
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();

    if (n % 4 == 0) {
        const long n4 = n / 4;
        const long num_blocks = (n4 + block_size - 1) / block_size;
        scalar_mul_vec4_kernel<<<num_blocks, block_size, 0, stream>>>(
            reinterpret_cast<const float4*>(A.data_ptr<float>()),
            reinterpret_cast<float4*>(C.data_ptr<float>()),
            sf,
            n4);
    } else {
        const long num_blocks = (n + block_size - 1) / block_size;
        scalar_mul_kernel<<<num_blocks, block_size, 0, stream>>>(
            A.data_ptr<float>(),
            C.data_ptr<float>(),
            sf,
            n);
    }

    return C;
}
"""

scalar_mul_cpp_source = (
    "torch::Tensor scalar_mul_cuda(torch::Tensor A, double s);"
)

# Compile the inline CUDA extension
scalar_mul = load_inline(
    name="scalar_mul_ext",
    cpp_sources=scalar_mul_cpp_source,
    cuda_sources=scalar_mul_source,
    functions=["scalar_mul_cuda"],
    verbose=False,
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3", "--use_fast_math"],
)


class ModelNew(nn.Module):
    """
    Optimized model that performs matrix-scalar multiplication (C = A * s)
    using a custom vectorized CUDA kernel.
    """
    def __init__(self):
        super(ModelNew, self).__init__()
        self.scalar_mul = scalar_mul

    def forward(self, A: torch.Tensor, s: float) -> torch.Tensor:
        if A.is_cuda and A.dtype == torch.float32 and A.is_contiguous():
            return self.scalar_mul.scalar_mul_cuda(A, float(s))
        # Fallback for non-CUDA / non-float32 inputs
        return A * s
```