Third-party licences for the code in this directory
==================================================

Some of the CUDA translation units here carry third-party work.  ArWen
distributes them under the Apache License 2.0; the notices below belong to
the parts that carry that work and are reproduced because the licences
those parts carry require it.  The same notices, with the fuller
provenance account, are in the repository's root NOTICE, and the complete
licence texts are in the repository's licenses/ directory, which ships in
the wheel under gpuwm-<version>.dist-info/licenses/.

WHY THIS FILE EXISTS RATHER THAN A HEADER IN EACH .cu
-----------------------------------------------------
Every .cu in this directory is pinned by SHA-256 -- by
tests/test_mp8_frozen.py::FROZEN_MODULE_DIGESTS, which pins the file AND the
assembled compile string the loader hands nvrtc, and by
tests/test_kernel_source_freeze_per_module.py::BASELINE_PINNED, which pins
the rest.  A comment prepended to any of them would move a frozen digest and
turn a numerics gate red for a reason that has nothing to do with numerics.
So the notice sits beside the code instead of inside it, and it ships with
the code: pyproject.toml's package-data glob for gpuwm.core.kernels names
this file explicitly.  The existing headers here are NOT digest-pinned and were
checked against every _EXTRA_HEADERS consumer -- the FP32 maths header and
thompson_aerosol_common.cuh -- and those two do carry their notice inline.
The FP32 trig header also carries its notice inline.

WHAT IS COVERED, AND WHERE
--------------------------
1. Arm optimized-routines (MIT)        -- logf, expf, exp2f, powf, sinf, cosf
2. FDLIBM / Sun Microsystems           -- expm1f, tanhf, atanf, log10f, log1pf,
                                          and binary64 log10, log1p, atan, atan2
3. AER RRTMG (BSD 3-Clause)            -- the legacy RRTMG radiation kernels
4. RTE+RRTMGP (BSD 3-Clause)           -- the default radiation kernels
5. Numerical Recipes Software          -- the GAMMLN log-gamma coefficients
6. CORE-MATH (MIT)                     -- tanf, asinf, acosf, atanf, log10f

Sections 1, 2 and 6 state their scope; section 7 states what none of
the six grants covers.

ArWen's FP32 maths routines are its own implementation.  It carries them
because it grades several physics schemes bitwise against a gfortran
reference built on x86-64 Linux, and CUDA's expf, powf and tgammaf are
different functions from the ones that reference calls.

Scope in this directory: generated by tools/update_kernel_license_scopes.py.
Arm table carriers (23 files): the FP32 maths header, the FP32 trig header,
mynn_libm.cuh, mynn_pbl.cu, mynn_surface_libm.cuh, noahmp_bareflux.cu,
noahmp_bareflux_options.cuh, noahmp_fluxprep.cu, noahmp_leaves.cu,
noahmp_radiation.cu, noahmp_snow.cu, noahmp_soilwater.cu, noahmp_vegeflux.cu,
noahmp_vegprecip.cu, noahmp_water.cu, noahmp_water_options.cuh, p3_gnu239.cuh,
rrtmg_lw.cu, rrtmg_sw.cu, rrtmgp_libm.cuh, thompson_aerosol_libm.cuh,
tiedtke_support.cuh, vert_interp.cu. FDLIBM audited carriers (30 files):
atan_scalar_flt32.cuh, dudhia_sw.cu, flt32_log10_tanh.cuh,
gf_wrf_normalization.cuh, km5_math.cuh, log10_flt32.cuh, mynn_libm.cuh,
mynn_pbl.cu, mynn_surface_libm.cuh, noahmp_bareflux.cu, noahmp_energy.cu,
noahmp_fluxprep.cu, noahmp_glacier.cu, noahmp_leaves.cu, noahmp_vegeflux.cu,
nssl2_diagnostics.cu, nssl2_shape_diagnostics.cu, p3_gnu239.cuh,
portable_libm64.cuh, ruc.cu, scalar_atan.cuh, sfclay.cu, sfclay_classic.cuh,
shinhong.cu, tempo/tempo_common.cuh, terrain_drag.cu,
thompson_aerosol_libm.cuh, thompson_classic.cu, thompson_fork.cu,
ysu_480_topo.cuh.

