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

_cpp_source = r"""
#include <torch/extension.h>
torch::Tensor triangular_mm_cuda(torch::Tensor A, torch::Tensor B);
"""

_cuda_source = r"""
#include <torch/extension.h>
#include <c10/cuda/CUDAGuard.h>
#include <c10/cuda/CUDAStream.h>
#include <c10/cuda/CUDAException.h>
#include <cuda_runtime.h>
#include <cuda_fp16.h>
#include <mma.h>

namespace wmma = nvcuda::wmma;

constexpr int TILE = 128;
constexpr int BK = 32;
constexpr int AS = 40;
constexpr int BS = 136;
constexpr int NT = 256;

union SharedStorage {
    struct {
        __half ah[TILE * AS];
        __half al[TILE * AS];
        __half bh[BK * BS];
        __half bl[BK * BS];
    } input;
    float output[8 * 16 * 64];
};

__device__ __forceinline__ void split_store(
    float4 v, __half* high, __half* low
) {
    const __half2 h01 = __floats2half2_rn(v.x, v.y);
    const __half2 h23 = __floats2half2_rn(v.z, v.w);
    const float2 f01 = __half22float2(h01);
    const float2 f23 = __half22float2(h23);

    reinterpret_cast<__half2*>(high)[0] = h01;
    reinterpret_cast<__half2*>(high)[1] = h23;
    reinterpret_cast<__half2*>(low)[0] =
        __floats2half2_rn(v.x - f01.x, v.y - f01.y);
    reinterpret_cast<__half2*>(low)[1] =
        __floats2half2_rn(v.z - f23.x, v.w - f23.y);
}

template<bool FULL>
__device__ __forceinline__ float4 read_four(
    const float* ptr, int row, int col, int n
) {
    if (FULL) {
        return *reinterpret_cast<const float4*>(
            ptr + static_cast<int64_t>(row) * n + col);
    }

    float4 v = make_float4(0.f, 0.f, 0.f, 0.f);
    if (row < n) {
        const int64_t offset = static_cast<int64_t>(row) * n + col;
        if (col     < n) v.x = ptr[offset];
        if (col + 1 < n) v.y = ptr[offset + 1];
        if (col + 2 < n) v.z = ptr[offset + 2];
        if (col + 3 < n) v.w = ptr[offset + 3];
    }
    return v;
}

template<bool FULL>
__global__ void triangular_mm_kernel(
    const float* __restrict__ A,
    const float* __restrict__ B,
    float* __restrict__ C,
    int n
) {
    const int tid = threadIdx.x;
    const int row0 = blockIdx.y * TILE;
    const int col0 = blockIdx.x * TILE;

    if (col0 > row0) {
        if (FULL) {
            for (int p = tid * 4; p < TILE * TILE; p += NT * 4) {
                const int row = row0 + p / TILE;
                const int col = col0 + p % TILE;
                *reinterpret_cast<float4*>(
                    C + static_cast<int64_t>(row) * n + col
                ) = make_float4(0.f, 0.f, 0.f, 0.f);
            }
        } else {
            for (int p = tid; p < TILE * TILE; p += NT) {
                const int row = row0 + p / TILE;
                const int col = col0 + p % TILE;
                if (row < n && col < n)
                    C[static_cast<int64_t>(row) * n + col] = 0.f;
            }
        }
        return;
    }

    __shared__ __align__(32) SharedStorage smem;

    const int warp = tid >> 5;
    const int wr = (warp >> 1) * 32;
    const int wc = (warp & 1) * 64;

    wmma::fragment<wmma::accumulator, 16, 16, 16, float> acc[2][4];

    #pragma unroll
    for (int i = 0; i < 2; ++i) {
        #pragma unroll
        for (int j = 0; j < 4; ++j)
            wmma::fill_fragment(acc[i][j], 0.f);
    }

    const int kend = min(row0 + TILE, n);

    for (int k0 = col0; k0 < kend; k0 += BK) {
        #pragma unroll
        for (int p = tid * 4; p < TILE * BK; p += NT * 4) {
            const int r = p / BK;
            const int k = p % BK;
            const float4 v = read_four<FULL>(A, row0 + r, k0 + k, n);
            split_store(
                v,
                smem.input.ah + r * AS + k,
                smem.input.al + r * AS + k);
        }

        #pragma unroll
        for (int p = tid * 4; p < BK * TILE; p += NT * 4) {
            const int k = p / TILE;
            const int c = p % TILE;
            const float4 v = read_four<FULL>(B, k0 + k, col0 + c, n);
            split_store(
                v,
                smem.input.bh + k * BS + c,
                smem.input.bl + k * BS + c);
        }

        __syncthreads();

        #pragma unroll
        for (int kk = 0; kk < BK; kk += 16) {
            wmma::fragment<
                wmma::matrix_a, 16, 16, 16, __half, wmma::row_major
            > ah[2], al[2];

            #pragma unroll
            for (int i = 0; i < 2; ++i) {
                wmma::load_matrix_sync(
                    ah[i], smem.input.ah + (wr + i * 16) * AS + kk, AS);
                wmma::load_matrix_sync(
                    al[i], smem.input.al + (wr + i * 16) * AS + kk, AS);
            }

            #pragma unroll
            for (int j = 0; j < 4; ++j) {
                wmma::fragment<
                    wmma::matrix_b, 16, 16, 16, __half, wmma::row_major
                > bh, bl;

                wmma::load_matrix_sync(
                    bh, smem.input.bh + kk * BS + wc + j * 16, BS);
                wmma::load_matrix_sync(
                    bl, smem.input.bl + kk * BS + wc + j * 16, BS);

                #pragma unroll
                for (int i = 0; i < 2; ++i) {
                    wmma::mma_sync(acc[i][j], ah[i], bl, acc[i][j]);
                    wmma::mma_sync(acc[i][j], al[i], bh, acc[i][j]);
                    wmma::mma_sync(acc[i][j], ah[i], bh, acc[i][j]);
                }
            }
        }
        __syncthreads();
    }

    #pragma unroll
    for (int i = 0; i < 2; ++i) {
        #pragma unroll
        for (int j = 0; j < 4; ++j) {
            wmma::store_matrix_sync(
                smem.output + warp * 1024 + j * 16,
                acc[i][j], 64, wmma::mem_row_major);
        }

        __syncthreads();

        for (int p = tid; p < 8192; p += NT) {
            const int w = p / 1024;
            const int local = p % 1024;
            const int row = row0 + (w >> 1) * 32 + i * 16 + local / 64;
            const int col = col0 + (w & 1) * 64 + local % 64;

            if (FULL || (row < n && col < n)) {
                C[static_cast<int64_t>(row) * n + col] =
                    col <= row ? smem.output[p] : 0.f;
            }
        }

        __syncthreads();
    }
}

torch::Tensor triangular_mm_cuda(torch::Tensor A, torch::Tensor B) {
    TORCH_CHECK(A.is_cuda() && B.is_cuda(), "Expected CUDA tensors");
    TORCH_CHECK(A.device() == B.device(), "Expected matching devices");
    TORCH_CHECK(
        A.scalar_type() == at::kFloat && B.scalar_type() == at::kFloat,
        "Expected float32 tensors");
    TORCH_CHECK(
        A.dim() == 2 && B.dim() == 2 &&
        A.size(0) == A.size(1) &&
        B.size(0) == A.size(0) && B.size(1) == A.size(1),
        "Expected equally sized square matrices");

    const c10::cuda::CUDAGuard guard(A.device());
    A = A.contiguous();
    B = B.contiguous();

    const int64_t size = A.size(0);
    TORCH_CHECK(size <= int64_t(TILE) * 65535, "Matrix is too large");

    auto C = torch::empty({size, size}, A.options());
    if (size == 0)
        return C;

    const int n = static_cast<int>(size);
    const dim3 grid((n + TILE - 1) / TILE, (n + TILE - 1) / TILE);
    const cudaStream_t stream = c10::cuda::getCurrentCUDAStream().stream();

    if (n % TILE == 0) {
        triangular_mm_kernel<true><<<grid, NT, 0, stream>>>(
            A.data_ptr<float>(), B.data_ptr<float>(), C.data_ptr<float>(), n);
    } else {
        triangular_mm_kernel<false><<<grid, NT, 0, stream>>>(
            A.data_ptr<float>(), B.data_ptr<float>(), C.data_ptr<float>(), n);
    }

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return C;
}
"""

_triangular_ops = load_inline(
    name="triangular_mm_compensated_vectorized_v3",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["triangular_mm_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, A, B):
        if (
            A.is_cuda
            and B.is_cuda
            and A.dtype == torch.float32
            and B.dtype == torch.float32
        ):
            return _triangular_ops.triangular_mm_cuda(A, B)
        return torch.tril(torch.matmul(A, B))
```