```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.
# The operation is purely memory-bound, so the key optimizations are:
#   1. Vectorized 128-bit (float4) global memory loads/stores for peak bandwidth.
#   2. A scalar fallback path for tensors whose element count is not divisible by 4.
scalar_mul_source = """
#include <torch/extension.h>
#include <cuda_runtime.h>

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

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

torch::Tensor scalar_mul_cuda(torch::Tensor A, double s) {
    TORCH_CHECK(A.is_cuda(), "A must be a CUDA tensor");
    TORCH_CHECK(A.scalar_type() == at::kFloat, "A must be float32");

    auto Ac = A.contiguous();
    auto C = torch::empty_like(Ac);

    long size = Ac.numel();
    if (size == 0) {
        return C;
    }

    float sf = static_cast<float>(s);
    long size4 = size / 4;
    long rem = size - size4 * 4;

    const int block_size = 256;

    if (size4 > 0) {
        long num_blocks = (size4 + block_size - 1) / block_size;
        scalar_mul_vec4_kernel<<<(unsigned int)num_blocks, block_size>>>(
            reinterpret_cast<const float4*>(Ac.data_ptr<float>()),
            reinterpret_cast<float4*>(C.data_ptr<float>()),
            sf,
            size4);
    }

    if (rem > 0) {
        int tail_blocks = (int)((rem + block_size - 1) / block_size);
        scalar_mul_tail_kernel<<<tail_blocks, block_size>>>(
            Ac.data_ptr<float>(),
            C.data_ptr<float>(),
            sf,
            size4 * 4,
            size);
    }

    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=[""],
    extra_ldflags=[""],
)


class ModelNew(nn.Module):
    """
    Optimized model that performs a 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:
        """
        Performs matrix-scalar multiplication.

        Args:
            A: Input matrix of shape (M, N)
            s: Scalar value

        Returns:
            C: Resulting matrix of shape (M, N)
        """
        if A.is_cuda and A.dtype == torch.float32:
            return self.scalar_mul.scalar_mul_cuda(A, float(s))
        return A * s
```