The wrf_vi_pressure_log helper in vert_interp.cu uses the FP32 maths
header's Arm logf tables and the same range reduction and polynomial, with
fused binary64 operations.  thompson_aerosol_libm.cuh's expf and powf cores
run on the FP32 maths header's Arm exp2f and powf tables.  The binary64
log10, log1p, atan and atan2 reductions (FDLIBM) appear in
thompson_aerosol_libm.cuh, and the binary64 log10 also in
thompson_classic.cu; tempo/tempo_common.cuh carries FDLIBM's binary64 log10
(e_log10.c) as TEMPO's device log10, and portable_libm64.cuh carries the
log1pf (s_log1pf.c) and binary64 log1p (s_log1p.c, through Rust libm's
log1p.rs) of its Rust libm port, whose MIT grant gpuwm's NOTICE records
beside it.  dudhia_sw.cu's log10f is the same reduction as
log10_flt32.cuh's.  The FP32 maths header is not on that second list: it
uses no FDLIBM code, and ArWen's gamma and log-gamma routines are its own
implementation.  The Python counterparts of these routines are in
gpuwm/core/noahmp_libm.py, gpuwm/core/mynn_pbl.py and gpuwm/core/ruc.py,
each of which carries this notice in its own header.
tests/test_cuda_libm_table_copies.py enumerates the table copies and keeps
them in step, so this list is machine-checkable rather than prose.


1. Arm optimized-routines -- logf, expf, exp2f, powf, sinf, cosf
----------------------------------------------------

Written by Szabolcs Nagy and published at
https://github.com/ARM-software/optimized-routines (math/logf.c, math/expf.c,
math/exp2f.c, math/powf.c and the corresponding math/*_data.c) in August 2017.
ArWen's FP32 logf, expf, exp2f and powf are its own implementation of these
published algorithms and use their coefficient tables.  ArWen takes this
material under the MIT branch of Arm's grant.

The sinf / cosf cores and their tables in gpuwm's FP32 trig header follow
Arm's work too: math/sinf.c, math/cosf.c, math/sincosf.h and
math/sincosf_data.c (Arm revision 5e8389113b47a48622d1de8beb9a4adc2b332694,
2018).  Arm's MIT relicensing at 11253b0b9d6b covers the same algorithms and
constants; current Arm fe09d4e7ed62aa24c81b5791c810bc9de70006e9 still offers
MIT.  Its source notices read:

    Copyright (c) 2018-2024, Arm Limited.
    Copyright (c) 2018-2019, Arm Limited.

ArWen's sinf and cosf implement the sine/cosine bodies, both range
reductions, the polynomials and the tables of that work, in its x86 FMA
form.  The MIT branch is elected for these parts too; the full Arm
permission notice below and licenses/LICENSE-Arm-optimized-routines-MIT.txt
apply.  This adds one trig header to the seventeen log/exp/pow kernel files
above; the Python log/exp/pow routines remain separate.

The 2017 Arm files (86067a740541, 2017-08-11) read "Copyright (C) 2017,
ARM Limited" under Apache-2.0.  Arm relicensed the same work to MIT fifteen
months later, at 11253b0b9d6b on 2018-11-12, and each file has carried

    Copyright (c) 2017-2018, Arm Limited.
    SPDX-License-Identifier: MIT

ever since.  A copyright holder may licence its own work on any terms it
chooses; Arm's MIT offer is public, current and made by the retained
copyright holder, and it is the offer ArWen takes.  The project LICENSE at
that relicensing (identical at every tag through v21.02, md5
c7e74e8165fadb7dd9ee169534fe99ef) reads:

    MIT License

    Copyright (c) 1999-2019, Arm Limited.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.


2. FDLIBM -- expm1f, tanhf, atanf, log10f, log1pf, and binary64 log10, log1p, atan, atan2
-----------------------------------------------------------------------------------------

These reductions descend from FDLIBM, developed at SunPro, a Sun Microsystems,
Inc. business, and converted to single precision at Cygnus Support.  The
binary64 log10, log1p, atan and atan2 in
thompson_aerosol_libm.cuh descend from FDLIBM's double-precision e_log10.c,
s_log1p.c, s_atan.c and e_atan2.c, which carry the same notice.  The notice below is the whole of the licence: its single
condition is that the notice be preserved, and this is that preservation.

    /*
     * ====================================================
     * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
     *
     * Developed at SunPro, a Sun Microsystems, Inc. business.
     * Permission to use, copy, modify, and distribute this
     * software is freely granted, provided that this notice
     * is preserved.
     * ====================================================
     */

