```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

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

scalar_mul_cuda_source = """
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda_runtime.h>

// Vectorized kernel: each thread handles 4 elements via float4 loads/stores
__global__ void scalar_mul_vec4_kernel(const float4* __restrict__ A,
                                       float4* __restrict__ C,
                                       const float s,
                                       const long n_vec) {
    long i = (long)blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n_vec) {
        float4 v = A[i];
        v.x *= s;
        v.y *= s;
        v.z *= s;
        v.w *= s;
        C[i] = v;
    }
}

// Scalar fallback kernel for sizes not divisible by 4
__global__ void scalar_mul_kernel(const float* __restrict__ A,
                                  float* __restrict__ C,
                                  const float s,
                                  const long n) {
    long i = (long)blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n) {
        C[i] = A[i] * s;
    }
}

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

    auto A_c = A.contiguous();
    auto C = torch::empty_like(A_c);
    const long n = A_c.numel();
    if (n == 0) {
        return C;
    }

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

    if ((n & 3) == 0) {
        const long n_vec = n >> 2;
        const long grid = (n_vec + block - 1) / block;
        scalar_mul_vec4_kernel<<<(unsigned int)grid, block, 0, stream>>>(
            reinterpret_cast<const float4*>(A_c.data_ptr<float>()),
            reinterpret_cast<float4*>(C.data_ptr<float>()),
            sf, n_vec);
    } else {
        const long grid = (n + block - 1) / block;
        scalar_mul_kernel<<<(unsigned int)grid, block, 0, stream>>>(
            A_c.data_ptr<float>(), C.data_ptr<float>(), sf, n);
    }

    return C;
}
"""

scalar_mul = load_inline(
    name="scalar_mul_ext",
    cpp_sources=scalar_mul_cpp_source,
    cuda_sources=scalar_mul_cuda_source,
    functions=["scalar_mul_cuda"],
    verbose=False,
    extra_cuda_cflags=["-O3"],
)


class ModelNew(nn.Module):
    """
    Optimized model that performs matrix-scalar multiplication (C = A * s)
    using a custom CUDA kernel with vectorized (float4) memory accesses.
    """
    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:
            return self.scalar_mul.scalar_mul_cuda(A, float(s))
        return A * s
```