Where ArWen must match the gfortran reference bit for bit, its routines
differ from other FDLIBM descendants at one point: atanf's 2**25
large-argument threshold, which was measured by running the reference on
float32 inputs.  tanhf carries no redundant zero guard (it would be
unreachable behind the |x| < 2**-55 branch) and log10f's zero path returns
-inf directly; both forms were compared on all 4,294,967,296 float32 bit
patterns with zero differing.  noahmp_energy.cu and noahmp_leaves.cu carry
the argument at the point where it applies.


3. AER RRTMG -- the legacy RRTMG radiation kernels
--------------------------------------------------

rrtmg_lw.cu, rrtmg_sw.cu, rrtmg_lw_chain.cu, rrtmg_lw_taugb02_10_11_12.cu,
rrtmg_lw_taugb03_05.cu, rrtmg_lw_taugb06_09.cu, rrtmg_lw_taugb13_16.cu and
rrtmg_mcica_wrf.cu transcribe WRF v4.6.1's phys/module_ra_rrtmg_lw.F and
phys/module_ra_rrtmg_sw.F.  That code is the work of Atmospheric and
Environmental Research, Inc., not of UCAR, and WRF says so by preserving
AER's notice -- seven times in the longwave file, nine in the shortwave:

    Copyright 2002-2008, Atmospheric & Environmental Research, Inc. (AER).
    This software may be used, copied, or redistributed as long as it is
    not sold and this copyright notice is reproduced on each copy made.
    This model is provided as is without any express or implied warranties.
                          (http://www.rtweb.aer.com/)

All three copyright-year spans in which that notice appears are reproduced
in licenses/NOTICE-AER-RRTMG-as-distributed-with-WRF.txt.

ArWen takes this material under AER's own current grant instead: BSD
3-Clause, "Copyright (c) 2020, Atmospheric and Environmental Research",
published by AER at https://github.com/AER-RC/RRTMG_LW and .../RRTMG_SW.  A
copyright holder may licence its own work on any terms it chooses, and that
offer is public, current and unconditional.  The BSD-3-Clause text is in
licenses/LICENSE-AER-RRTMG-BSD-3-Clause.txt and beside the packaged
coefficients in gpuwm/data/wrf_radiation/.


4. RTE+RRTMGP -- the default radiation kernels
----------------------------------------------

rrtmgp_gas.cu, rrtmgp_cloud.cu, rrtmgp_mcica.cu, rrtmgp_rte.cu,
rrtmgp_validation.cu and rrtmgp_planck_common.cuh transcribe
earth-system-radiation/rte-rrtmgp at commit
fa107a16120051c4124305c6b3d4c87059119f58, which each file's own header
cites.  That project is BSD 3-Clause:

    Copyright (c) 2015-2025, Atmospheric and Environmental Research,
      Regents of the University of Colorado,
      Trustees of Columbia University in the City of New York.
    All rights reserved.

Clause 1 requires a source redistribution to retain that notice, the list of
conditions and the disclaimer.  The full text is in
licenses/LICENSE-RTE-RRTMGP-BSD-3-Clause.txt.  It is a DIFFERENT work from
the rrtmgp-data k-distribution files, which carry their own, earlier
copyright line and ship beside the data in the companion gpuwm-data
distribution.


5. Numerical Recipes Software -- the GAMMLN log-gamma coefficients
------------------------------------------------------------------

nssl2_fused_gs.cu's wrf_gamma_dp, and the THOMPSON_AA_CC* tables in
thompson_aerosol_common.cuh that were produced with it, carry the Lanczos
g=5, n=6 coefficient set and evaluation that WRF v4.6.1 takes from Numerical
Recipes.  WRF preserves the notice immediately above and below REAL FUNCTION
GAMMLN(XX) at phys/module_mp_thompson.F:5325-5347:

    (C) Copr. 1986-92 Numerical Recipes Software 2.02

It is preserved here for the same reason.  ArWen's position on this material
-- taken from WRF, reproduced in order to match WRF bit for bit, and the
standard published Lanczos coefficient set -- is set out in full, including
the argument against it, in licenses/NOTICE-Numerical-Recipes.txt.


6. CORE-MATH -- tanf, asinf, acosf, atanf, log10f
------------------------------------------------

The tanf, asinf, acosf and atanf functions in gpuwm's FP32 trig header
implement the CORE-MATH correctly-rounded binary32 algorithms at these
upstream paths and revisions:

    src/binary32/tan/tanf.c, 59d21d7
    src/binary32/asin/asinf.c, bc385c2
    src/binary32/acos/acosf.c, 56dd347
    src/binary32/atan/atanf.c, a8066a5

The common asinf/acosf coefficient tables are included in that scope.
These files carry MIT permission directly.  The atanf here is CORE-MATH;
the FDLIBM atanf in other files remains covered by the separate Sun notice.
The FP32 trig header uses no FDLIBM code.

The ubm_log10f and ubm_log10f_special functions in
gpuwm/core/kernels/urban_bem.cuh implement CORE-MATH's correctly-rounded
binary32 log10f (src/binary32/log10/log10f.c, bc385c2), Copyright (c)
2022-2023 Alexei Sibidanov, under the same MIT permission. That file
carries the copyright line and the permission notice beside the code.
ubm_atanf there calls the trig header's atanf above.

The noah_log10 and noah_log10_special functions in
gpuwm/core/kernels/noah_mosaic.cu implement the same CORE-MATH log10f
(bc385c2, Copyright (c) 2022-2023 Alexei Sibidanov, the same MIT
permission) for the Noah mosaic column, whose TDFCND takes LOG10 of the
soil saturation ratio; that file too carries the copyright line and the
permission notice beside the code.

The sfire_tanhf function in gpuwm/core/kernels/sfire_libm.cuh implements
CORE-MATH's correctly-rounded binary32 tanhf
(src/binary32/tanh/tanhf.c, b1ecd83),
Copyright (c) 2022-2024 Alexei Sibidanov, under the same MIT permission, for
the native SFIRE fire state; that file carries the copyright line and the
permission notice beside the code.

Both upstream copyright-year lines and the exact common permission text
are reproduced in licenses/LICENSE-CORE-MATH-MIT.txt, in the header and
beside the code in gpuwm/core/kernels/LICENSE-third-party.txt. MIT
requires the copyright and permission notice in copies or substantial
portions of this work:

    Copyright (c) 2022-2024 Alexei Sibidanov.
    Copyright (c) 2023-2024 Alexei Sibidanov.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.


7. The scope of the six grants above
-------------------------------------

Each is stated by routine or by file on purpose.  They cover what sections 1
to 6 name and nothing else.  Other code in this directory -- including
gfk_tgamma in the FP32 maths header, which is ArWen's own work -- takes
nothing from Arm, Sun, AER, the RTE+RRTMGP
copyright holders, Numerical Recipes or CORE-MATH, and is not offered to a reader on
the strength of these notices.  Its provenance is recorded where it lives:
in the repository NOTICE, in PROVENANCE.md, and in each file's own header.


ADDENDUM. The binary64 maths of the UW boundary layer
-----------------------------------------------------

gpuwm's binary64 maths header is prepended to uwpbl.cu (bl_pbl_physics = 9)
and carries its notice inline.  It implements, by routine:

a. Arm optimized-routines (MIT) -- binary64 exp, log and pow and their data
   tables (math/exp.c, exp_data.c, log.c, log_data.c, pow.c,
   pow_log_data.c).  Source notices: "Copyright (c) 2018-2026, Arm
   Limited.", SPDX-License-Identifier: MIT.  The permission text is
   section 1's.

b. CORE-MATH (MIT) -- binary64 cos and acos, correctly rounded.

The upstream files are kept verbatim, sha256-pinned, at
tools/uwpbl_wrf471_oracle/libm64/upstream/.  These two grants cover the
routines named here and nothing else, on the terms section 6 states for the
others.  CORE-MATH's copyright lines and permission notice, reproduced as
MIT requires (also at licenses/LICENSE-CORE-MATH-binary64-MIT.txt):

    Copyright (c) 2022-2025 Paul Zimmermann and Tom Hubrecht
    Copyright (c) 2024-2025 Alexei Sibidanov.

    These files are part of the CORE-MATH project
    (https://core-math.gitlabpages.inria.fr/).

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

The native proof profile in noahmp_log10_profile.cuh reuses the same CORE-MATH log10f from noah_mosaic.cu under the retained MIT notice.
