{"text":"\\section{Introduction}\n\nFix a continuous, absolutely irreducible, 2-dimensional, odd, mod $p$ representation\n$ {\\bar {\\rho} } :\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q}) \\rightarrow \\mathrm{GL}_2({\\mathbb F})$ with ${\\mathbb F}$ a finite field of\ncharacteristic $p$.\nWe denote by $N( {\\bar {\\rho} } )$ the (prime to $p$) Artin conductor of $ {\\bar {\\rho} } $, and \n$k( {\\bar {\\rho} } )$ the weight of $ {\\bar {\\rho} } $ as defined in \\cite{Serre3}. Serre has conjectured in \\cite{Serre3} that such a $ {\\bar {\\rho} } $ {\\it arises} (with respect to some fixed embedding $\\iota:\\overline{\\mathbb{Q}} \\hookrightarrow \\overline{\\mathbb{Q}_{p}}$) from a newform of weight $k( {\\bar {\\rho} } )$ and level $N( {\\bar {\\rho} } )$. \n\nIf $ {\\bar {\\rho} } $ is unramified outside $p$, we say that it is of level 1.\nThis corresponds to the case \nwhen $N( {\\bar {\\rho} } )$ is $1$. \n\n\n\\subsection{The main result}\n\n\\begin{theorem}\\label{main}\n A $ {\\bar {\\rho} } $ of level one arises from $S_{k( {\\bar {\\rho} } )}(SL_2(\\mathbb{Z}))$ with respect\n to an embedding $\\iota:\\overline{\\mathbb{Q}} \\hookrightarrow \\overline{\\mathbb{Q}_{p}}$.\n\\end{theorem}\n\nThe theorem settles the conjecture stated \nin article 104 of \\cite{Serre2} which is in the case of level 1.\nWe summarise the history of the conjecture. The level 1 \nconjecture was first \nmade by Serre in September 1972 (just after the Antwerp meeting) when he\nwrote to Swinnerton-Dyer about it, and asked him to mention this\nconjecture (or problem) in his Antwerp text (see \\cite{SWD}, p.9). This is\nprobably the first appearance (1973) of this conjecture in print.\nSerre wrote about these conjectures to Tate on May 1st, 1973.\nTate replied to Serre first on June 11, and then on July 2, 1973: in the second letter, he \nproved the conjecture for $p = 2$.\n\n\nThe proof of Theorem \\ref{main} builds on the ideas of an earlier work of\nWintenberger and the author, see \\cite{KW}. There the above\ntheorem was proved for primes $p=5,7$ (it being known \nearlier conditionally under GRH for $p=5$ by \\cite{Brue}), it being already known\nfor $p=2,3$ because of a method of Tate, see \\cite{Tate} for $p=2$, which was \nlater applied to the case of $p=3$ by Serre, see page 710 of\n\\cite{Serre2}. In \\cite{KW} it was shown how\nmodularity lifting theorems would yield Serre's conjecture when proved in\nsufficient generality, and the conjecture was proven in level 1 for\nweights $2,4,6,8,12,14$.\nThe main contribution of this paper is a method to \nprove the level 1 case of the\nconjecture using only known modularity lifting theorems, thus completing the proof of the level 1 case of Serre's conjecture. We need lifting theorems when either the $p$-adic lift is crystalline at $p$ of weight $k$ (i.e., Hodge-Tate weights $(k-1,0)$) $\\leq p+1$ (and when the weight is $p+1$ the lift is ordinary at $p$), or at $p$ the lift is of Hodge-Tate weights $(1,0)$ and \nBarsotti-Tate over $\\mathbb{Q}_p(\\mu_p)$. \n\n\nHenceforth $p$ will be an odd prime.\nWe use the inductive method proposed in Theorem 5.1 of \\cite{KW}\nto prove the level 1 case of the conjecture. \nThe main new idea of this paper is a ``weight reduction'' \ntechnique. This allows us to carry out \nthe inductive step in a manner that is different from the one contemplated in \n{\\it loc.\\ cit.\\ }\n\nThe cases of the conjecture for small weights in level 1 proved in \\cite{KW}\nwere dealt with using the\nresults of Fontaine, Brumer and Kramer, and Schoof (\\cite{Fontaine}, \\cite{BK} and \\cite{Schoof1}), together with modularity\nlifting results of the type pioneered by Wiles. \n\nIn this paper we use the results of \\cite{KW} for weights $2,4,6$, and after that prove the level\none case without making any further use of results classifying abelian varities\nover $\\mathbb{Q}$ with certain good reduction properties. Thus in the end we see that the\nonly such results we use are those showing that there is no semistable\nabelian variety\nover $\\mathbb{Q}$ with good reduction outside 5 (see \\cite{Fontaine}, \\cite{Schoof1} and \\cite{BK}). \nWe do make use of course of modularity lifting results. These are \ndue to Wiles, Taylor, Breuil, Conrad, Diamond, Fujiwara, Kisin, Savitt, Skinner et al\n(see \\cite{Wiles}, \\cite{TW}, \n\\cite{Fujiwara}, \\cite{CDT},\\cite{BCDT}, \\cite{SW2}, \\cite{SW3}, \\cite{Savitt}, \\cite{Kisin}). In particular, besides the basic method \nof Taylor and Wiles in \\cite{Wiles} and \\cite{TW}, we need crucially the results of Skinner and Wiles in \\cite{SW2},\n\\cite{SW3}, and the result of Kisin in \\cite{Kisin}. Although Kisin proves a very general modularity lifting theorem for potentially Barsotti-Tate lifts (at $p$) when the residual representation is non-degenerate, i.e., \nirreducible on restriction to $G_{\\mathbb{Q}(\\sqrt{{ (-1)}^{p-1 \\over 2}p})}$, in this paper the main theorem of \\cite{Kisin} is used only in the \ncase when the $p$-adic lift being considered is (locally at $p$) Barsotti-Tate over $\\mathbb{Q}_p(\\mu_p)$. The residually degenerate cases are handled by quoting the results of Skinner and Wiles in \\cite{SW2}, \\cite{SW3} which may be applied as in these cases the lifts that need to be proved modular are ordinary up to a twist. The ordinarity is a consequence of a result\nof Breuil and M\\'ezard (Proposition 6.1.1 of \\cite{BM}), and Savitt (see \\cite{Savitt1}, Theorems 6.11 and 6.12), which is vital for us. \n\nAs in \\cite{KW}, we use crucially the\npotential version of Serre's conjecture proved by Taylor in \\cite{Tay1} and \\cite{Tay2}, and a deformation theoretic result of B\\\"ockle in the appendix to \\cite{[K03]}.\n\nTheorem \\ref{main} yields the following corollaries (see Section \\ref{cors}),\nthe first needing also the method of ``killing ramification'' of Section 5.2 of \\cite{KW}:\n\n\\begin{cor}\\label{cond}\n If $ {\\bar {\\rho} } $ is an irreducible, odd, 2-dimensional, mod $p$ representation of $G_\\mathbb{Q}$ with $k( {\\bar {\\rho} } )=2$, \n $N( {\\bar {\\rho} } )=q$, with $q$ prime, and $p>2$, then\n it arises from $S_2(\\Gamma_1(q))$.\n\\end{cor}\n\n\\begin{cor}\\label{finite}\n There are only finitely many isomorphism classes of continuous semisimple\n odd representations $ {\\bar {\\rho} } :G_\\mathbb{Q} \\rightarrow GL_2(\\overline{\\mathbb{F}_{p}})$\n that are unramified outside $p$.\n\\end{cor}\n\n\n\nOur theorem, when combined with modularity lifting theorems also implies that if $\\rho:G_\\mathbb{Q} \\rightarrow GL_2({O})$ is an irreducible $p$-adic representation unramified outside $p$ and at $p$ crystalline of Hodge Tate weights $(k-1,0)$ with $k$ even and \neither $2 \\leq k \\leq p-1$ (even the weight $p+1$ case can be deduced, after the work in \\cite{BLZ}: \nsee Lemma \\ref{rubbish} below) or $\\rho$ is ordinary at $p$, then $\\rho$ arises from $S_k(SL_2(\\mathbb{Z}))$. It is quite likely that the restriction on weights in the non-ordinary cases\ncan be eased to allowing weights up to $2p$ provided that residually the representation is non-degenerate. This will probably follow\nfrom ongoing work of Berger on Breuil's conjecture in \\cite{Breuill}, and the modifications of the Taylor-Wiles system carried out in \\cite{Kisin}.\nTheorem \\ref{main} also implies that\na $\\mathrm{GL}_2$-type semistable abelian variety over $\\mathbb{Q}$ with good reduction outside a prime $p$ is a factor of $J_0(p)$. Such a result was earlier used in \\cite{KW} in the case when $p=5,7,11,13$ being a special case of the results proven in \\cite{Schoof1}, \\cite{BK}: now we can recover these results in the case of $\\mathrm{GL}_2$-type abelian varieties when $p>5$. \n\n\\subsection{Sketch of proof}\n\nWe give a \nrough sketch of the proof of Theorem \\ref{main}, starting with some general comment about the method used. As in Theorem 5.1 of \\cite{KW}, the method is inductive with respect to the prime which is the residue characteristic, but as said earlier the inductive step is carried out differently. The method uses in an essential way the method of \n``congruences between Galois representations'' which was introduced in Section 4 of \\cite{KW}\nto prove the cases of the conjecture in level 1 and weights $6,8,12,14$, and is refined here. In Section 4 of {\\em loc.\\ cit.\\ } congruences were produced\nbetween $p$-adic representations of $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ \nthat were crystalline of weight $p+1$ at $p$ and semistable of weight 2 at $p$\n(the analog for modular forms being a result of Serre: see Th\\'eor\\`eme 11 of \narticle 97 of \\cite{Serre2}).\nThe method in Section 2 of \\cite{KW} can be used to prove more results about such congruences which parallel \nresults that are well-known for congruences between modular forms. For instance\nwe can now in principle prove analogs for Galois representations of \nthe ``type changing'' arguments of Carayol in \\cite{car} for modular forms (some instances are carried out in \nSection 3 of the paper, and used in the proof of Theorem \\ref{main} to ``change types'' at a prime different from the residue characteristic), or the level raising results for\nmodular forms of Ribet (see \\cite{Ribet1}). We do not use the Galois-theoretic\nanalog of the latter in this paper, but this and other such ``level raising'' results for Galois representations will be crucial in future work. \n\nWe fix an embedding $\\iota_p:\\overline{\\mathbb{Q}} \\hookrightarrow \\overline{\\mathbb{Q}_{p}}$ for each prime $p$. \nWe say a residual mod $p$ representation $ {\\bar {\\rho} } $ or a $p$-adic \nrepresentation $\\rho$, is {\\it modular} if it is either reducible (in the $p$-adic case we assume irreducibility) or it arises from a newform with respect to the embedding $\\iota_p$.\nWe say that a compatible system $(\\rho_{\\lambda})$ is modular if it arises from a newform.\n\nAssuming we have proved Serre's conjecture for level 1 modulo the $n$th prime $p_n$, we prove it mod $P_{n+1}$ where $P_{n+1}$ is the least non-Fermat prime $>p_n$. This is (more or less!) the inductive method \nto attack the level 1 case of Serre's conjecture \nproposed in Theorem 5.1 of \\cite{KW}.\nVia the methods of \\cite{KW}, see also Lemma \\ref{rubbish} and Corollary \\ref{trivial} below, this also means that one knows (the level 1 case of) Serre's conjectures for $ {\\bar {\\rho} } $ of any residue characterictic $p$ bigger than $p_n$ for all weights up to $P_{n+1}+1$. Then we repeat the process starting with $P_{n+1}$ instead of $p_n$.\n\n\nIn \\cite{KW} to prove weights $6,8,12,14$ the minimal lifting result in Section 2 of \\cite{KW} was used twice to get 2 different compatible systems whose interplay (via the residual representations at a certain place of the 2 compatible systems being isomorphic up to semisimplification: we say that 2 such compatible systems are {\\em linked}) proved the modularity\nof $ {\\bar {\\rho} } $. Here 3 compatible systems are considered instead which arise from $ {\\bar {\\rho} } $ directly or indirectly.\nThe lifts constructed are not always minimal. The inductive step is different\nfrom the one proposed in \\cite{KW} \nin that the residual modularity is essentially used only for representations in smaller weights of the same residual characteristic which has already been \ninductively established earlier. Another prime $\\ell$ is used as a foil in an auxiliary fashion to achieve this reduction of weight.\n\nMore precisely, starting with a $ {\\bar {\\rho} } $ mod $p:=P_{n+1}$ such that\n$p_{n}+1 < k( {\\bar {\\rho} } )\\leq p+1$ of level 1, we first reduce to considering \n$ {\\bar {\\rho} } $ which are ordinary at $p$ (by Lemma \\ref{weights} below), and then construct \na minimal lifting (see Proposition \\ref{p} below) of $ {\\bar {\\rho} } $ to a $p$-adic representation that is unramified outside $p$ and of weight 2 at $p$ (it is \nBarsotti-Tate \nover $\\mathbb{Q}_p(\\mu_p)$ if $k( {\\bar {\\rho} } ) \\neq p+1$, and otherwise semistable of weight 2). We then get a compatible system $(\\rho_{\\lambda})$ (see Proposition \\ref{c}) such that $\\rho$ is\npart of this system for a $\\lambda$ above $p$. \nWe choose an odd prime $\\ell$ such that $\\ell^r||p-1$ (hence the assumption that $p$ is not a Fermat prime), \nand consider the residual representation $\\overline \\rho_{\\lambda}$ for $\\lambda$ now a prime above $\\ell$. \n\nNow in the cases when the residual modularity is not known for this mod $\\ell$ representation \n(the residual modularity will be known if the image is solvable, or the representation is unramified at $p$) we \nconstruct another lifting (see Proposition \\ref{q} which plays in some sense the analog of a lemma of Carayol \\cite{car}, or \nde Shalit's lemma as in \\cite{Wiles} and \\cite{TW}, for Galois representations) \n$\\rho'$ of this mod $\\ell$ representation that is Barsotti-Tate at $\\ell$, and at $p$ is non-minimal with \n``nebentype'' that is well-chosen, and is unramified outside $\\ell,p$. \n(If the mod $\\ell$ modularity were known, we conclude the modularity of $(\\rho_\\lambda)$ \nby a modularity lifting theorem applied at $\\ell$: the modularity lifting result in \nthis case would be the one contained in \\cite{Wiles}, \\cite{TW}, \\cite{SW2} and \\cite{SW3}.)\nWe construct another compatible \nsystem $(\\rho'_{\\lambda})$ of which $\\rho'$ is a member, and such that at \na prime above $p$, because of the well-chosenness of the nebentype at $p$ in the $\\ell$-adic lift, the residual representation \nis already known to be modular by the inductive hypothesis (which includes the case when the representation \nis reducible as these by convention are also called modular). This control of the weight of the mod $p$ \nresidual representation arising from $(\\rho'_{\\lambda})$ is due \nto a result of Breuil and M\\'ezard in \\cite{BM}, and Savitt \\cite{Savitt1}. Then the fact that we are \nin a position to apply known modularity lifting results (see \\cite{SW2}, \\cite{SW3}, \\cite{Kisin}) \nis again because of \\cite{BM} which says that all lifts of reducible 2-dimensional mod $p$ representation of $G_{\\mathbb{Q}_p}$\nthat become Barsotti-Tate over $\\mathbb{Q}_p(\\mu_p)$ are up to twist ordinary. (This is one important reason why the \nstrategy here does not need modularity lifting results beyond the known range.)\n\nThese known modularity lifting theorems then prove modularity of \n$(\\rho'_{\\lambda})$, and then another use of modularity lifting theorems (of \\cite{Wiles}, \\cite{TW}, \\cite{SW2}, \\cite{SW3}) \nprove the modularity of $(\\rho_{\\lambda})$, as the 2 compatible systems are linked mod the prime above $\\ell$ fixed by $\\iota_\\ell$, \nand thus $ {\\bar {\\rho} } $ is modular. We need a third kind of compatible system $(\\rho''_{\\lambda})$\nconstructed in \\cite{KW} to conclude now that all level 1 representations modulo a prime $\\geq k( {\\bar {\\rho} } )-1$ \nand of the weight of $ {\\bar {\\rho} } $ are modular (see Lemma \\ref{rubbish} and \nCorollary \\ref{trivial} below). \n \n\nThe entire strategy of the paper roughly uses that $p_n$ \nis at least two-thirds as large as $p_{n+1}$ (using classical Chebyshev estimates: \nsee Section \\ref{cheb}). \n\nThus schematically the argument may be summarised as follows:\n\\begin{itemize}\n\n\\item Start with a mod $p$ representation\n$ {\\bar {\\rho} } $,\n\n\\item lift it to $\\rho$ (using Proposition \\ref{p}), \n\n\\item construct a compatible system\n$(\\rho_{\\lambda})$ (using Proposition \\ref{c}) such that for the prime above $p$ fixed by $\\iota_p$ the corresponding representation\nis $\\rho$, \n\n\\item consider the residual representation at a prime $\\lambda$ above \na ``suitable'' prime $\\ell$ ($\\lambda$ fixed by $\\iota_\\ell$), \n\n\n\\item lift this to a ``good'' lift $\\rho'$ (using Proposition \\ref{q}), \n\n\\item make it part of a compatible system \n$(\\rho'_{\\lambda})$ (using Proposition \\ref{p}), \n\n\\item consider the residual representation at the above $p$ fixed by $\\iota_p$\narising from the system $(\\rho'_{\\lambda})$, \n\n\\item inductively this is known to be modular as $\\rho'$ is a ``good'' lift, \n\n\\item modularity lifting theorems imply $(\\rho'_{\\lambda})$ is modular, \n\n\\item another application of lifting theorems gives $(\\rho_{\\lambda})$ is modular, and hence $ {\\bar {\\rho} } $ is modular. \n\\end{itemize}\n\n\\noindent (This is in the ``generic'' case, as sometimes the procedure yields success earlier.) After this we use a third kind of compatible system \n$(\\rho''_{\\lambda})$ constructed in Sections 2 and 3 of \\cite{KW}, to deduce that once Serre's conjecture is known in weight $k$ for a prime $p$ then it is known in weight $k$ for all primes $\\geq k-1$ (see Corollary \\ref{trivial} below).\n\n\nJust as in \\cite{KW}, besides modularity lifting results, the potential version of Serre's conjectures \nproven by Taylor in \\cite{Tay1} and \\cite{Tay2}, and a result of B\\\"ockle\nin the appendix to \\cite{[K03]}, is crucial in constructing (minimal and non-minimal) liftings \n$\\rho$ of various kinds (see Sections 2 and 3), and then making them part of a compatible system \n$(\\rho_\\lambda)$ (see Section 4) whose refined properties are then obtained by arguments \nof Dieulefait and Wintenberger,\n\\cite{D} and \\cite{Wint}.\n\n\n\\section{Liftings}\n\nFor $F$ a field, $\\mathbb{Q} \\subset F \\subset \\overline{\\mathbb{Q}}$,\nwe write $G_{F}$ for the Galois group of $\\overline{\\mathbb{Q}} \/ F$.\nFor $\\lambda$ a prime\/place of $F$,\nwe mean by $D_{\\lambda}$ (resp., $I_{\\lambda}$) a decomposition\n(resp., inertia) subgroup of $G_F$ at $\\lambda$.\nWe have fixed embeddings $\\iota_p, \\iota_\\infty$ of $\\overline{\\mathbb{Q}}$ in its completions $\\overline{\\mathbb{Q}_{p}}$ and $\\mathbb{C}$ in the introduction.\nDenote by $\\chi_p$ the $p$-adic\ncyclotomic character, and $\\omega_p$ the Teichm\\\"uller lift of the mod $p$ cyclotomic character $\\overline \\chi_p$ \n(the later being the reduction mod $p$ of $\\chi_p$). By abuse of notation we also denote by $\\omega_p$ the $\\ell$-adic character $\\iota_\\ell\\iota_p^{-1}(\\omega_p)$ for any prime $\\ell$: this should not cause confusion as from the context it will be clear where the character is valued. For a number field $F$ we denote the restriction of a character of $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ to $G_F$ by the same symbol.\n\nLet $p$ an odd prime.\nFix $ {\\bar {\\rho} } : G_{\\mathbb{Q}}\\rightarrow \\mathrm{GL}_2 (\\overline{\\mathbb{F}_{p}} )$\nto be an odd irreducible representation.\nWe assume that the Serre\nweight $k( {\\bar {\\rho} } )$ is such that $2 \\leq k( {\\bar {\\rho} } ) \\leq p+1$. (Note that\nthere\nis always\na twist of $ {\\bar {\\rho} } $ by some power of the mod $p$ cyclotomic character\n$\\overline{\\chi _p}$\nthat has weights in this range.) We denote by ${\\rm Ad}^0( {\\bar {\\rho} } )$ the $G_{\\mathbb{Q}}$-module arising from the adjoint action on the trace 0 matrices of $M_2({\\mathbb F})$.\n\nLet ${\\mathbb F} \\subset \\overline{\\mathbb{F}_{p}}$ be a finite field\nsuch that the image of $\\overline{\\rho}$ is contained in\n$\\mathrm{GL}_2 ({\\mathbb F} )$, and let $W$ be the Witt vectors $W({\\mathbb F} )$.\nBy a {\\it lift} of $\\overline{\\rho}$, we mean a continuous representation\n$\\rho : G_{\\mathbb{Q}}\\rightarrow\n\\mathrm{GL}_2 ({V})$, where $ V$ is the ring of integers of a\nfinite\nextension of the field of fractions of $W$, such that\nthe reduction of $\\rho$ modulo the maximal ideal of ${V}$ is\nisomorphic to $\\overline{\\rho}$. Liftings when considered up to equivalence, i.e., up to conjugation by matrices that are residually the identity, are referred to as deformations.\nWe say that $\\rho$ is minimal at a prime $\\ell \\neq p$ if it is minimally\nramified at $\\ell$ in the terminology of \\cite{[D97]}.\n\n\nLet ${\\varepsilon}$ be the Teichm\\\"uller lift of the character \n${\\rm det}( {\\bar {\\rho} } )\\overline \\chi_p^{1-k( {\\bar {\\rho} } )}$ whose restriction to any open subgroup of $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ we denote by the same symbol. \n\n\n\\subsection{The method of producing liftings of \\cite{KW}}\\label{liftings}\n\nIn this section we will produce liftings with certain prescribed local properties\nof $ {\\bar {\\rho} } $ (one of the properties being unramified almost everywhere) using the methods of Section 2 of \\cite{KW}. We assume \nthat $ {\\bar {\\rho} } $ has non-solvable image and $k( {\\bar {\\rho} } ) \\neq p$.\nBy Lemma 2.6 of \\cite{KW}, this also means that for any totally real field $F$,\n $ {\\bar {\\rho} } |_{G_F}$ has non-solvable image, and as $2 \\leq k( {\\bar {\\rho} } ) \\leq p+1$ and $\\neq p$, if $F$ is unramified at $p$, \n$\\wp$ a place of $F$ above $p$, $ {\\bar {\\rho} } |_{I_{\\wp}}$ is non-scalar.\n\n\nTo orient the reader we say a few words about \nthe way the method of {\\it loc.\\ cit.\\ } gets used here. We wish to point out that the method there is flexible enough to produce liftings with the desired local properties, provided the local calculations work out.\n\nWe \nproduce liftings\nwith prescribed properties as in Propositions \\ref{p} and \\ref{q} below, \nby proving, as in \\cite{KW},\nthat a deformation ring $R$ (over a suitable ring of integers $O$ of a finite extension of $\\mathbb{Q}_p$, with uniformiser $\\pi$) which parametrises (equivalence classes of) liftings of $ {\\bar {\\rho} } $\nwith these prescribed properties is flat \nover $O$. (The prescribed properties will be deformation conditions in the sense of \\cite{Mazur} and thus the problem will be representable globally by a \nuniversal ring $R$.) To do this one shows first that $R\/(\\pi)$ is finite, which\nby Lemma 2.4 of {\\it loc.\\ cit.\\ }, as explained below,\nis equivalent to showing that $R_F\/(\\pi)$ is finite, where $R_F$ is\na certain deformation ring for $ {\\bar {\\rho} } |_{G_F}$ and $F$ is some totally real\nfield. \n\nThe finiteness of $R_F\/(\\pi)$ is established by identifying $R_F$ to\na Hecke algebra $\\mathbb{T}_F$ which we know is finite over $\\mathbb{Z}_p$. \nA suitable $F$ with this property is produced by using Taylor's results\nin \\cite{Tay1}, \\cite{Tay2}: for instance $F$ is unramified at $p$, and in the cases below $R_F$ can be taken to be a minimal deformation ring (although $R$ need not be a minimal deformation ring, see Proposition \\ref{q} for instance).\nHere the minimality of $R_F$ at the local defining conditions at \nplaces $\\lambda$ not above $p$ does not need futher comment: for $\\lambda$ above $p$ the minimality condition is as explained below the same as the minimal condition at $p$ when defining $R$, and is different in the case\nof Propositions \\ref{p} and \\ref{q}.\n\nTo see that $R_F$ can be taken to be the the minimal deformation ring in the \nproofs of Propositions \\ref{p} and \\ref{q} below we indicate the argument. Denote the universal representation $\\rho_R$ and $\\rho_{R_F}$ corresponding\nto the deformation problem that $R$ and $R_F$ represent (with $R_F$ the minimal deformation ring), and $\\overline \\rho_R$ and $\\overline \\rho_{R_F}$ it's reduction mod $\\pi$. Then using the properties of the lifts prescribed in \nPropositions \\ref{p} and \\ref{q} below, for $\\ell \\neq p$, the order of ${\\overline \\rho_R} (I_\\ell)$ is the same as the order of $ {\\bar {\\rho} } (I_\\ell)$. This is seen by using the proof of the claim after Lemma 2.4 of \\cite{KW}. \n\nThis gives that\n${\\overline \\rho_R}|_{G_F}$ is a specialisation of $\\overline \\rho_{R_F}$. \nThe finiteness of $R_F$ as a $O$-module yields that the latter has finite image and hence so does the former, which by Lemma 2.4 of \\cite{KW} gives that\n$R\/(\\pi)$ is of finite cardinality. \n\nWe give some more details about the choice of $F$ and the identification of $R_F$ to\na Hecke algebra $\\mathbb{T}_F$ (see also proof of Theorem 2.2 of \\cite{KW}).\nWe choose the totally real field $F$, Galois over $\\mathbb{Q}$ and of even degree, so that when $ {\\bar {\\rho} } $ is ordinary at $p$ (resp., supersingular by which we mean locally irreducible at $p$), $F$ is unramified at $p$ \n(resp., split at $p$),\n$ {\\bar {\\rho} } |_{G_F}$ is unramified outside places above $p$, {\\it and} such that there is a cuspidal automorphic representation $\\pi$ for $GL_2(\\mathbb{A}_F)$\nthat is discrete series of parallel weight $(2,\\cdots,2)$ at infinity (resp.,\nof parallel weight $(k( {\\bar {\\rho} } ),\\cdots,k( {\\bar {\\rho} } ))$ at infinity) is unramified at all places not above $p$, and is ordinary at places $\\wp$ above $p$ \nof conductor dividing $\\wp$ (resp., unramified at places $\\wp$ above $p$), and unramified at $p$ when $k( {\\bar {\\rho} } )=2$,\nthat gives rise to $ {\\bar {\\rho} } |_{G_F}$ with respect to (w.r.t.) the \nembedding $\\iota_p$. In the ordinary case (in Proposition \\ref{q})\nwe also use the existence of $F$ unramified at $p$, \nGalois over $\\mathbb{Q}$ and of even degree, such that $ {\\bar {\\rho} } |_{G_F}$ is unramified outside places above $p$, {\\it and} such that there is a cuspidal automorphic representation $\\pi$ for $GL_2(\\mathbb{A}_F)$\nthat is discrete series of parallel weight $(k( {\\bar {\\rho} } ),\\cdots,k( {\\bar {\\rho} } ))$ at infinity and is unramified at all finite places (see \\cite{Tay1} and Proposition 2.5 of \\cite{KW}), that gives rise to $ {\\bar {\\rho} } |_{G_F}$ with respect to (w.r.t.) the \nembedding $\\iota_p$.\n\nThe existence of a $F$ with all these properties \nfollows from Lemma 1.5 and Corollary 1.7 of \\cite{Tay1}, and Proposition 2.5 of \\cite{KW}, in the ordinary case, and Theorem 5.7 of \\cite{Tay2} in the supersingular case, and uses as an ingredient the level-lowering up to base change method of \\cite{SW1}. (The evenness of $[F:\\mathbb{Q}]$ is not mentioned in \\cite{Tay1} in the ordinary case,\nbut certainly may be ensured by a further quadratic base change.) \n\nIn the case of Proposition \\ref{p}, in which case $F$ \nis unramified at $p$, the minimal deformation ring $R_F$ \nparametrises lifts $\\rho$ of $ {\\bar {\\rho} } |_{G_F}$ that are unramified away from $p$, and\nat places $\\wp$ above $p$ are such that $\\rho|_{I_{\\wp}}$ is of the form \n$$\\left( \\begin{array}{cc}\n \\omega_p^{k-2}\\chi_p & * \\\\\n 0 & 1\n\\end{array} \\right),$$ if $ {\\bar {\\rho} } |_{I_{\\wp}}$\nis of the form $$\\left( \\begin{array}{cc}\n \\overline \\chi_p ^{k-1} & * \\\\\n 0 & 1\n\\end{array} \\right),$$ with $2 \\leq k \\leq p-1$, with the further condition that if $k( {\\bar {\\rho} } )=2$, $\\rho|_{I_{\\wp}}$ is Barsotti-Tate, and of determinant (the restiction of) ${\\varepsilon} \\omega_p^{k-2}\\chi_p$. In the case of Proposition \\ref{q}, in which case $F$ may be taken to be split at $p$ when $ {\\bar {\\rho} } |_{D_p}$ is supersingular, the minimal deformation ring $R_F$ \nparametrises lifts $\\rho$ of $ {\\bar {\\rho} } |_{G_F}$ that are unramified away from $p$, and at places $\\wp$ above $p$ the representation is crystalline of weight $k( {\\bar {\\rho} } )$, and the lifts have determinant ${\\varepsilon} \\eta_q^i \\chi_p^{k( {\\bar {\\rho} } )-1}$\nusing the notation of Proposition \\ref{q}. (We can also ensure that ${\\varepsilon}|_{G_F} $ or ${\\varepsilon} \\eta_q^i|_{G_F}$ is trivial if we want when the Serre weight is even:\nthe Serre weight will always be even in all applications below.)\n\nIt remains to recall the identification of $R_F$ to suitable Hecke algebra $\\mathbb{T}_F$.\nIn the case of Proposition \\ref{p} below, the Hecke algebra $\\mathbb{T}_F$ is a ($\\mathbb{Z}_p$-)algebra cut out by the \nHecke action on cusp forms for $GL_2(\\mathbb{A}_F)$ that are of weight $(2,\\cdots,2)$, \nunramified outside $p$, and at places $\\wp$ above $p$ of conductor dividing $\\wp$ (and unramified if $k( {\\bar {\\rho} } )=2$), and\nof central character corresponding to (restriction of) ${\\varepsilon} \\omega_p^{k-2}$ by class field theory, with respect to the embedding $\\iota_p$.\nIn the case of Proposition \\ref{q} below, the Hecke algebra $\\mathbb{T}_F$ is a ($\\mathbb{Z}_p$-)algebra \ncut out by the \nHecke action on cusp forms for $GL_2(\\mathbb{A}_F)$ that are of weight $(k( {\\bar {\\rho} } ),\n\\cdots,k( {\\bar {\\rho} } ))$, unramified at all finite places, and of central character \ncorresponding to, using it's notation, $\\eta_q^i {\\varepsilon} \\chi_p^{k( {\\bar {\\rho} } )-2}$ by class field theory. \n(The fact that the $\\mathbb{T}_F$ is non-zero is a consequence of the results of \nTaylor in \\cite{Tay1} and \\cite{Tay2} that we have recalled.) \n\nThe identification $R_F\\simeq \\mathbb{T}_F$\nis proved using \\cite{Fujiwara} in the ordinary case, and \nSection 3 of \\cite{Tay2} in the supersingular case. ({\\small \nAs \\cite{Fujiwara} may not be widely available, note that in the ordinary case,\nwe are in a situation where we do have a minimal modular lift of $ {\\bar {\\rho} } |_{G_F}$ that is ordinary at places above $p$, and such that $ {\\bar {\\rho} } |_{G_F}$ has nonsolvable image, and $F$ is unramified at $p$. Thus the deduction of the isomorphism \n$R_F \\simeq \\mathbb{T}_F$ is by now standard.})\n\nNote that we are allowing $p=3$, which is a case excluded in\nsome sections of \\cite{Tay2}: thus we say a few words to justify why we still have the results of \\cite{Tay2} available. We exploit the fact that we know \nthat by our assumption \n$ {\\bar {\\rho} } |_{G_F}$ is not solvable for any totally real field $F$ (Lemma 2.6 of \\cite{KW}), and as\n$\\overline \\chi_3$ restricted to $F$ has order 2, \n we thus have an auxiliary prime $r$, as guaranteed\nby Lemma 3 of \\cite{DT} or Lemma 4.11 of \\cite{[DDT]}, which handles non-neatness problems. (For instance, this allows us to pass from the results in Section 4 of \\cite{Tay2}\nto those of Section 5 requiring only that $p>2$, and also to have available the results of Sections 2 and 3 of \\cite{Tay2} requiring only that $p>2$.)\n\n\nThe finiteness of $R\/(\\pi)$ leads to $R$ being flat (finite, complete intersection) over $ O$ if we know that $R \\simeq {O}[[X_1,\\cdots,X_r]]\/(f_1,\\cdots,f_s)$ with $s \\leq r$. By the crucial Proposition 1 of B\\\"ockle's appendix to \\cite{[K03]}, this will follow from some purely local information about the kind of lifts $R$ parametrises. (The local conditions will always be deformation conditions in the sense of \\cite{Mazur}.) If $R$ parametrises (equivalence classes of) lifts unramified outside a fixed set of primes, of a certain fixed determinant, only the following local properties at each prime $\\ell$ need be checked: the corresponding local deformation ring $R_{\\ell}$ should be a flat, complete intersection over $O$, of relative dimension \n${\\rm dim}{_{\\mathbb F}} H^0(D_{\\ell},{\\rm Ad}^0( {\\bar {\\rho} } ))$ \nwhen $\\ell \\neq p$, and of relative dimension \n${\\rm dim}{_{\\mathbb F}} H^0(D_{p},{\\rm Ad}^0( {\\bar {\\rho} } ))+1$ \nwhen $\\ell = p$. We check these local conditions in Propositions \\ref{p} and \\ref{q} showing that they follow from results of B\\\"ockle, Ramakrishna and Taylor, see \\cite{Boe}, \\cite{Boe1}, \\cite{Tay3}, \\cite{[R02]} (in all the cases below the local deformation ring turns out to be smooth). At primes $\\ell \\neq p$ \nwhere no ramification is allowed the deformation ring is directly checked to be smooth of relative dimension ${\\rm dim}{_{\\mathbb F}} H^0(D_{\\ell},{\\rm Ad}^0( {\\bar {\\rho} } ))$. At primes $\\ell \\neq p$ at which the residual representation is ramified and \nwhere the corresponding local deformations that are \nallowed are minimal the ring is smooth of the required dimension as checked in Section 3 of \\cite{Boe}, \\cite{[R02]} (see the \n`` local at $\\ell \\neq p$'' section) and \\cite{Tay3} (see E1 to E3). \nThus below we only check the local condition at the residual characteristic \n(where the results are again found in \\cite{Boe}, \\cite{[R02]} \nand \\cite{Tay3}), \nand at a prime $\\ell$ where the deformations allowed are not minimal.\n(Note that in \\cite{Tay3} for the local versal \ndeformation rings below, \nat $p$, or when $\\ell \\neq p$ and the deformations allowed are minimal, \nthe unobstructedness of the ring\nis checked, and it is shown that the tangent space is of dimension ${\\rm dim}{_{\\mathbb F}} H^0(D_{\\ell},{\\rm Ad}^0( {\\bar {\\rho} } ))+\\delta_{\\ell p}$, which implies that the versal ring is smooth of relative dimension ${\\rm dim}{_{\\mathbb F}} H^0(D_{\\ell},{\\rm Ad}^0( {\\bar {\\rho} } ))+\\delta_{\\ell p}$ over $W$.)\n\n\\subsection{Minimal $p$-adic weight 2 \nlifts of $ {\\bar {\\rho} } $}\\label{weight2}\n\nWe consider (just for this subsection) only\n$ {\\bar {\\rho} } $ such that\n$ {\\bar {\\rho} } $ is ordinary at $p$, i.e., $ {\\bar {\\rho} } |_{I_p}$ has non-trivial\ncovariants, and we also assume as before $k( {\\bar {\\rho} } ) \\neq p$.\nIn this subsection we consider lifts \n$\\rho$ of $ {\\bar {\\rho} } $ whose determinant is ${\\varepsilon}\\omega_p^{k( {\\bar {\\rho} } )-2}\\chi_p$.\n\n\nWe say that $\\rho$ is minimal of weight 2 at $p$ (as in E3 and E4 of\n\\cite{Tay3}) if \nits determinant is ${\\varepsilon}\\omega_p^{k( {\\bar {\\rho} } )-2}\\chi_p|_{D_p}$, and assuming $ {\\bar {\\rho} } |_{I_p}$\nis of the form\n$$\\left( \\begin{array}{cc}\n \\overline \\chi_p ^{k-1} & * \\\\\n 0 & 1\n\\end{array} \\right),$$ with $2 \\leq k \\leq p-1$, then $\\rho|_{I_p}$ is of\nthe form\n$$\\left( \\begin{array}{cc}\n \\omega_p^{k-2}\\chi_p & * \\\\\n 0 & 1\n\\end{array} \\right),$$ with the further condition that when $k( {\\bar {\\rho} } )=2$, $\\rho|_{I_p}$ is Barsotti-Tate. \n\nIf a lift $\\rho$ satisfies this condition at $p$ and is minimal at all prime $\\neq p$ (and thus necessarily\nhas determinant fixed as above), then we say that it is minimal\nof weight 2.\n\n\\begin{prop}\\label{p}\nLet $p$ be a prime $> 3$.\nLet $\\overline{\\rho} : G_{\\mathbb{Q}}\\rightarrow\n\\mathrm{GL}_2 ({\\mathbb F})$ be an odd absolutely irreducible representation.\nWe suppose that $2 \\leq k( {\\bar {\\rho} } ) \\leq p+1$ and\n $k( {\\bar {\\rho} } )\\not= p$ and with $ {\\bar {\\rho} } $ ordinary at $p$. Then\n$ {\\bar {\\rho} } $ has a lift $\\rho$ that is minimal of weight 2. (Its determinant\nis necessarily ${\\varepsilon}\\omega_p^{k( {\\bar {\\rho} } )-2}\\chi_p$.)\n\\end{prop}\n\n\\begin{proof} If the image of $ {\\bar {\\rho} } $ is solvable we are done using \nthat Serre's conjecture is known in this case even in its refined form (see \\cite{Ribet}) and the fact that if $ {\\bar {\\rho} } $ arises from a mod $p$ ordinary \neigenform in $S_{k( {\\bar {\\rho} } )}(\\Gamma_1(N),\\overline{\\mathbb{F}_{p}})$ ($(N,p)=1$), then it also arises from an ordinary eigenform in\n$S_2(\\Gamma_1(N) \\cap \\Gamma_0(p),\\overline{\\mathbb{F}_{p}}({\\overline \\chi_p}^{k( {\\bar {\\rho} } )-2}))$ (see Proposition 8.13 of \\cite{Gross} or\nSection 6 of \\cite{Edix}). So we\nnow assume that the image of $ {\\bar {\\rho} } $ is not solvable.\n \nThe proof follows immediately from the method of proof of Theorem 2.1 of\n\\cite{KW}, as noted in Section \\ref{liftings}, on noting the\nfollowing local fact: consider the versal deformation ring $R_p$\n that parametrises deformations of $ {\\bar {\\rho} } |_{D_p}$\n(to $W$-algebras that are complete Noetherian local (CNL)\nrings with residue field ${\\mathbb F}$ as usual)\nthat on inertia $I_p$ have the form $$\\left( \\begin{array}{cc}\n \\omega_p^{k-2}\\chi_p & * \\\\\n 0 & 1\n\\end{array} \\right),$$ have fixed determinant the image of the character \n${\\varepsilon}\\omega_p^{k-2}\\chi_p|_{D_p}$, and in the case of weight $k( {\\bar {\\rho} } )=2$ the deformation is Barsotti-Tate. Then $R_p$ is a complete intersection, flat over $W({\\mathbb F})$\nof relative dimension $1+{\\rm dim}_{{\\mathbb F}}(H^0(D_p,{\\rm Ad}^0( {\\bar {\\rho} } ))$: \nin fact it is even smooth \nof relative dimension $1+{\\rm dim}_{{\\mathbb F}}(H^0(D_p,{\\rm Ad}^0( {\\bar {\\rho} } ))$ as checked\n in E3 and E4 of \\cite{Tay3} (see also \\cite{[R02]}). This, by Section \\ref{liftings}, gives the flatness of the ring $R$ over $W$ that parametrises (equivalence classes of) \nlifts of $ {\\bar {\\rho} } |_{D_p}$ that are minimal of weight 2 and hence we are done.\n\\end{proof}\n\n\\noindent{\\bf Remark:} In this paper we use this theorem only for representations unramified outside $p$. We also do not need to use the proposition when the image is solvable. The condition of ordinarity may be removed using\nresults in \\cite{BM}, \\cite{Savitt1} (Proposition 6.1.2(iii) of the former, \nTheorem 6.22 of latter), together with the modification of Taylor-Wiles systems\nin \\cite{Kisin}.\n\n\\subsection{A Galois theoretic analog of Carayol's lemma}\\label{type}\n\nIn this subsection we prove a Galois theoretic analog of Lemme 1 of \\cite{car}.\nConsider $ {\\bar {\\rho} } : \\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q}) \\rightarrow GL_2({\\mathbb F})$ that is continuous, odd, irreducible, $2 \\leq k( {\\bar {\\rho} } ) \\leq p+1$ and $k( {\\bar {\\rho} } ) \\neq p$, \nand consider an odd prime $q$ which we assume is ramified in\n$ {\\bar {\\rho} } $.\nFurther assume that $ {\\bar {\\rho} } |_{I_q}$ is of the form\n$$\\left( \\begin{array}{cc}\n \\overline \\chi & * \\\\\n 0 & 1\n\\end{array} \\right),$$ where $\\overline \\chi$ arises from a mod $p$ character of ${\\rm Gal}(\\mathbb{Q}_q(\\mu_q)\/\\mathbb{Q}_q)$.\nLet $\\chi$ be its Teichm\\\"uller lift. This will be a power of the character $\\iota_p\\iota_q^{-1}(\\omega_q)$\nwhich we recall that by our conventions is again denoted by $\\omega_q$.\n\n\nAssume that $p^r||q-1$ ($r>0$) and consider $\\eta_q=\\omega_q^{ {q-1} \\over p^r }$: this is (for this subsection)\n a character with values in $\\overline{\\mathbb{Q}_{p}}^*$.\nWe denote the corresponding global characters which factor through\n${\\rm Gal}(\\mathbb{Q}(\\zeta_q)\/\\mathbb{Q})$ by the same symbol. We enlarge ${\\mathbb F}$ so that it contains all the ${q-1} \\over p^r$th roots of 1.\nBelow, we denote by $O$ the ring of integers of $W({\\mathbb F})(\\mu_{q-1})$ and by $\\pi$ a uniformiser of $O$.\n\nIn this section the minimality condition at $p$ we will consider\nis of being crystalline of weight $k( {\\bar {\\rho} } )$.\n\n\\begin{prop}\\label{q}\n Let $p$ be an odd prime, fix a $ {\\bar {\\rho} } $ as above (in particular $k( {\\bar {\\rho} } )\\neq p$ and $ {\\bar {\\rho} } |_{I_q}$ has the form above), and assume that $ {\\bar {\\rho} } $ does not have solvable\nimage. Fix an integer $i$. For some $V$ that is the ring of \nintegers of a finite extension of $\\mathbb{Q}_p$, there is a $V$-valued lift $\\rho$ of $ {\\bar {\\rho} } $ of determinant\n${\\varepsilon}\\chi_p^{k( {\\bar {\\rho} } )-1}\\eta_q^i$, that is minimal at primes outside $p,q$, is minimal\nat $p$ (crystalline of weight $k( {\\bar {\\rho} } )$), and at $q$, $\\rho|_{I_q}$ is of the from\n$$\\left( \\begin{array}{cc}\n \\chi \\eta_q^i & * \\\\\n 0 & 1\n\\end{array} \\right).$$ We say that such a lifting has nebentype $\\chi \\eta_q^i$ at $q$.\n\\end{prop}\n\n\\begin{proof}\n This follows by the arguments in Section 2 of \\cite{KW}, as noted in \nSection \\ref{liftings}, \nfrom the following 2 local\nfacts: \n\n- The local deformation ring $R_p$ which parametrises (equivalence classes of)\nlifts of $ {\\bar {\\rho} } |_{G_p}$\nto $O$-algebras that are crystalline of weight $k( {\\bar {\\rho} } )$, and of fixed determinant, is smooth over $ O$ of dimension ${\\rm dim}{_{\\mathbb F}} H^0(D_p,{\\rm Ad}^0( {\\bar {\\rho} } ))+1$.\nThis is proved in \\cite{[R00]}, \\cite{Tay3} (see also discussion in Section 2\nof \\cite{KW} and Proposition 2.3 of \n\\cite{KW} for the case of $k( {\\bar {\\rho} } )=p+1$).\n\n- Consider the versal ring $R_q$ that parametrises (equivalence classes of) lifts of\n$ {\\bar {\\rho} } |_{D_q}$ to CNL $O$-algebras with residue field ${\\mathbb F}$ \nof determinant (the restriction to $D_q$ of) ${\\varepsilon}\\chi_p^{k( {\\bar {\\rho} } )-1}\\eta_q^i|_{D_q}$, and such\nthat\n$\\rho|_{I_q}$ is of the from\n$$\\left( \\begin{array}{cc}\n \\chi\\eta_q^i & * \\\\\n 0 & 1\n\\end{array} \\right).$$ That such a ring exists (i.e., the conditions we are defining, which can be interpreted as a condition of ordinarity as we are fixing determinants, are deformation conditions) follows easily from our assumption that $q$ is ramified in $ {\\bar {\\rho} } $ (see for instance Section 6.2 of \\cite{dsl}). The key fact we need is that $R_q$ is a complete intersection, which is flat over $ O$, and of relative\ndimension ${\\rm dim}_{{\\mathbb F}}H^0(D_q,{\\rm Ad}^0( {\\bar {\\rho} } ))=1$. (In fact, it is even smooth.) The asserted dimension of the cohomology group is easily checked using\nthat $ {\\bar {\\rho} } $ is ramified at $q$.\n\nWe now prove that $R_q$ is smooth over $O$ of relative dimension 1.\nThis essentially follows from Section 2 of \\cite{Boe} \n(see Section 2, and in particular Theorem 3.8 and Lemma 3.10: the deformation problem we are describing here \nis one obtained by specializing the $T$ in \nTheorem 3.10 (iii) of {\\it loc.\\ cit.\\ } to a specific value and twisting).\nWe sketch an argument to be more self-contained. \n\nThe dimension over ${\\mathbb F}$ of the mod $\\pi$ Zariski tangent space of $R_q$ is 1. This follows from the calculations in Section 1 of \\cite{Wiles}, \nsee also Section 4.3 of \\cite{deshalit} for an exposition in semistable cases, as the dual number lifts that arise from $R_q$ are the same as the minimal lifts in\n\\cite{Wiles}. Thus to show that $R_q$ is in fact smooth of relative \ndimension 1 over O it will be enough to show that there are infinitely many \nnon-equivalent $O$-valued lifts $\\rho_q$ of $ {\\bar {\\rho} } |_{D_q}$ \nof the required kind which we now proceed to show. \nAny lift will be tamely ramified and thus will be specified by lifting the image of $ {\\bar {\\rho} } (\\sigma_q)$ \nand $ {\\bar {\\rho} } (\\tau_q)$, where $\\sigma_q,\\tau_q$\nare generators of Galois group of the maximal tamely ramified extension of $\\mathbb{Q}_q$, and the \nonly relation these satisfy is $\\sigma_q\\tau_q\\sigma_q^{-1}=\\tau_q^q$. When $\\overline \\chi$ is non-trivial, \nand thus $ {\\bar {\\rho} } |_{I_q}$ may be assumed split and \n$ {\\bar {\\rho} } |_{D_q}$ is diagonal, \nby inspection we get infinitely many lifts to diagonal matrices. \n\nIn the case when $\\overline{\\chi}$ and $\\chi$ are trivial, and hence $ {\\bar {\\rho} } |_{I_q}$ is unipotent, and not-trivial by \nassumption, again a simple calculation yields infinitely many $O$-valued lifts.\nThere will be 2 cases corresponding to $\\chi':=\\eta_q^i$ being trivial or non-trivial.\nWhen it is trivial this is covered by E3 of \\cite{Tay3} (this is the only case when the lifts considered locally at $q$ do not have abelian image). Otherwise we choose a $\\sigma=\\sigma_q$ and a $\\tau=\\tau_q$ such that\n$ {\\bar {\\rho} } (\\sigma)$ is $$\\left( \\begin{array}{cc}\n r & b \\\\\n 0 & r\n\\end{array} \\right)$$ (note that by the relation $\\sigma\\tau\\sigma^{-1}=\\tau^q$, the characteristic polynomial \nof $ {\\bar {\\rho} } (\\sigma)$ is forced to have double roots as $q$ is 1 mod $p$ and \n$ {\\bar {\\rho} } $ is tamely ramified at $q$), and $ {\\bar {\\rho} } (\\tau)$ is the matrix $$\\left( \\begin{array}{cc}\n 1 & a \\\\\n 0 & 1\n\\end{array} \\right).$$ We want to construct infinitely many $O$-valued lifts $\\rho_q$ of determinant \n${\\varepsilon}\\chi_p^{k( {\\bar {\\rho} } )-1}\\eta_q^i|_{D_q}$, and such that\n$\\rho_q|_{I_q}$ is of the from\n$$\\left( \\begin{array}{cc}\n \\chi' & * \\\\\n 0 & 1\n\\end{array} \\right).$$ We seek $$\\rho_q(\\sigma)=\\left( \\begin{array}{cc}\n \\alpha & \\gamma \\\\\n 0 & \\beta\n\\end{array} \\right),$$ say $A$, and $$\\rho_q(\\tau)=\\left( \\begin{array}{cc}\n \\chi'(\\tau) & a' \\\\\n 0 & 1\n\\end{array} \\right),$$ say $B$. \nHere $\\alpha\\beta={\\varepsilon}(\\sigma)\\chi_p^{k( {\\bar {\\rho} } )-1}(\\sigma)\\eta_q^i(\\sigma)$, $\\alpha,\\beta$ reduce to $r$, $a'$ reduces to $a$ (and hence is a unit), $\\gamma$ \nto $b$. \n\nWe explicitly produce these lifts by the following calculation. (The version \nof the calculation we present here is suggested by B\\\"ockle.)\nWe can assume by conjugation that $a$ and $a'$ are equal to one. \nAs the order of $B$ divide $q-1$ (as $\\chi'$ is not trivial of order dividing $q-1$), the relation \n$\\rho_q(\\sigma)\\rho_q(\\tau)\\rho_q(\\sigma)^{-1}=\\rho_q(\\tau)^q$\nis therefore equivalent to $AB=BA$, which yields\n $\\alpha-\\beta=\\gamma(\\chi'(\\tau)-1)$\n as the only relation. Combining this with the equation \n$\\alpha\\beta=\\psi:=\\epsilon(\\sigma)\n\\chi_p^{k( {\\bar {\\rho} } )-1}(\\sigma)\\eta_q^i(\\sigma)$\n gives the quadratic equation\n $\\beta^2-\\beta\\gamma(\\chi'(\\tau)-1)-\\psi=0$ for $\\beta$.\n Since $\\chi'(\\tau)-1$ lies in the maximal ideal, it follows easily that \n for each $\\gamma$ (reducing to $b$)\n there is a unique solution $\\beta$ that is congruent to $r$ \n modulo the maximal ideal of $ O$, and hence there is a unique $\\alpha$ depending on $\\gamma$.\n Thus one has a 1-parameter family (in $\\gamma$) of lifts \n$\\rho_q$ of the required type, thus proving that $R_q$ is smooth over $O$ of relative dimension 1.\n\n\\vspace{3mm}\n\nAfter these 2 facts, from Section \\ref{liftings}, we deduce that\nthe global deformation ring $R$ which parametrises (equivalence classes of) lifts of $ {\\bar {\\rho} } $\n\n- of the given determinant ${\\varepsilon}\\chi_p^{k( {\\bar {\\rho} } )-1}\\eta_q^i$, \n\n- that at $q$ are of the given form,\n\n- are minimal at primes $\\neq q,p$ in the sense of the section above, \n\n- at $p$ the lift is crystalline of weight $k( {\\bar {\\rho} } )$ \n(and thus finite flat when the residual representation has weight 2),\n\n\\noindent is a finite flat complete intersection (ffci) over $O$, and hence we get a lift of the desired kind. \n\n\n\\end{proof}\n\n\n\\noindent{\\bf Remark:} We will apply this proposition only when $ {\\bar {\\rho} } $ has weight 2, and \nis unramified outside $p,q$, and the lifts that need to be constructed\nhave non-trivial nebentype at $q$. In the proposition, \nwhen $ {\\bar {\\rho} } $ is ordinary we could also have allowed the \ndeformations at $p$ to be minimal of weight 2, and hence \nBarsotti-Tate over $\\mathbb{Q}_p(\\mu_p)$ when the weight is not $p+1$, and semistable of weight 2 otherwise.\n\nAs we have seen, the proofs of Proposition \\ref{p} and \\ref{q} follow easily from the method of proof of Theorem 2.2 of \\cite{KW} after \nsome computations of local deformation rings. \nThe point is that because of the method of Section 2 of \\cite{KW}, we can prove results about congruences of Galois representations to parallel many of the results known for congruences between modular forms. The method should allow one to prove in many more cases the analog of the results in \\cite{DT} and\n\\cite{inv}, these are level raising results for modular forms, for Galois representations: this is reduced \nto some local computation. The local computations in the ``$(p,p)$ case'' (needed for the analog of \\cite{inv}) are likely to be involved, while those in the $\\ell \\neq p$ case may be easier in many cases, and could be deduced for instance from \\cite{Boe} when locally the residual representation at the place $\\ell$ is not scalar. \n\n\\section{Compatible systems}\\label{comp}\n\nWe explain how to make the lifts $\\rho$ of Proposition \\ref{p} and \\ref{q}\npart of a compatible system. As in Section 3 of\n\\cite{KW}, the proof uses the method of \\cite{Tay2} (see proof of Theorem 6.6 of \\cite{Tay2}), and the refinements in \\cite{D} and \\cite{Wint}.\n\n\\begin{prop}\\label{c}\n \n(i) Assume $ {\\bar {\\rho} } $ is as in Proposition \\ref{p}: so it is ordinary of weight $2 \\leq k( {\\bar {\\rho} } ) \\leq p+1$ and $k( {\\bar {\\rho} } ) \\neq p$, and $p>3$.\nGiven a minimal lift $\\rho$ of $ {\\bar {\\rho} } $ as in Proposition \\ref{p}, there is a\n(weakly) compatible system $(\\rho_{\\lambda})$ where $\\lambda$ runs through all\nplaces of a number field $E$, and $\\rho$ is a member of the\ncompatible system above the prime of $p$ fixed by $\\iota_p$. Further \n$\\rho_{\\lambda}$ for $\\lambda$ above the prime $\\ell$ ($>2$) fixed by $\\iota_\\ell$, that is not ramified in $ {\\bar {\\rho} } $ (and hence $\\neq p$), \nthe representation is Barsotti-Tate at $\\ell$, unramified outside the primes ramified in $ {\\bar {\\rho} } $, and \nthe inertial Weil-Deligne (WD) parameter at $p$ of $\\rho_{\\lambda}$ \n(i.e., if $(\\tau,N)$ is the WD parameter, with $\\tau$ a $F$-semisimple representation of the Weil group and $N$ \na nilpotent matrix, we consider only $(\\tau|_{I_q},N)$) is the same as that of\n$\\rho$ at $p$.\n \n(ii) Now we assume $ {\\bar {\\rho} } $ is as in Proposition \\ref{q}: thus \n$ {\\bar {\\rho} } $ does not have solvable image (but $p=3$ is allowed), it has the behaviour at a prime $q$ as in Proposition \\ref{q}, but we make the additional assumption that \n$k( {\\bar {\\rho} } )=2$. \nConsider a minimal lift $\\rho$ as in Proposition \\ref{q}, thus $\\rho$\nis Barsotti-Tate at $p$, and we assume that the nebentype at $q$, \n$\\chi\\eta_q^i$, is non-trivial. The inertial parameter at $q$ of $\\rho$ is $(\\omega_q^j \\oplus 1,0)$ ($ 1 \\leq j \\leq q-2$) where \n$\\omega_q^j:=\\chi\\eta_q^i$. There is a (weakly) compatible system $(\\rho_{\\lambda})$ where $\\lambda$ runs\nthrough all places of a number field $E$, and $\\rho$ is a member of\nthe compatible system at the place above $p$ fixed by $\\iota_p$. Further $\\rho_{\\lambda}$ for\n$\\lambda$ a prime above $q$ that is determined by $\\iota_q$, is unramified at all primes $\\neq\np,q$ outside which $ {\\bar {\\rho} } $ is unramified, is unramified at $p$, and at $q$\nis Barsotti-Tate over $\\mathbb{Q}_q(\\mu_q)$. Assume that $\\overline{\\rho_\\lambda}$\nhas non-solvable image. Then $\\overline{\\rho_\\lambda}$ has weight $j+2$, \nor its twist by ${\\overline \\chi_q}^{-j}$\nhas weight $q+1-j$. \n\\end{prop}\n\n\\begin{proof}\nThis follows from the results in \\cite{Tay1} and \\cite{Tay2}, using the arguments in Section 3 of\n\\cite{KW} (see Theorem 3.1 of \\cite{KW}). \n\nThe existence of a weakly compatible system $(\\rho_{\\lambda})$, of which $\\rho$ is a member, follows easily from the proof of Theorem 6.6 of \\cite{Tay2} (which uses Brauer's theorem on writing representations of finite groups as a virtual sum of representations induced from characters of solvable subgroups, and base change results of Arthur and Clozel in \\cite{AC}). ({\\small We recall the construction of Taylor in \\cite{Tay1} and \\cite{Tay2}. In both (i) and (ii) we may assume that the image of $ {\\bar {\\rho} } $ is non-solvable. Then the lift $\\rho$ constructed is such that there is a totally real field $F$, Galois over $\\mathbb{Q}$, such that $\\rho|_{G_F}$ arises from a holomorphic, cuspidal automorphic representation $\\pi$ of $\\mathrm{GL}_2(\\mathbb{A}_F)$ with respect to the embedding $\\iota_p$. Using Brauer's theorem\nwe get subextensions $F_i$ of $F$ \nsuch that $G_i=\\mathrm{Gal} (F\/F_i)$ is solvable, characters $\\chi_i$ of $G_i$ with values in $\\overline \\mathbb{Q}$ (that we embed in $\\overline \\mathbb{Q}_p$ using $\\iota_p$), such that $1_{G}=\\sum_{G_i}n_i{\\rm Ind}_{G_i}^{G} \\chi_i$. Using \\cite{AC} we also\nget holomorphic cuspidal automorphic representations $\\pi_i$ of $\\mathrm{GL}_2(\\mathbb{A}_{F_i})$ such that\nif $\\rho_{\\pi_i,\\iota_p}$ is the representation of $G_{F_i}$ corresponding to $\\pi_i$ w.r.t. $\\iota_p$, then $\\rho_{\\pi_i,\\iota_p}=\\rho|_{G_{F_i}}$. Thus $\\rho=\\sum_{G_i}n_i{\\rm Ind}_{G_{F_i}}^{G_\\mathbb{Q}} \\chi_i\\otimes \\rho_{\\pi_i,\\iota_p}$.\nNow for any prime $\\ell$ and any embedding \n$\\iota:\\overline \\mathbb{Q} \\rightarrow \\overline \\mathbb{Q}_\\ell$, we define the virtual representation\n$\\rho_{\\iota}=\\sum_{G_i}n_i{\\rm Ind}_{G_{F_i}}^{G_\\mathbb{Q}} \\chi_i\\otimes \\rho_{\\pi_i,\\iota}$ of $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$\nwith the $\\chi_i$'s now regarded as $\\ell$-adic characters via the embedding $\\iota$. We check that $\\rho_{\\iota}$ is a true representation by computing its inner product. The representations $\\rho_\\iota$ together constitute the weakly compatible system we seek.})\n\nThus we concentrate below on proving some of the finer ramification properties claimed for $\\rho_{\\lambda}$\nat the prime of the same residue characteristic as $\\lambda$.\n\nFor instance the property at $p$ asserted in (i) follows directly from\nTaylor's results in \\cite{Tay1} (see Lemma 1.5 and Corollary 1.7 of it) which show that $\\rho|_{G_F}$ is modular for some $F$ that is unramified at $p$, i.e., it arises (w.r.t.\nthe embedding $\\iota_p$) from a Hilbert modular form $f$ for $F$.\nIn fact \\cite{Tay1} also shows that $f$ is ordinary at all primes above $p$ (w.r.t. $\\iota_p$), and at such primes \nis either principal series of conductor dividing $p$ with ``nebentype'' $\\omega_p^{k-2}$ (i.e.,\nthe automorphic representation corresponding to $f$ is such that at primes $\\wp$ above $p$ the corresponding\nlocal component is the principal series $\\pi(\\psi_1,\\psi_2)$, with $\\psi_1$ restricted to the units given by the character corresponding to $\\omega_p^{k-2}$ by local class field theory and $\\psi_2$ unramified), or Steinberg at $p$ (the latter only in the case $k( {\\bar {\\rho} } )=p+1$). The reader may also consult proof of Proposition 2.5 of \\cite{KW} for more details, especially in the ordinary case.\n\nWe turn to proving (ii).\nWe know by \\cite{Tay1} and \\cite{Tay2} that there is a totally real field $F$\n(which we may assume to be Galois over $\\mathbb{Q}$) \nover which $\\rho|_{G_F}$ is modular. \nIf $F'\\subset F$ is the fixed field of a decomposition group above $q$, then there is a prime $Q$ above $q$ in $F'$ which is a split prime. We deduce using \\cite{AC}, \\cite{Carayol} and \\cite{Tay}, \nthat $\\rho|_{G_F'}$, and hence \n$\\rho_\\lambda|_{G_{F'}}$, arises from a Hilbert modular form $f$ which locally at \n$Q$ is a ramified principal series of conductor $Q$, whose nebentypus at $Q$ is $\\omega_q^j:=\\chi\\eta_q^i$. This also proves the assertion about the inertial parameter of $\\rho$ at $q$.\n\nWe now focus on the properties of $\\rho_{\\lambda}$ asserted at $q$\n(as outside $q$ the proof is the same as in Section 3 of \\cite{KW}).(We may assume that $F$ is of even degree over $\\mathbb{Q}$ as we are done otherwise by \\cite{Saito}.) We first prove that $\\rho_\\lambda$ when restricted to\n$\\mathbb{Q}_q(\\mu_q)$ is Barsotti-Tate (which uses the assumption\nthat $\\chi\\eta_q^i$ is non-trivial). To see this, we work over a totally real field \n$F''$ that is a solvable extension of $\\mathbb{Q}$ which when completed at all \nplaces above $q$ is $\\mathbb{Q}_q(\\mu_q)$ (see Lemma 2.2 of \\cite{Tay3}), \nand apply to $(\\rho_\\lambda|_{G_{F''}})$ the same arguments as those in proof of Theorem 3.1 of \\cite{KW} for $(\\rho_\\lambda)$, but instead of using \nTh\\'eor\\`eme 1 (ii) of \\cite{Breuil-cong} we use \na result of \\cite{Raynaud} (see Proposition 2.3.1), which we may \nas we are in the weight 2 case. \n({\\small Recall that $\\rho|_{G_{F'}}$ arises from a weight 2 Hilbert modular form $f$ for $GL_2(\\mathbb{A}_{F'})$ that when base changed to the composite $F'F''$ of $F'$ and $F''$, which is a solvable extension of $F'$, becomes\nunramified at places above $q$. This uses results of \\cite{Tay1}, \\cite{Tay2}, \n\\cite{Carayol}, \\cite{Tay}, \\cite{AC} as in Section 3 of \\cite{KW}.\nThis then gives the required statement by deducing that \n$\\rho_{\\lambda}|_{G_{F''F'}}$ mod $\\lambda^n$ is finite flat at primes above $q$ by Th\\'eor\\`eme 1 (i) of \\cite{Breuil-cong},\nand then using Proposition 2.3.1 of \\cite{Raynaud}, instead of using Th\\'eor\\`eme 1 (ii) of \\cite{Breuil-cong} which got used in proof of Theorem 3.1 of \\cite{KW}. Note that the completion at a prime above $Q$ of $F'F''$ is $\\mathbb{Q}_q(\\mu_q)$.}) \n\nNow assume that the image of $\\overline \\rho_\\lambda$ is non-solvable.\nIt is not hard to see that \n${\\overline \\rho_\\lambda}|_{G_{F'}}$, which we know is modular, also arises from a Hilbert modular \nform $f'$, congruent to $f$ mod place fixed by $\\iota_q$, that is square integrable at a finite place $\\alpha$ and at $Q$ of conductor $Q$ and of nebentypus $\\chi\\eta_q^i$ at $Q$. \n({\\small To get such a $f'$ congruent to $f$ is standard: \nWe use the level raising techniques of \\cite{Tay}, using the proof of Theorem 2 of {\\it loc.\\ cit.\\ } to find a \n$\\alpha$, prime to $q$, such that using notation of Theorem 1 of {\\it loc.\\ cit.\\ } the valuation under $\\iota_p$ of $\\Theta_f(T_{\\alpha}^2-S_{\\alpha}(\\mathbb{N} \\alpha +1)^2)$\nis bigger than that of $E_f((\\mathbb{N} \\alpha +1))$ (for instance $\\mathbb{N}$ stands for the norm from $F'$ to $\\mathbb{Q}$). Then we prove the existence of the desired $f'$ which is square integrable at a finite place $\\alpha$ and at $Q$ is fixed by $U_1(Q)$ which gives rise to ${\\overline \\rho_\\lambda}|_{G_{F'}}$, using the proof of Theorem 1 of {\\it loc.\\ cit.\\ } with $\\lambda=\\alpha$ in the notation there.\nThat $f'$ has nebentype $\\omega_q^j=\\chi\\eta_q^i$ at $Q$ follows by considering determinants and central characters.})\n\nThen we use the results of \\cite{Saito} to conclude that at $Q$ the inertial WD parameter of $\\rho_\\lambda|_{G_{F'}}$ \nis the same as that of $\\rho|_{G_{F'}}$ which we know to be $(\\omega_q^j \\oplus 1, 0)$\n(note that as $Q$ is a split prime of \n$F'$, local information at $Q$ of $\\rho_\\lambda|_{G_{F'}}$ gives the local information of $\\rho_\\lambda$\nat $q$). After this, to get the information about \nweights, we use Proposition 6.1.1 of \\cite{BM} and Theorem 6.11 of \\cite{Savitt1},\nas we have that $\\rho_\\lambda|_{G_{F'}}$\nis irreducible by Lemma 2.6 of \\cite{KW}.\n\\end{proof}\n\n\n\n\n\\section{Chebyshev's estimates on primes}\\label{cheb}\n\nIn the proof of Theorem \\ref{main} below, \nwe will need some estimates on prime numbers proven by Chebyshev (we learnt about \nthe following precise form of Chebyshev's estimate from a message of J-P.~Serre, and from R.~Ramakrishna). \n\nIf $\\pi(x)$ is the prime counting function, then if $x >30$\n$$A({ x \\over {\\rm log}(x)}) \\leq \\pi(x) \\leq B({ x \\over {\\rm log}(x)})$$ where $A=0.921...$ and \n$B \\over A$ is ${6 \\over 5}=1.2$ (see \\cite{Chebyshev1} and \\cite{Chebyshev2}, and also page 21 of \\cite{Ellison}). From this we easily deduce that\nif we fix a real number $a>1.2$, and denote by $p_n$ the $n$th prime which we\nassume $> {\\rm max}(30,a^{{6} \\over {5a-6}})$, then $p_{n+1} \\leq ap_n$. \n\nIn the arguments below this estimate will be relevant for particular values of $a$. Given $p_n>2$ we consider an odd (prime power) \ndivisor $\\ell^r=2m+1$ of \n$P_{n+1}-1$, where $P_{n+1}$ is either $p_{n+1}$, or $p_{n+2}$ if $p_{n+1}$ is a Fermat prime, \nand divide the integers in the interval $[0,P_{n+1}-1]$ into blocks of size ${{P_{n+1}-1} \\over {\\ell^r}}$. We need to ensure that\n$p_n+1 \\geq {\\rm max}({{m+1} \\over {2m+1}}({P_{n+1}-1} )+2,\nP_{n+1}-({{m} \\over {2m+1}}({P_{n+1}-1} )))$. A computation shows that\nthis is ensured by requiring that\n$${{P_{n+1}}\\over p_n} \\leq {2m+1 \\over {m+1}} - ({m \\over {m+1}})({1 \\over {p_n}}).$$\nWe consider $p_n \\geq 31$.\n\nAn inspection shows that there is always a $P_{n+1}$ as required up to $p_n=1000$: use $a$ in the Chebyshev estimate to be ${44 \\over 30}={3 \\over 2} -{1 \\over 30}$ and rule out Fermat primes causing problems in that range (the only ones are $5,17,257$ and for $p_n=251$, the prime preceding $257$, we can use $P_{n+1}=263$).\nAfter that the Chebyshev estimate used with $a=\\sqrt{1.499}$ (note $1.499={3 \\over 2} - {1 \\over 1000}$, and that after $3,5$ no two successive primes can both be Fermat primes) \ngives the existence of $P_{n+1}$ of the required kind if $p_n$ is at least $21591$. For primes $10001$.\nAs $H$ has order prime to $p$, the image of inertia $I_p$ in $H$ is cyclic\n: denote by $\\tau _p$ a generator of the image of $I_p$ in $H$, and by $i_p$ the order of $\\tau_p$.\nNote that $t$ is odd. For if $t$ were even, $D_{2t}$ would have\na quotient which is $\\mathbb{Z}\/2\\mathbb{Z} \\times \\mathbb{Z}\/2\\mathbb{Z}$ which would give\na character of order $2$ unramified everywhere.\nAs $t$ is odd, $D_{2t}$ has only one\ncharacter of order $2$, say $\\eta$. It corresponds to a quadratic\nfield $K$ which is ramified at $p$. As $\\eta (\\tau _p )=-1$,\nand $t$ is odd, $\\tau _p$ is of order $2$.\nLet $L$ be the field cut up by the representation\nof $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ in $H$. Then $L\/K$ is unramified everywhere.\n\nLet $c\\in \\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ be a complex conjugation. As $ {\\bar {\\rho} } $ is odd,\n$c$ has non trivial image $\\gamma$ in $H$. As $t$ is odd,\n$\\eta (\\gamma)\\neq 1$ and\nthe quadratic field $K$ is imaginary. This implies\n$p \\equiv 3$ modulo $4$, and that $t$ is a divisor of $h_K$,\nthe class number of $K$ (which is known to be odd). Let $\\Delta _p$ be the image of the decomposition group\nat $p$ in $H$. As $\\Delta _p$ is a quotient of the Galois\ngroup of $\\mathbb{Q}_{p,unr}(\\sqrt{p} )\/\\mathbb{Q}_p$ (wher $\\mathbb{Q}_{p,nr}$ is the maximal unramified extension of $\\mathbb{Q}_p$), $\\Delta _p$ is\nabelian. As the subgroup $\\Gamma_p$ of $H$ of order $2$\ngenerated by $\\tau _p$ is its own centralizer ($t$ is odd),\none sees that $\\Delta _p=\\Gamma_p$. This implies that $ {\\bar {\\rho} } (D_p)$ is abelian.Thus $I_p$ acts under\n$ {\\bar {\\rho} } $ via characters of level $1$.\nLet us assume that we have twisted $ {\\bar {\\rho} } $ by the suitable\npower of the cyclotomic character so that\nthe Serre weight $k$ of $\\rho$ satisfies $2\\leq k\\leq p+1$.\nThen $I_p$ acts with characters $1$ and $\\chi_p ^{k-1}$.\nAs the image of $I_p$ in $H$ is of order $2$, one has $k-1= {p-1 \\over 2}$\nand $k={p+1 \\over 2}$.\n\n(ii) This follows because the image of inertia $I_p$ in the projective \nimage of $ {\\bar {\\rho} } $, which we know to be cyclic, is forced to be of order 2.\n\\end{proof}\n\n\\noindent{\\bf Remark:} We use part (i) of Lemma \\ref{dihedral} only to\ndeduce that a dihedral $ {\\bar {\\rho} } $ which is unramified outside $p$ is up to twist\nordinary at $p$. Note that once we know that in the proof $t$ is odd, we can also see this by deducing that locally at $p$\nthe fixed field of the kernel of $ {\\bar {\\rho} } $ cannot have an unramified quadratic subfield.\n\\vspace{3mm}\n\nWe also have a useful lemma which follows immediately from Serre's definition of weights:\n\n\\begin{lemma}\\label{weights}\n Assume $\\tau:G_{\\mathbb{Q}_p} \\rightarrow GL_2({\\mathbb F})$ is such that its weight $k \n\\neq 2$ is $2$,\n then for any prime $q$ the level 1 case of Serre's conjectures is known\n for all 2-dimensional, mod $q$, odd, irreducible representations $ {\\bar {\\rho} } $\n of weight $k( {\\bar {\\rho} } ) \\leq p+1$.\n\\end{cor}\n\n\\begin{proof} This is proved implicitly in \\cite{KW}.\nIt is enough to prove the first statement. We may assume $q>3$.\nBy Theorem 2.1 of \\cite{KW} lift $ {\\bar {\\rho} } '$ to a representation $\\rho'$ which is unramified outside $q$ and crystalline at $q$ of weight $k$. By Theorem 3.1\nof {\\em loc.\\ cit.\\ }, $\\rho'$ is part of a compatible system $(\\rho'_\\lambda)$\nsuch that at a place $\\lambda$ above $p$ the representation is unramified outside $p$ and crystalline of weight $k$ at $p$. The hypothesis of the corollary and Lemma \\ref{rubbish}, then gives the modularity of $(\\rho'_\\lambda)$ and hence that of $ {\\bar {\\rho} } '$.\n\\end{proof}\n\n\\section{Proof of Theorem \\ref{main}}\n\n\\subsection{Small weights}\n\nWe now prove our main theorem up to weights 32. (We do not really have to do so many weights before giving the general argument, \nbut this seems good preparation for that and also verification of the general strategy in concrete cases.) When we choose a place $\\lambda$ above a prime $\\ell$ this is always chosen to be with respect to the\nembedding $\\iota_\\ell: \\overline{\\mathbb{Q}} \\hookrightarrow \\overline{\\mathbb{Q}_{\\ell}}$ fixed once and for all a while ago.\n\nFor weights 2,4,6 this has already been proved in \\cite{KW}. Although the cases of weights 8,12,14 are also done in \\cite{KW}\nwe redo them to illustrate that after weight 6 our inductive method takes over.\nOur arguments below prove that the $ {\\bar {\\rho} } $ being considered arises from some level and weight, and then that it arises from weight $k( {\\bar {\\rho} } )$ and level $N( {\\bar {\\rho} } )=1$ follows from the results in \\cite{Ribet}, \\cite{Edix}.\n(Also note that the Serre weight in all cases considered is even and so \nthe residual mod $p$ representations when restricted to $I_p$ are never \nscalar. We often use the fact implicitly below that if $ {\\bar {\\rho} } $ is modular so is any twist of it by an abelian character, and the same fact for twists of $p$-adic representations $\\rho$ by finite order characters.)\n\n-- Consider the\nweight 8 case. It's enough to prove using Corollary \\ref{trivial}\nthat an irreducible $2$-dimensional, mod $7$ representation $ {\\bar {\\rho} } $ of level $1$ and\nweight $8$ is modular. (If the image is solvable we are done.) Such a representation is ordinary at $7$. By Proposition \n\\ref{p}, lift $ {\\bar {\\rho} } $ to a weight 2,\nsemistable at $7$, $7$-adic representation $\\rho$ that is unramified outside $7$. Using part (i) of \nProposition \\ref{c} get a compatible system $(\\rho_\\lambda)$ and reduce it mod a prime above 3 determined by $\\iota_3$ to get $ {\\bar {\\rho} } '$. Note that \nby Proposition \\ref{c} (i), $k( {\\bar {\\rho} } ')=2$, and $ {\\bar {\\rho} } '$ is\nunramified outside 3 and 7. If $ {\\bar {\\rho} } '$ has solvable image we are done, as in that case we have a representation to which we can apply known \nmodularity lifting results to conclude that the compatible system\n$\\rho_{\\lambda}$ is modular (\\cite{Wiles}, \\cite{TW}, \\cite{SW2}, \\cite{SW3}) and hence so is $ {\\bar {\\rho} } $:\nthese modularity lifting results may be applied\nas by part (ii) of Lemma \\ref{dihedral}, $ {\\bar {\\rho} } '$ cannot be both reducible when restricted\nto $G_{\\mathbb{Q}(\\sqrt{-3})}$ and irreducible locally at $3$. Similarly \nif $ {\\bar {\\rho} } '$ is unramified at $7$ we are again done\nas we know by page 710 of \\cite{Serre2} that the residual mod $3$ representation is then reducible.\nOtherwise use Proposition \n\\ref{q}, to\nget a 3-adic lift $\\rho'$ of $ {\\bar {\\rho} } '$ with nebentype $\\omega_7^2$ at 7 ($\\omega_7^4$ would also work). Then use Proposition\n\\ref{c} to get a compatible system $(\\rho'_{\\lambda})$ with $\\rho'$ the member of this compatible system at the place corresponding to $\\iota_3$, \nand consider a residual representation $ {\\bar {\\rho} } '_7$ arising from this system at a place \n$\\lambda$ above 7 fixed by $\\iota_7$. We know\nby Lemma \\ref{breuil} (Proposition 6.1.1 of \\cite{BM})\nthat if the residual mod $7$ representation $ {\\bar {\\rho} } '_7$ locally at $7$ is reducible then the $7$-adic\nrepresentation is also locally reducible. Thus in this case up to twisting \nby a power of $\\omega_7$ we may\nassume the $7$-adic representation is ordinary at $7$ by Proposition 6.1.1 of \\cite{BM}: the representation will also be $I_7$-distinguished as the residual weights are even.\n\nIf $ {\\bar {\\rho} } '_7$ has solvable image, and hence known to be modular, we are done by applying results of \\cite{SW2}, \\cite{SW3} and \\cite{Kisin}, which can be applied as\nin the ordinary cases the representation will be $I_7$-distinguished\n(and that in the dihedral case the representation is ordinary at $7$ by part (i) of Lemma \\ref{dihedral}), and we conclude that \n$(\\rho'_{\\lambda})$ is modular.\n\nNow assume that $ {\\bar {\\rho} } '_7$ has non-solvable image. We get a\nresidual representation whose Serre weight (up to twisting) is either 4\nor $7+3-4=6$ by Proposition 6.1.1 of \\cite{BM}, Theorems 6.11 and 6.12 of \n \\cite{Savitt1} (as explained in Proposition \\ref{c} (ii)), \nand we know the residual modularity for such weights (in fact we also know that in these cases again that $ {\\bar {\\rho} } '_7$ is reducible,\nalthough for uniformity of treatment we do not use this). \nNow we again use modularity lifting results in \\cite{SW2}, \\cite{SW3}, \\cite{Kisin} as we just used and conclude that \n$(\\rho'_{\\lambda})$ is modular.\n\nHence so is the residual representation \n$ {\\bar {\\rho} } '$, and hence by another application of modularity lifting theorem \nwe conclude that the first compatible system $(\\rho_{\\lambda})$ is modular (as the compatible systems $(\\rho_{\\lambda})$ and $(\\rho'_{\\lambda})$ are linked at the place above 3 fixed by $\\iota_3$), and hence so is $ {\\bar {\\rho} } $ (which in this case means that it does not exist!).\n\n(Now we will be more succinct, and skimp some of the details before we get to the general arguments of the next section, as it's much of the same thing!)\n\n-- Weights 10 and 12: Consider a representation $ {\\bar {\\rho} } $ mod 11 that is irreducible and of\nweight 10 or 12. Its enough by Corollary \\ref{trivial} to prove this to be modular to conclude that for any prime at least 11, any $ {\\bar {\\rho} } $ of level 1 and \nweight 10 or 12 is modular. (If the image is solvable we are done.) By Lemma \\ref{weights} locally at 11 we may assume that the representation is (non semisimple and)\nordinary, and hence we get a weight 2 minimal lifting $\\rho$ unramified outside 11. \nThen by Propositions \\ref{p} and \\ref{c} make $\\rho$ part of a \ncompatible system $(\\rho_{\\lambda})$, \nsuch that the representation in the system corresponding to $\\iota_{11}$ is $\\rho$,\nand then consider the residual representation $\\overline{\\rho_{5}}$ \nat a prime $\\lambda$ above 5 fixed by $\\iota_5$. We are done if the image\nof $\\overline{\\rho_{5}}$ is solvable (or unramified at 11 and hence solvable by the weight 2, level 1 case proved in \\cite{KW}) arguing just as in the previous case. \nOtherwise using Proposition \\ref{q} construct lift of $\\overline{\\rho_{5}}$ with nebentype $\\omega_{11}^4$ ($\\omega_{11}^6$ would also work) at 11, and we can do this for either of the 2 weights 10 or 12 being considered.\nArgue as before and get a compatible system $(\\rho'_{\\lambda})$ which residually \nat the prime above 11 fixed by $\\iota_{11}$ \nwill have weight (up to twisting by some power of $\\overline \\chi_{11}$)\neither 6 or 8 (the same weights if we had chosen lifting with nebentype $\\omega_{11}^6$ when applying Proposition \\ref{q}), and then we are done as before.\n\n\n--Weights $14,16,18,20$: It will be enough to show that a mod $19$ representation $ {\\bar {\\rho} } $ \n(irreducible, odd, $2$-dimensional of level one as always) of any of these weights is modular. (If the image is solvable we are done.) As we have \ndealt with weights up to $12$, we may assume by Lemma \\ref{weights} that $ {\\bar {\\rho} } $ is ordinary at $19$.\nWe again construct a weight 2 minimal lift $\\rho$ of $ {\\bar {\\rho} } $ and get a compatible system $(\\rho_{\\lambda})$ (by Propositions \\ref{p} and \\ref{c}(i)) and consider a residual representation at the place above $3$\ndetermined by $\\iota_3$ (again we are done if the residual mod 3 representation has either solvable image or is unramified at 19), and apply Proposition \\ref{q}\nto get a lifting $\\rho'$ of the mod 3 representation that is unramified outside $3,19$, Barsotti-Tate at 3, and has nebentype\n$\\omega_{19}^8$ at 19 ($\\omega_{19}^{10}$ would also work). Then make it part of a compatible system $(\\rho'_{\\lambda})$ (using Proposition \\ref{c} (ii)) \nwhich residually at a prime above 19 will \nhave weight (up to twisting by some power of $\\overline \\chi_{19}$) either 10 or 12 (the same if the nebentype $\\omega_{19}^{10}$ had been chosen). Again we can argue as \nbefore, knowing Serre's conjecture in level 1 for weights 10 and 12, and we are done.\n\n\n-- Weights $22,24,26,28,30$: It will be enough to show that a mod 29 representation $ {\\bar {\\rho} } $ (irreducible, odd, 2-dimensional of level one as always) of any of these weights is modular. (If the image is solvable we are done.) As we have dealt with weights up to 20, \nwe may assume by Lemma \\ref{weights} that $ {\\bar {\\rho} } $ is ordinary at 29.\nThis time we lift $ {\\bar {\\rho} } $ to a minimal lift $\\rho$ of weight 2\n(by Proposition \\ref{p}), make $\\rho$ part of \na compatible system $(\\rho_{\\lambda})$ \n(by Proposition \\ref{c}(i)) and \nconsider a residual representation at a prime above 7 determined by $\\iota_7$\n(that we may assume is ramified at $29$ and has non-solvable image). Apply Proposition \\ref{q}\nto get a lifting $\\rho'$ of the mod $7$ representation that is unramified outside $3,19$, Barsotti-Tate at $7$, and has nebentype\n$\\omega_{29}^{16}$ at 29 when the weight is one of 22,26,30, or nebentype\n$\\omega_{29}^{14}$ at 29 when the weight is 24 or 28. Using Proposition \\ref{c} (ii)\nmake it part of a compatible system $(\\rho'_{\\lambda})$ which residually at a prime above 29 will have weight (up to twisting by some power of $\\overline \\chi_{29}$) 18 or 14 (if the \nweight of $ {\\bar {\\rho} } $ is one of 22,26,30), or weight 16 (if the weight of $ {\\bar {\\rho} } $ was either 24 or 28). Again we can argue as \nbefore, knowing Serre's conjecture in level 1 for weights 14,16,18, and we are done.\n\n-- Weight 32: It will be enough to show that a mod 31 representation $ {\\bar {\\rho} } $ (irreducible, odd, 2-dimensional of level one as always) of weight 32 is modular. (If the image is solvable we are done.) It's the same argument as before. We use as a foil the prime 5, and in the end construct a weight 2 compatible system $(\\rho'_{\\lambda})$, whose modularity yields that of $ {\\bar {\\rho} } $, \nof nebentype $\\omega_{31}^{16}$ at 31\nsuch that at a prime above 31 the residual representation has weight (up to twisting by some power of $\\overline \\chi_{31}$)\neither 18 or 16. As we know Serre's conjecture in level 1 for these weights we can conclude.\n\n\\subsection{The general argument}\n\nNow we give the general argument (which the reader \nmust surely have guessed the gist of). This, together with the previous section, will prove Theorem \\ref{main}.\n\nAssume we have proven the level 1 case of Serre's \nconjecture mod $p_n$ where $p_n$ is a prime $\\geq 31$. This implies by Corollary \\ref{trivial} (ii)\nthat for any prime $q$ we know Serre's conjecture for any level 1 \nmod $q$ representation $ {\\bar {\\rho} } $ that is odd, irreducible, 2-dimensional\nof weight $ k( {\\bar {\\rho} } ) \\leq p_n+1$.\n \nBy the arguments in Section \\ref{cheb}, we can find a prime $P_{n+1}>p_n$, \nwhich is not a Fermat prime, and an odd prime power $\\ell^r=2m+1$ that divides $P_{n+1}-1$ exactly such that\n\\begin{equation}\\label{*}\n{{P_{n+1}} \\over {p_n}} \\leq \n{2m+1 \\over m+1} - ({m \\over m+1})({1 \\over p_n}).\n\\end{equation} (This inequality holds for any integer $m \\geq 1$.)\nConsider any weight $k$ such that $p_n+2 \\leq k \\leq P_{n+1}+1$: \ngiven such a $k$ \nwe would like\nto prove that any 2-dimensional irreducible, odd, mod $P_{n+1}$ representation $ {\\bar {\\rho} } $ of $\\Galois( \\bar{ {\\mathbb Q}}\/{\\mathbb Q})$ of level 1 and weight $k( {\\bar {\\rho} } )=k$ is modular. \nBy Corollary \\ref{trivial}, this will prove Serre's level 1 conjecture\nfor any 2-dimensional, odd irreducible, mod $q$ representation \nof Serre weight $k$, where $q \\geq k-1$, and also the level 1 conjecture mod all primes $\\leq P_{n+1}$ \nonce we have done this for all weights $p_n+2 \\leq k \\leq P_{n+1}+1$. Then we continue with $P_{n+1}$, treating it like $p_n$ etc.\nWe denote $P_{n+1}$ by $p$ for notational \nsimplicity. (This is the inductive method \nto attack the level 1 case of Serre's conjecture \nproposed in Theorem 5.1 of \\cite{KW}.)\n\nBy Lemma \\ref{weights}, and as we know the conjecture for weights $\\leq p_n+1$, and using (\\ref{*}),\nwe can assume that $ {\\bar {\\rho} } $ is ordinary at $p$. \nConstruct a minimal weight 2 \nlift $\\rho$ of $ {\\bar {\\rho} } $ using Proposition \\ref{p}. (If $ {\\bar {\\rho} } $ is solvable we already know its modularity, so we may assume it is not, although we need not.) \nThis lift is unramified outside $p$ and minimal of weight 2 at $p$.\nUsing part (i) of Proposition \\ref{c} make it part of a compatible system $(\\rho_{\\lambda})$, so that for a place above $p$ fixed by the embedding $\\iota_p$ the corresponding representation is $\\rho$. \nNow reduce the system modulo a prime $\\lambda$ above \n$\\ell$ with $\\lambda$ determined by the embedding $\\iota_{\\ell}$. \nDenote the residual mod $\\ell$ representaion by $ {\\bar {\\rho} } _\\ell$, and note that by part (i) of Proposition \\ref{c}, $k( {\\bar {\\rho} } _\\ell)=2$.\nIf $ {\\bar {\\rho} } _\\ell$ had solvable image we would be done. This is because by Lemma \\ref{dihedral} (i), \nin the case when the representation $ {\\bar {\\rho} } _\\ell$ restricted to $G_{\\mathbb{Q}(\\sqrt{{(-1)}^{\\ell-1 \\over 2}\\ell})}$ is reducible, \n$ {\\bar {\\rho} } _\\ell|_{D_\\ell}$ is ordinary (as $\\ell>2$ and hence $\\ell+3 \\over 2$$>2$), \nand in the cases when either this happens or $ {\\bar {\\rho} } _\\ell$ is reducible, and thus ordinary at $\\ell$, \n$ {\\bar {\\rho} } _\\ell$ restricted to $I_{\\ell}$ is distinguished. As $\\ell$ is an odd prime, \nthis allows us to apply the modularity lifting theorems \nproved in \\cite{Wiles}, \\cite{TW}, \\cite{SW2} and \\cite{SW3}, to prove the modularity of \n$\\rho_\\lambda$ and hence of $ {\\bar {\\rho} } $.\nIf the mod $\\ell$ representation were unramified at \n$p$, using the result in \\cite{KW} for weight 2, we \nwould see that the representation is reducible and \nagain we would be done.\n\nOtherwise apply Proposition \\ref{q}\n(with $p$ of that proposition, the present $\\ell$, and the $q$ there the present $p$!) \nto choose a lifting $\\rho'$ of this residual mod $\\ell$ representation $ {\\bar {\\rho} } _\\ell$, unramified outside $\\ell,p$, \nBarsotti-Tate at $\\ell$, and such \nthat the nebentype at $p$ is $\\omega_p^j$ \nwith $j$ in the interval $({m \\over 2m+1} ({p-1}),{m+1 \\over 2m+1} ({p-1})]$\n(recall that we have set $\\ell^r=2m+1$).\nUsing part (ii) of Proposition \\ref{c}, make $\\rho'$ part of a compatible system $(\\rho'_{\\lambda})$ and consider a place above $p$\ndetermined by the embedding $\\iota_p$. We get a $p$-adic representation $\\rho''$ at that place \nthat is unramified outside $p$, and such that\nat $p$ the representation is Barsotti-Tate over (the degree $p-1 \\over 2$ subfield of) $\\mathbb{Q}_p(\\mu_p)$ by part (ii) of Proposition \\ref{c}. \n\nNow note that if the representation residually, say $ {\\bar {\\rho} } ''$, were reducible locally at $p$, then $\\rho''$ at $p$ itself would be ordinary up to twisting by \na power of $\\omega_p$ by \nLemma \\ref{breuil} above (which is a consequence of \nProposition 6.1.1 of \\cite{BM}, and Theorems 6.11 of \n \\cite{Savitt1}), and would also\nhave distinct characters on the diagonals when restricted to $I_p$ (as the weight is even), i.e., is $I_p$-distinguished. \n\nFurther if $ {\\bar {\\rho} } ''$ had solvable image, then as by \n Lemma \\ref{dihedral} above we know that if $ {\\bar {\\rho} } ''$ is reducible when restricted to $G_{\\mathbb{Q}(\\sqrt{{(-1)}^{p-1 \\over 2}p})}$\nthen it's ordinary at $p$, and also $I_p$-distinguished, we can apply the modularity lifting theorems of \n\\cite{SW2},\\cite{SW3} and \\cite{Kisin} to conclude the modularity of $\\rho''$.\nThe main theorem of \\cite{Kisin} \nis used in the non-ordinary case,\nwhen we invoke a modularity lifting result when the lift is potentially Barsotti-Tate at $p$ over a tamely ramified extension, in fact over $\\mathbb{Q}_p(\\mu_p)$, and the residual representation is irreducible when restricted to\n$G_{\\mathbb{Q}(\\sqrt{{(-1)}^{p-1 \\over 2}}p)}$.\n\n\nSo we can now assume that $ {\\bar {\\rho} } ''$ has non-solvable image. \nWe see by the last line of part (ii) of Proposition \\ref{c},\nthat $k( {\\bar {\\rho} } '')$ is either $j+2$ or $k( {\\bar {\\rho} } '' \\otimes \\overline \\chi_p^{-j})=p+1-j$. Note that by our choice of $j$, $j+2$ is contained \nin in the interval $({ m \\over 2m+1} ({p-1})+2,({ m+1 \\over 2m+1}) ({p-1})+2]$ and $p+1-j$\nis in the interval\n$[p+1-(({ m+1 \\over 2m+1}) ({p-1})), p+1-(({ m \\over 2m+1}) ({p-1})))$.\n But (\\ref{*}) gives that both these intervals are contained in the interval $[2,p_n+1]$ as noted in Section \\ref{cheb}.\nHence we know the modularity of $ {\\bar {\\rho} } ''$ as we know by hypothesis the modularity of irreducible, mod $p$, odd, 2-dimensional, unramified outside $p$ \nrepresentations of weights $\\leq p_n+1$.\nWe can now apply the modularity lifting theorems of \n\\cite{Kisin} to conclude that $\\rho''$ is modular.\n\nThus the compatible system $(\\rho_\\lambda')$ is modular. Note that $(\\rho_\\lambda)$ \nand $(\\rho_\\lambda')$ are linked at the prime above $\\ell$ determined by $\\iota_\\ell$, i.e., \nat the prime \nabove $\\ell$ fixed by $\\iota_\\ell$, the residual representations \narising from the 2 systems are isomorphic (and have non-solvable image). Thus applying the modularity lifting theorems which were the first ones to be proven, i.e., in \\cite{Wiles} and \\cite{TW}, \nwe conclude that $(\\rho_{\\lambda})$ is modular. Hence $ {\\bar {\\rho} } $ is modular of some weight $k$ and level, and then of weight $k( {\\bar {\\rho} } )$ and level 1 \nby \\cite{Ribet}, \\cite{Edix}.\n\n\\vspace{3mm}\n\n\\noindent{\\bf Remark:} It will be of interest to see, both in \\cite{KW} and the present paper, if the residually solvable cases can also be handled internally by the method of the papers themselves, rather than using the fact that Serre's conjecture is known for them.\n\nWe also remark that the proof does use an auxiliary prime $\\ell \\neq p$, but no ramification is introduced at this prime, unlike in the \nmore traditional use of auxiliary primes. \n\n \n\\section{Corollaries}\\label{cors}\n\n\\subsection{Proof of corollaries}\n\nThe case of $q=2$ of Corollary \\ref{cond} is dealt with in Theorem 4.1(ii) \nof \\cite{KW}. (The case $p=3$ is excluded there, but is dealt with\nby the remarks about $p=3$ in Section \\ref{liftings}.) Note that in the case $q=2$ we are using results of the type proven in \\cite{Fontaine}, \\cite{BK}, \\cite{Schoof1}.\n\nCorollary \\ref{cond} when $q \\neq 2$ follows from Theorem \\ref{main} on using the method of ``killing ramification'' in Section 5.2 of \\cite{KW}. We give very briefly the proof.\nFirst apply the minimal lifting result of \\cite{KW}, Theorem 2.1 of Section 2,\nto construct first a minimal $p$-adic lift $\\rho$ of $ {\\bar {\\rho} } $ and then apply Theorem 3.1 of \n{\\it loc.\\ cit.\\ } to get a compatible system $(\\rho_\\lambda)$\nof which $\\rho$ is a part.\nConsider the prime above $q$ determined by $\\iota_q$ and reduce the representation which is a member of $(\\rho_\\lambda)$ \nat this prime (this is the method of ``killing ramification'' of Section 5.2 of \n\\cite{KW}). Residually we get a mod $q$ representation that is unramified outside $q$, for which we know Serre's conjecture by the main theorem of this paper. Then the lifting theorems recalled above, which may be applied because of Lemma \\ref{dihedral} and Lemma \\ref{breuil} (the latter due to Breuil, M\\'ezard and Savitt), imply that the compatible system $(\\rho_\\lambda)$ is modular and hence so is $ {\\bar {\\rho} } $.\n\nCorollary \\ref{finite} follows as we know that a mod $p$ irreducible 2-dimensional representation\nof $G_\\mathbb{Q}$ that arises from $S_k(SL_2(\\mathbb{Z}))$ (for any integer $k\\geq 2$) also arises from $S_2(\\Gamma_1(p^2))$. \n\n\n\n\\subsection{Quantitative refinements?} \n\nCorollary \\ref{finite} is a folk-lore consequence of Serre's conjecture and \nis there implicitly at the end of Tate's article \\cite{Tate}.\nIt will be of interest to get quantitative refinements of Corollary \\ref{finite}. \n\n After the corollary it is easy to see that for a fixed prime $p$ the number\n$N(2,p)$ of\nisomorphism classes of continuous semisimple\n odd representations $ {\\bar {\\rho} } :G_\\mathbb{Q} \\rightarrow GL_2(\\overline{\\mathbb{F}_{p}})$\n that are unramified outside $p$ is bounded by $Cp^3$ for a constant $C$ independent of $p$. This is seen as by the main theorem of the paper we are counting the number of distinct level 1 mod $p$ Hecke eigensystems, and then using formulas for the dimension of $S_k(SL_2(\\mathbb{Z}))$, and the fact that, up to twist by powers of $\\overline \\chi_p$, all mod $p$ forms have weight $\\leq p+1$, we are done. \n\nWe would guess that $N(2,p)$ is asymptotic to ${1 \\over {48}} p^3$ with $p$.\n\nSerre has pointed out that another easy corollary of Theorem \\ref{main} is that any $ {\\bar {\\rho} } $ in Corollary \\ref{finite} can be\nwritten over a finite field ${\\mathbb F}_{p^e}$ with $e \\leq {\\rm sup}(1,{p+1 \\over 12})$.\n\n\\section{Some remarks}\n\nThe arguments in this paper were arrived at when thinking of how to extend the results in \\cite{KW} \nto prove Serre's conjecture in the level 1 case for \n(finitely many) more weights, upon Schoof telling us that he could prove that all semistable abelian varieties over $\\mathbb{Q}$ with good reduction outside 17 (resp., 19) are isogenous to powers of $J_0(17)$ (resp., $J_0(19)$). Using the method of \\cite{KW} this immediately proved modularity of $ {\\bar {\\rho} } $ of level 1 and weights 18 and 20. With further thought, we could do weights 10 and 16. The trick we came up with to do weight 16\nled to the method presented in this paper. \n\n\nThe trick to do weight 10, which we have not used in the\npresent paper, was as follows: it's enough to prove that a mod $11$ representation of weight 10 is modular, and enough to assume that it's ordinary at 11. Now we can get a minimal lifting of $ {\\bar {\\rho} } $ that is crystalline, and ordinary, of weight 20 at $11$ by using the arguments of proof of Theorem 2.1 of \\cite{KW}, and then putting it in a compatible system and \nreducing it mod $19$ we deduce modularity by the weights $2$ and $20$ results.\nThe trick for weight 16 is subsumed, and superseded (as we at first still made\nuse of Schoof's result for the prime 19), in the \nmethod of the paper. \n\nThe weaning away (after weight 6) \nfrom results classifying semistable abelian varieties \n$A$ with good reduction outside a prime $p$ was necessary, as such results can only be proven for small $p$. For large $p$ such $A$ may not be isogenous to products of $\\mathrm{GL}_2$-type abelian varieties, and even those of the latter type cannot be proved to be factors of $J_0(p)$ by arguments that use discriminant bounds. For a related reason the method of Tate cannot be used\nto prove Theorem \\ref{main} for large primes $p$ (perhaps $p=5$ is the limit\nof this method, even assuming the GRH: see \\cite{Tate} and the discussion in \\cite{Brue}).\n\nIn \\cite{KW} a possible, and even plausible, path to the general case of Serre's conjecture was mapped out\nin its last section. The method was to use induction on primes in 2 different ways. For the level 1 case (see Theorem 5.1 there), the induction was on the prime which was the residue characteristic, the starting point being the cases of the conjecture proved for $p=2,3$ by Tate and Serre. \nWe have used this method in the present paper.\nFor the reduction to the level 1 case (see Theorem 5.2 there; this is the method of ``killing ramification''),\nthe induction was on the number of primes ramified in the residual representation, the starting point being the level 1 case. \n\nBut the path seemed to be blocked by \nformidable obstacles. This paper reaches \nthe level 1 case by sidestepping (and not overcoming any of) these technical obstacles. The method here, combined \nwith the proposed method of reduction of the general case \nto the level 1 case in the last section of \\cite{KW}, will probably be useful for general\nlevel $N$, and ease some of the technical difficulties. \n\n\n\n\n\n\n\\vspace{5mm}\n\n\\noindent{\\bf Acknowledgements:} We are grateful to Ren\\'e Schoof for \ntelling us about his unpublished results \nfor semistable abelian varieties over $\\mathbb{Q}$ with good reduction outside 17 and 19: although in this paper we have \nnot directly made use of these, our attempt to apply them to Serre's conjecture led to the method of the paper.\nWe would like to thank Gebhard B\\\"ockle for very helpful correspondence about Section 2 of the paper. \nWe are grateful to Gebhard B\\\"ockle, Kevin Buzzard, Jean-Pierre Serre and Jean-Pierre Wintenberger for very helpful comments on the mansucript. We thank Christophe Breuil for pointing out the reference \\cite{Savitt1}. We thank Jean-Pierre Serre for telling us about the history of his conjecture. The author was partially supported\nby NSF Grant DMS - 0355528.\n\n\\nocite{*}\n\\bibliographystyle{plain}\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} {"text":"\\section{Introduction}\n\\label{sec:introduction}\nGeneral matrix multiplication(GEMM), as one of the most important numerical algorithm in dense linear algebra, has been exhaustively studied over the years\\cite{goto2008anatomy, wang2013augem, van2015blis}. Many famous BLAS(Basic Linear Algebra Subprograms) libraries, like Intel MKL\\cite{intel}, OpenBLAS\\cite{wang2013augem}, BLIS\\cite{van2015blis}, and ARMPL\\cite{armpl}, already implemented high-performance GEMM. GEMM is used to compute $C=\\alpha A\\times B + \\beta C$. Here $C$, $A$, $B$ are $M\\times N$, $M\\times K$, and $K \\times N$ matrices, respectively.\n\nIn recent years, small GEMM becomes more and more important in many fields, such as machine learning\\cite{hinton2018matrix}, sparse matrix\\cite{borvstnik2014sparse}, and fluid dynamics\\cite{wozniak2016gimmik}. Many CNNs algorithms use the small matrix on their fully connected layers\\cite{CNNinFClayer, wang2021high}. \nCaffe \\cite{caffe} is a famous deep learning framework. \nComparing to BLIS that has not optimized small GEMM, the performance of Caffe utilized optimized BLIS can obtain a performance improvement of 17\\%\\cite{2017AcceleratingMLbyBLIS}.\nBy using the optimized implementation of small GEMM, Geoffrey Hinton reduced the number of parameters by a factor of 15 to 310K compared with their baseline CNN with 4.2M parameters \\cite{hinton2018matrix}.\nIn this paper, we define small GEMM as, $\\sqrt[3]{MNK}\\le 80$, when transposition of input matrices is not TN(TN will be explained in TABLE \\ref{tab:ALL GENERATED KERNELS}), or $\\sqrt[3]{MNK}\\le 32$ when transposition of input matrices is TN. This definition will be explained in Section \\ref{sec:performance}.\n\nTraditional implementation and optimization methods of GEMM mainly have three steps: block step, pack step and compute step. Block step tiles matrices into a series of small blocks based on features of the hardware, e.g., TLB, size of the L2 cache. Pack step packs these small blocks based on kernel size to ensure continuity of memory access during kernel calculation. Compute step uses one high-performance kernel with boundary processing to compute matrix multiplication. Because input matrices are relatively large, pack step can massively reduce cache miss and TLB miss, and costs of boundary processing can be neglected.\n\nHowever, traditional implementation and optimization methods of GEMM, as described above, cannot achieve optimal performance for small GEMM. Here are two reasons for this. First, the overhead of pack step in small GEMM is too high, as shown in Section \\ref{sec:performance}. The advantages of pack step are no longer significant, but it results in high extra memory access overhead. Second, the costs of boundary processing are not neglected for small GEMM. Therefore, designing and implementing a method without pack steps and boundary processing is very necessary for achieving high performance of small GEMM.\n\nThis paper proposes an input-aware adaptive tuning framework(IAAT) for small GEMM to achieve near-optimal performance. IAAT has two stages, the install-time stage and the run-time stage. The install-time stage is responsible for auto-generating high-performance assembly kernels of different sizes. This stage automatically tunes kernels based on features of hardware to achieve optimal performance. The run-time stage's core is the input-aware adaptive tile algorithm, which tiles input matrices into some small blocks. This stage plays the role of runtime tuning by tiling matrix during program execution. Our performance evaluation shows that IAAT can achieve near-optimal performance when the size of input matrices is small as shown in Section \\ref{sec:performance}.\n\nOur contributions are summarized as follows:\n\\begin{itemize}\n \\item We propose a template-based high-performance code auto-generation method to generate high-performance kernels for GEMM of different sizes in assembly language.\n \\item We design an input-aware adaptive algorithm to divide input matrices into blocks in runtime to obtain a near-optimal solution. \n \\item We implement a high-performance input-aware adaptive tuning framework(IAAT) for small GEMM based on ARMv8.\n\\end{itemize}\n\nThe remainder of this paper is organized as follows. Section \\ref{sec:relatedwork} presents related works. Section \\ref{sec:framework} provides an overview of the framework. Section \\ref{sec:installtime} and Section \\ref{sec:runtime} introduces the details of two stages of IATT. Section \\ref{sec:performance} presents the experimental results. Finally, Section \\ref{sec:conclusions} concludes the paper.\n\n\\section{Related Works}\n\\label{sec:relatedwork}\nMatrix multiplication has been optimized over years. Researchers utilize different methods and technologies to improve various matrix multiplication, such as tall and skinny matrix multiplication\\cite{chen2019tsm2, rivera2021tsm2x, li2021autotsmm}, batches of matrix multiplication\\cite{abdelfattah2020matrix,abdelfattah2019fast}, parallel matrix multiplication\\cite{kang2020hpmax} and so on. \nFor example, tall and skinny matrix multiplication kernels are optimized by a flexible, configurable mapping scheme and outperform on an NVIDIA Volta GPGPU\\cite{ernst2021performance}.\nLionel Eyraud-Dubois\\cite{eyraud2018using} uses more general allocations to perform matrix multiplication on a heterogeneous node based on task-based runtime systems. \n\nSmall GEMM are becoming more and more important in recent years. The optimization of small GEMM is introduced by many libraries, like LIBXSMM\\cite{libxsmm}, BLIS\\cite{blislib, blis2019}. LIBXSMM uses a code generator that has a built-in architectural model to auto-generate code. And the code runs well without requiring an auto-tuning phase by utilizing just-in-time compilation. BLIS uses the method of optimizing skinny matrix to optimize the small matrix and works well\\cite{blis2019}. \n\nHowever, current methods and implementations of small GEMM cannot achieve near-optimal performance on ARMv8 platform. LIBXSMM and BLIS only focused on x86 CPU. Besides, BLIS tile algorithm cannot improve the performance of small GEMM to optimal performance of small GEMM\\cite{blis2019}. And BLIS only implemented the small GEMM for single-precision and double-precision but not single-precision complex and double-precision complex. Distinguish from LIBXSMM and BLIS, we optimize all types of small GEMM for ARMv8 platform.\n\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=0.45\\textwidth]{fig\/codeframework.pdf}\n\\caption{The overall IAAT}\n\\label{fig:code framework}\n\\end{figure}\n\n\\section{Framework}\n\\label{sec:framework}\nThis section introduces the input-aware adaptive tuning framework(IAAT), as shown in Fig.\\ref{fig:code framework}, with two stages, the install-time stage and the run-time stage to achieve near-optimal performance for small GEMM.\n\n\\subsection{The Install-Time Stage}\n\\label{subsec:framework_installtimestage}\nThe install-time stage auto-generates hundreds of kernels of different sizes. \nPack step of the traditional method of GEMM makes data access continuous. So the traditional method of GEMM only needs one kernel to accomplish computation for different transpositions. After removing pack step, we have to use hundreds of kernels for different matrix sizes, types and transpositions. These kernels need lots of work to write by hand. Therefore, IAAT uses auto-generation to generate high-performance kernels in the install-time stage. This stage automatically tunes kernels based on features of the hardware to achieve optimal performance. The install-time stage utilizes four components to generate kernels:\n\n\\begin{itemize}\n\\item \\textbf{Computational Template Designer} abstracts typical computing patterns of matrix multiplication as templates.\n\\item \\textbf{Kernel Generator} designs a kernel generation algorithm, which utilizes templates from compute template designer to generate basic kernels of different sizes. \n\\item \\textbf{Register Allocator} allocates SIMD registers for kernels based on the size of kernel and SIMD register features.\n\\item \\textbf{Kernel Optimizer} optimizes kernels from kernel generator to approach full potential power of the hardware.\n\\end{itemize}\n\n\\begin{table}[htbp]\n\\caption{ALL GENERATED KERNELS}\n\\footnotesize\n\\begin{center}\n\\setlength\\tabcolsep{4pt}\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\n & \\textbf{NN} & \\textbf{NT} & \\textbf{TN} & \\textbf{TT} \\\\ \\hline\n\\textbf{\\rotatebox[origin=c]{270}{SGEMM}} & \\begin{tabular}[c]{@{}l@{}}16$\\times$\\{1,2,3,4\\}\\\\ 12$\\times$\\{1,2,...,6\\}\\\\ 8$\\times$\\{1,2,...,8\\}\\\\ 4$\\times$\\{1,2,...,13\\}\\\\ 3$\\times$\\{1,2,...,13\\}\\\\ 2$\\times$\\{1,2,...,13\\}\\\\ 1$\\times$\\{1,2,...,13\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}16$\\times$\\{1,2,3,4\\}\\\\ 12$\\times$\\{1,2,...,8\\}\\\\ 8$\\times$\\{1,2,...,8\\}\\\\ 4$\\times$\\{1,2,...,20\\}\\\\ 3$\\times$\\{1,2,...,24\\}\\\\ 2$\\times$\\{1,2,...,28\\}\\\\ 1$\\times$\\{1,2,...,32\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,3,4\\}\\\\ 3$\\times$\\{1,2,3,4,5\\}\\\\ 2$\\times$\\{1,2,...,7\\}\\\\ 1$\\times$\\{1,2,...,10\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}\\{1,2,3,4\\}$\\times$16\\\\ \\{1,2,...,6\\}$\\times$12\\\\ \\{1,2,...,8\\}$\\times$8\\\\ \\{1,2,...,13\\}$\\times$4\\\\ \\{1,2,...,13\\}$\\times$3\\\\ \\{1,2,...,13\\}$\\times$2\\\\ \\{1,2,...,13\\}$\\times$1\\end{tabular} \\\\ \\hline\n\\textbf{\\rotatebox[origin=c]{270}{DGEMM}} & \\begin{tabular}[c]{@{}l@{}}8$\\times$\\{1,2,3,4\\}\\\\ 4$\\times$\\{1,2,...,8\\}\\\\ 3$\\times$\\{1,2,...,8\\}\\\\ 2$\\times$\\{1,2,...,15\\}\\\\ 1$\\times$\\{1,2,...,15\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}8$\\times$\\{1,2,3,4\\}\\\\ 4$\\times$\\{1,2,...,8\\}\\\\ 3$\\times$\\{1,2,...,8\\}\\\\ 2$\\times$\\{1,2,...,20\\}\\\\ 1$\\times$\\{1,2,...,20\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,3,4\\}\\\\ 3$\\times$\\{1,2,3,4,5\\}\\\\ 2$\\times$\\{1,2,...,7\\}\\\\ 1$\\times$\\{1,2,...,10\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}\\{1,2,3,4\\}$\\times$8\\\\ \\{1,2,...,8\\}$\\times$4\\\\ \\{1,2,...,8\\}$\\times$3\\\\ \\{1,2,...,15\\}$\\times$2\\\\ \\{1,2,...,15\\}$\\times$1\\end{tabular} \\\\ \\hline\n\\textbf{\\rotatebox[origin=c]{270}{CGEMM}} & \\begin{tabular}[c]{@{}l@{}}8$\\times$\\{1,2,3,4\\}\\\\ 4$\\times$\\{1,2,...,9\\}\\\\ 3$\\times$\\{1,2,...,9\\}\\\\ 2$\\times$\\{1,2,...,12\\}\\\\ 1$\\times$\\{1,2,...,20\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}8$\\times$\\{1,2,3,4\\}\\\\ 4$\\times$\\{1,2,...,8\\}\\\\ 3$\\times$\\{1,2,...,8\\}\\\\ 2$\\times$\\{1,2,...,12\\}\\\\ 1$\\times$\\{1,2,...,20\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,...,9\\}\\\\ 3$\\times$\\{1,2,...,9\\}\\\\ 2$\\times$\\{1,2,...,12\\}\\\\ 1$\\times$\\{1,2,...,20\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}\\{1,2,3,4\\}$\\times$8\\\\ \\{1,2,...,9\\}$\\times$4\\\\ \\{1,2,...,9\\}$\\times$3\\\\ \\{1,2,...,12\\}$\\times$2\\\\ \\{1,2,...,20\\}$\\times$1\\end{tabular} \\\\ \\hline\n\\textbf{\\rotatebox[origin=c]{270}{ZGEMM}} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,3,4\\}\\\\ 3$\\times$\\{1,2,3,4\\}\\\\ 2$\\times$\\{1,2,...,7\\}\\\\ 1$\\times$\\{1,2,...,10\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,3,4\\}\\\\ 3$\\times$\\{1,2,3,4\\}\\\\ 2$\\times$\\{1,2,...,7\\}\\\\ 1$\\times$\\{1,2,...,10\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}4$\\times$\\{1,2,3,4\\}\\\\ 3$\\times$\\{1,2,3,4\\}\\\\ 2$\\times$\\{1,2,...,7\\}\\\\ 1$\\times$\\{1,2,...,10\\}\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}\\{1,2,3,4\\}$\\times$4\\\\ \\{1,2,3,4\\}$\\times$3\\\\ \\{1,2,...,7\\}$\\times$2\\\\ \\{1,2,...,10\\}$\\times$1\\end{tabular} \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\footnotesize\nWe define the kernel for different matrix types and different transpositions. The SGEMM\/DGEMM\/CGEMM\/ZGEMM represent single-precision matrix multiplication, double-precision matrix multiplication, single-precision complex matrix multiplication, double-precision complex matrix multiplication. Each type has four transpositions, NN, NT, TN, and TT. For example, NT means matrix A is not transposed and matrix B is transposed. We will also use abbreviations like SGEMM\\_TN, which means input matrix type is single and matrix A is transposed and matrix B isn't transposed. We acquiescence the matrix in column-major order.\n\\label{tab:ALL GENERATED KERNELS}\n\\end{table}\n\nTABLE \\ref{tab:ALL GENERATED KERNELS} shows all kernels we defined in this paper, which are completely auto-generated. All these kernels construct basic computation of small GEMM and form a kernel array, which is directly invoked by the run-time stage.\n\n\\subsection{The Run-Time Stage}\nThe run-time stage tiles input matrices A, B, and C into blocks and generates a near-optimal small GEMM kernel executing plan.\nThe costs of boundary processing can be neglected for GEMM. However, for small GEMM, the costs of boundary processing are high and cannot be neglected. To reduce or eliminate boundary processing, an algorithm is required, which can tile input matrices into optimal blocks with less boundary processing. The core of the run-time stage is the input-aware adaptive tile algorithm. This algorithm tiles input matrices into optimal blocks according to the size of kernels from the install-time stage. These blocks are tuned according to input matrix sizes, types and transpositions. Therefore, the run-time stage plays the role of runtime tuning. Then this stage connects the kernel to form a sequence of kernels, which is called the kernel executing plan. Finally, IAAT computes the small GEMM based on this kernel executing plan.\n \n\\section{The Install-Time Stage}\n\\label{sec:installtime}\nThis section focuses on the install-time stage, which auto-generates hundreds of kernels of different sizes. Below we introduce four components of the install-time stage as shown in Fig.\\ref{fig:code framework}.\n\n\\subsection{Computational Template Designer}\nTo construct main calculation of GEMM kernel, we introduce computational template designer. The computational template designer extracts typical computing patterns of matrix multiplication as templates, which are shown in TABLE \\ref{tab:The Kernel Computational Templates}.\n\\begin{itemize}\n\\item \\textbf{sfmlas} and \\textbf{dfmlas} represent a vector-scalar multiply-add operation.\n\\item \\textbf{sfmlav} and \\textbf{dfmlav} represent a vector-vector multiply-add operation.\n\\item \\textbf{sfmlss} and \\textbf{dfmlss} represent a vector-scalar multiplication and subtraction.\n\\item \\textbf{sfnegv} and \\textbf{dfnegv} are used to invert values in register.\n\\item \\textbf{sfcmlas} and \\textbf{dfcmlas} represent a vector-scalar complex multiply-add operation.\n\\item \\textbf{sfcmlav} and \\textbf{dfcmlav} represent a vector-vector complex multiply-add operation.\n\\end{itemize}\n\n\\begin{table}[htbp]\n\\caption{Kernel Computational Templates}\n\\scriptsize\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfmlas}(out, in1, in2, index):\\\\\\ \nfmla out.4s, in1.4s, in2.s{[}index{]} \n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfmlas}(out, in1, in2, index):\\\\\\ \nfmla out.2d, in1.2d, in2.d{[}index{]}\n\\end{tabular} \\\\ \\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfmlav}(out, in1, in2):\\\\\\ \nfmla out.4s, in1.4s, in2.4s\n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfmlav}(out, in1, in2):\\\\\\ \nfmls out.2d, in1.2d, in2.2d\n\\end{tabular} \\\\ \\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfmlss}(out, in1, in2, index):\\\\\\ \nfmls out.4s, in1.4s, in2.s{[}index{]}\n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfmlss}(out, in1, in2, index):\\\\\\ \nfmla out.2d, in1.2d, in2.d{[}index{]}\n\\end{tabular} \\\\ \\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfnegv}(out, in1):\\\\\\ \nfneg out.4s, in1.4s\n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfnegv}(out, in1):\\\\\\ \nfneg out.2d, in1.2d\n\\end{tabular} \\\\ \\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfcmlas}(out, in1, in2, index, rot[2]):\\\\\\ \nfcmla out.4s, in1.4s, in2.s{[}index{]}, rot[0] \\\\\\ \nfcmla out.4s, in1.4s, in2.s{[}index{]}, rot[1]\n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfcmlas}(out, in1, in2, rot[2]):\\\\\\ \nfcmla out.2d, in1.2d, in2.2d, rot[0] \\\\\\ \nfcmla out.2d, in1.2d, in2.2d, rot[1]\n\\end{tabular} \\\\ \\hline\n\\begin{tabular}[c]{@{}l@{}}\\textbf{sfcmlav}(out, in1, in2, rot[2]):\\\\\\ \nfcmla out.4s, in1.4s, in2.4s, rot[0] \\\\\\ \nfcmla out.4s, in1.4s, in2.4s, rot[1]\n\\end{tabular} & \n\\begin{tabular}[c]{@{}l@{}}\\textbf{dfcmlav}(out, in1, in2, rot[2]):\\\\\\ \nfcmla out.2d, in1.2d, in2.2d, rot[0] \\\\\\ \nfcmla out.2d, in1.2d, in2.2d, rot[1]\n\\end{tabular} \\\\ \\hline\n\\end{tabular}\n\\label{tab:The Kernel Computational Templates}\n\\end{center}\n\\end{table}\n\n\\subsection{Kernel Generator}\n\\label{subsec:kernel generator}\nKernel generator is responsible for generating kernels. These kernels are used to compute $C_c=A_c\\times B_c+Cc$. Here $A_c$, $B_c$, and $C_c$ are blocks of input matrices A, B, and C. And they are $m_c \\times k_c$, $k_c \\times n_c$, and $m_c \\times n_c$ matrices, respectively. The algorithm of kernel generator takes size of $C_c$ as input and outputs high-performance kernel in assembly language.\n\nKernel generator generates two kinds of subkernels for ping-pang operation. The ping-pang operation is an optimization method that split the multiplication into two stages, M1 and M2 stages. There are two types of ping-pang operations. In the first type, each stage of ping-pang operation multiplies a column of block $A_c$ and a row of block $B_c$ and loads the next column of block $A_c$ and next row of block $B_c$. In the second type, each stage multiplies a column of block $A_c$ and a row of block $B_c$, M1 stage loads the next column of block $A_c$ and two rows of block $B_c$, and M2 stage loads the next column of block $A_c$. And the performance difference between these two types is not too much.\n\nThe kernel generator algorithms for various input matrix types and transpositions are similar. We only discuss SGEMM\\_NN kernel generator shown in Algorithm \\ref{alg:kernel generation of SGEMMNN}.\n\nSGEMM\\_NN kernel generator generates two subkernels in lines 6-12 and 14-19. The first subkernel loads a column of $A_c$ and two rows of $B_c$ in lines 6-7 and the second subkernel loads a column of $A_c$ in line 14. Each subkernel multiplies a column of $A_c$ and a row of $B_c$ by utilizing \\textbf{sfmlas} in lines 8-12 and 15-19.\n\nAfter two kinds of subkernels of SGEMM\\_NN are generated, the kernel generator invokes these two subkernels in a loop on the $k_c$ dimension and completes the generation of SGEMM\\_NN kernel.\n\n\\begin{algorithm}[h]\n\\caption{kernel generator of SGEMM\\_NN}\n\\label{alg:kernel generation of SGEMMNN}\n\\begin{algorithmic}[1]\n\t \\REQUIRE $m_c$, $n_c$: the size of the input kernel\n\t \\ENSURE $kernel$\n\t \\STATE $Cregs \\gets \\{C_1, C_2,..., C_{m_{\\left \\lceil m_c\/4 \\right \\rceil}n_c}\\}$\n\t \\STATE $A1regs \\gets \\{A_1, A_2,..., A_{\\left \\lceil m_c\/4 \\right \\rceil}\\}$\n\t \\STATE $A2regs \\gets \\{A_{\\left \\lceil m_c\/4 \\right \\rceil+1},$ $A_{\\left \\lceil m_c\/4 \\right \\rceil+2},$ $...,$ $A_{2\\left \\lceil m_c\/4 \\right \\rceil}\\}$\n\t \\STATE $Bregs \\gets \\{B_1, B_2,..., B_{n_c}\\}$\n\t \\STATE \/\/first subkernel\n\t \\STATE load next column of block $A_c$ to $A2regs$\n\t \\STATE load two rows of block $B_c$ to $Bregs$\n\t \\FOR{$i$ $\\gets$ $0$ $to$ $n_c$}\n\t \\FOR{$j$ $\\gets$ $0$ $to$ $\\left \\lceil m_c\/4 \\right \\rceil$}\n\t \\STATE \\textbf{sfmlas}($Cregs{[}i\\left \\lceil m_c\/4 \\right \\rceil+j{]}$, $A1regs{[}j{]}$, $Bregs{[}i{]}$, 0)\n\t \\ENDFOR\n\t \\ENDFOR\n\t \\STATE \/\/second subkernel\n\t \\STATE load next column of block $A_c$ to $A1regs$\n\t \\FOR{$i$ $\\gets$ $0$ $to$ $n_c$}\n\t \\FOR{$j$ $\\gets$ $0$ $to$ $\\left \\lceil m_c\/4 \\right \\rceil$}\n\t \\STATE \\textbf{sfmlas}($Cregs{[}i\\left \\lceil m_c\/4 \\right \\rceil+j{]}$, $A2regs{[}j{]}$, $Bregs{[}i{]}$, 1)\n\t \\ENDFOR\n\t \\ENDFOR\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Register Allocator}\n\\label{subsec:register allocator}\nThe allocation of registers is very important for the performance of small GEMM. Hence, we need to define the strategies of register allocation for different kernels. The work of our paper is mainly carried out on ARMv8 platform, which contains 32 128-bit SIMD registers.\n\nThe basic idea behind the register allocator is to divide all registers into three groups. $A_c$ register group contains two columns of $A_c$; $B_c$ register group contains two rows of $B_c$ for ping-pang operation; $C_c$ register group holds the whole block $C_c$.\n\nAllocation of the $A_c$ register group has four main strategies, ANTwoCC, ATEachCTwo, ATEachCOne, and ATTwoRR. \n\\begin{itemize}\n \\item \\textbf{ANTwoCC} is for loading two columns of $A_c$ to registers. It allocates $2\\left \\lceil m_c\/elenum \\right \\rceil$ registers, the $elenum$ means the number of elements that a register can store.\n \\item \\textbf{ATEachCTwo} is for loading first two data of each column of transposed $A_c$ to two registers. It allocates a total of $2m_c$ registers.\n \\item \\textbf{ATEachCOne} is for loading first two data of each column of transposed $A_c$ to one register. It requires a total of $m_c$ registers for single-precision, double-precision, and single-precision complex. As for double-precision complex, it requires a total of $2m_c$ registers. \n \\item \\textbf{ATTwoRR} is for loading two rows of transposed $A_c$ to registers. It allocates $2\\left \\lceil m_c\/elenum \\right \\rceil$ registers.\n\\end{itemize}\n\nThe strategies of allocating $B_c$ register group are BTTwoCC, BNEachCTwo, BNEachCOne, and BNTwoRR corresponding to ANTwoCC, ATEachCTwo, ATEachCOne, and ATTwoRR. This is because load methods of $A_c$ are the same as load methods of $B_c$.\n\nThe strategy of allocating the C register group is allocating $\\left \\lceil m_c\\times n_c\/elenum \\right \\rceil$ registers.\n\nThe register allocator has one special strategy for TN transposition that allocates $2m_c$ registers for $A_c$ and $2n_c$ registers for $B_c$. This transposition makes memory access to $A_c$ and $B_c$ discontinuous. So we cannot vectorize small GEMM for this transposition. Therefore, the methods of loading data are load data from each column of $A_c$ by columns and load data from each column of $B_c$ by columns.\n\n\\subsection{Kernel Optimizer}\nAfter kernels are generated, kernels will be optimized as follows.\n\n\\paragraph{Instruction Choice} Computational template designer utilizes the FMA instruction instead of $mul$ or $add$ because there usually are fused multiply-add(FMA) units in hardware. Besides, we prioritize the $ldp$ and $ldr$ instructions because these two instructions are relatively high-performance.\n\n\\paragraph{Instruction Order} The loading instructions are interspersed among the computing instructions. It makes better use of the instruction pipeline to avoid pipeline stalling.\n\n\\paragraph{Ping-Pang Operation} As described in Subsection \\ref{subsec:kernel generator}, this optimization utilizes computing instruction to hide the delay of loading instructions.\n\n\\section{The Run-Time Stage}\n\\label{sec:runtime}\nThis section introduces the run-time stage. This stage first tile input matrices and then construct a kernel executing plan to compute small GEMM. The input-aware adaptive tile algorithm is the core of this stage.\n\n\\subsection{Input-Aware Adaptive Tile Algorithm}\nThe input-aware adaptive tile algorithm first tiles input matrix C into some small blocks. Each block has the same size as one of the generated kernels. Then, this algorithm tiles matrices A and B based on tiled blocks of C. This algorithm is based on the three principles listed below.\n\n\\begin{algorithm}[h]\n\t\\caption{SGEMM\\_NN Tile Algorithm}\n\t\\label{alg:SGEMMNNtileAlg}\n\t\\footnotesize\n\t\\begin{algorithmic}[1]\n\t \\REQUIRE $M,N,K$: the sizes of input matrices, $kernels$: array of all sorted SGEMM\\_NN kernels from TABLE \\ref{tab:ALL GENERATED KERNELS}\n\t \\ENSURE $blocksC$[], $blocksA$[], $blocksB$[]\n\t \\IF {$N \\le 13$}\n\t \\STATE $m[] \\gets (m_1, I)$, $m_1$ is the largest $m_c$ of kernel that's $n_c$ is equal $N$ and $I$ is an integer and make sure the $m_1I \\le M$\n\t \\STATE $n[] \\gets [(N, 1)]$\n \\IF{$m_1I < M$}\n \\STATE $m$.append($(M-m_1I, 1)$)\n \\STATE $n$.append($[(N, 1)]$)\n \\ENDIF\n \\ELSE\n \\IF{$M < 8$}\n \\STATE $m[] \\gets TileSingleDim(M, [1,2,3,4])$\n \\STATE $n[] \\gets [TileSingleDim(N, [1,2,...,13])]$\n \\IF{size of $m$ == 2}\n \\STATE $n.append([TileSingleDim(N, [1,2,...,13])])$\n \\ENDIF\n \\ELSIF{$M == 9$}\n \\STATE $m[] \\gets (4, 1), (3, 1), (2, 1)$\n \\STATE $n[] \\gets [TileSingleDim(N, [1,2,...,13])],$ $[TileSingleDim$ $(N,$ $[1,2,...,13])],$ $[TileSingleDim(N,$ $ [1,2,...,13])]$\n \\ELSIF{$M < 12$}\n \\STATE $m[] \\gets (8, 1), (M - 8, 1)$\n \\STATE $n[] \\gets [TileSingleDim(N,[1,2,...,8])],$ $[TileSingleDim$ $(N,$ $[1,2,...,13])]$\n \\ELSIF{$M == 12$}\n \\STATE $m[] \\gets (12, 1)$\n \\STATE $n[] \\gets [TileSingleDim(N, [1,2,3,4,5,6])]$\n \\ELSE\n \\STATE $m_1[] \\gets (4, \\lfloor M\/4 \\rfloor)$\n \\STATE $m_2[] \\gets (M-4\\lfloor M\/4 \\rfloor, 1)$\n \\STATE $n_2[] \\gets [TileSingleDim(N, [1,2,...,13])]$\n \\IF{$M-4\\lfloor M\/4 \\rfloor == 1$}\n \\STATE $m_1[] \\gets (4, \\lfloor M\/4 \\rfloor-1)$\n \\STATE $m_2[] \\gets (3, 1), (2, 1)$\n \\STATE $n_2[] \\gets$ $[TileSingleDim(N,$ $[1,2,...,8])],$ $[TileSingleDim$ $(N,$ $[1,2,...,13])]$\n \\ENDIF\n \\STATE $m8\\gets ExtendTo8(m_1)$\n \\STATE $m16\\gets ExtendTo16(m_1)$\n \\STATE $n8[]$ and $n16[]$ $\\gets$ tile $N$ by $m8[]$ and $m16[]$\n \\STATE $blocksC1\\gets Combine(m8, n8)$\n \\STATE $blocksC2\\gets Combine(m16, n16)$\n \\STATE $blocksC\\gets CompareLessMemops(blocksC1, blocksC2)$\n \\STATE $blocksC$.append(combine($m_2$, $n_2$))\n \\STATE return\n \\ENDIF\n\t \\ENDIF\n\t \\STATE $blocksC \\gets Combine(m, n)$\n\t \\STATE $blocksA[] \\gets$ tile matrix A according to $blocksC[]$\n\t \\STATE $blocksB[] \\gets$ tile matrix B according to $blocksC[]$\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\paragraph{Bigger Block Size} Smaller blocks cause matrices A and B to be repeatedly loaded more times. The larger the block size, the lower the number of repetitions.\n\n\\paragraph{Minimal Memops} Different tiling methods have the same amount of computing instructions but different numbers of loading instructions. Therefore, the optimal tiling method is tiling matrices into blocks with the fewest loading instructions. The tiled blocks for matrix C are supposed to be $m_0 \\times n_0$, $m_1 \\times n_1$, ..., $m_i \\times n_i$. The $m_i \\times n_i$ is size of tiled block. This tiling method have a total of $(m_0+n_0+m_1+n_1...+m_a+n_a)K+2mn$ data to access from L2 cache to register. So the value of $(m_0+n_0+m_1+n_1...+m_a+n_a)$ should be preserved to a bare minimum.\n\n\\paragraph{SIMD Friendly} The dimension of block, that data is continuous, can be divisible by the length of SIMD register.\n\nThe pseudo-code of SGEMM\\_NN tile algorithm are shown in Algorithm \\ref{alg:SGEMMNNtileAlg}. The outline of this algorithm is below:\n\nWhen $N \\le 13$, we let $n_c=N$ and make $m_c$ the maximum value that $m_c$ can be taken in lines 1-7. When $N > 13$, we first tile $M$ into multiples of 4 and use 1, 2, 3 to supplement the deficiency, and\nthen tile $N$ into maximum value that $n_c$ can be taken according to the result of $M$'s tile in lines 9-42. Besides, when $M > 12$, $M$ can be tiled by 8 or 16 and we compare which one is better by counting the number of loading instructions and choose that. Then, we combine the two tiled dimensions $m[]$ and $n[]$ into $blocksC$. Finally, we tile matrices A and B into $blocksA$ and $blocksB$ according to blocks of matrix C.\n\n$TileSingleDim$ algorithm, as shown in line 10, is for tiling a single dimension. It takes two input parameters: the length that you want to tile, and the array of lengths that you used to tile. This algorithm outputs array $(dim, nums)$ means $dim$ is repeated $nums$ times. We tile $dim$ into $nums_1I+nums_2...+nums_i$ and the bigger $nums_1$, the better. And if $nums_i$ is too small, this algorithm will average $nums_{i-1}$ and $nums_i$.\n\nFor various types and transpositions, the specific tile algorithm is changed slightly. But the basic ideas are consistent as shown above.\n\n\\begin{figure}[htbp]\n\\centering\n\\subfigure[traditional tiling method]{\n\\includegraphics{fig\/traditionalkernelallocationsamplegraph.pdf}\n\\label{fig:fig1}\n}\n\\quad\n\\subfigure[new tiling method]{\n\\includegraphics{fig\/newkernelallocationsamplegraph.pdf}\n\\label{fig:fig2}\n}\n\\caption{Schematic sketch of tiling method for a $15 \\times 15$ SGEMMNN matrix}\n\\end{figure}\n\nFor SGEMM\\_NN $15\\times 15\\times K$ matrix, the traditional tiling method is showed in Figure \\ref{fig:fig1}. This method needs to load $105k+450$ data from L2 cache to register. And, our method tile SGEMM\\_NN is showed in Figure \\ref{fig:fig2}. This tiling method needs to load $72K+450$ data. The amount of data loaded by the traditional method is 45\\% more than that of our method.\n\n\\subsection{Kernel Executing Plan}\nAfter input matrices are tiled, IAAT constructs a kernel executing plan by connecting kernels, which correspond to the sizes of tiled blocks. Finally, IAAT executes this plan to compute small GEMM.\n\n\\section{Performance Evaluation}\n\\label{sec:performance}\nIn this section, we analyze small GEMM's performance on ARMv8 platform as listed in TABLE \\ref{tab:Experimental Environment Of ARMv8 platform}. We compared IAAT with currently state-of-the-art BLAS libraries: OpenBLAS, ARMPL, and BLIS. GEMM in these libraries is well optimized. Our work supports four data types: single-precision, double-precision, single-precision complex, and double-precision complex. Each data type supports four transpositions: NN, NT, TN, TT. Thus, we compared 16 kinds of small GEMMs. We use Equation \\ref{equ:sd} to evaluate performance of SGEMM and DGEMM and Equation \\ref{equ:cz} to evaluate performance of CGEMM and ZGEMM.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{Experimental Environment Of ARMv8 platform}\n\\renewcommand{\\arraystretch}{1.2}\n\\setlength{\\tabcolsep}{10pt}\n\\begin{tabular}{lcc}\n\\hline\n\\multicolumn{1}{l}{Hardware} & CPU & Kunpeng920 \\\\\n\\hline\n&Arch. & ARMv8.2 \\\\\n&Freq. & 2.6GHz \\\\\n&SIMD & 128bits \\\\\n&L1 cache & 4MiB \\\\\n&L2 cache & 32MiB \\\\\n\\hline\n\\multicolumn{1}{l}{Software} &Compiler & GCC7.5 \\\\\n&OpenBLAS & 0.3.13 \\\\\n&ARMPL & 21.0 \\\\\n&BLIS & 0.81 \\\\\n\\hline\n\\end{tabular}\n\\label{tab:Experimental Environment Of ARMv8 platform}\n\\end{table}\n\n\\begin{eqnarray}\nGFLOPS&=&\\frac{2\\times M \\times N\\times K}{t} \\label{equ:sd}\\\\\nGFLOPS&=&\\frac{2\\times 4 \\times M \\times N\\times K}{t} \\label{equ:cz}\n\\end{eqnarray}\n\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=3.4in]{perf\/pack.pdf}\n\\caption{Pack step cost proportion}\n\\label{fig:pack}\n\\end{figure}\n\nFig.\\ref{fig:pack} shows proportion of pack step cost in traditional implementation of GEMM. It shows that the proportion of pack step cost can reach 67\\% when input matrices are very small. As the size of input matrices increases, the proportion decreases exponentially. When input matrices are large enough, the proportion is near 3\\%.\n\n\\begin{figure*}[htbp]\n\\centering\n\\subfigure[NN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmsnn.pdf}\n\\end{minipage}\n\\label{fig:snn}\n}\n\\hspace{-0.5cm}\n\\subfigure[NT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmsnt.pdf}\n\\end{minipage}\n\\label{fig:snt}\n}\n\\hspace{-0.5cm}\n\\subfigure[TN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmstn.pdf}\n\\end{minipage}\n\\label{fig:stn}\n}\n\\hspace{-0.5cm}\n\\subfigure[TT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmstt.pdf}\n\\end{minipage}\n\\label{fig:stt}\n}\n\\centering\n\\caption{Performance evaluation of IAAT vs. OpenBLAS, BLIS, ARMPL for SGEMM}\n\\label{fig:sgemm}\n\\end{figure*}\n\n\\begin{figure*}[htbp]\n\\centering\n\\subfigure[NN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmdnn.pdf}\n\\end{minipage}\n\\label{fig:dnn}\n}\n\\hspace{-0.5cm}\n\\subfigure[NT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmdnt.pdf}\n\\end{minipage}\n\\label{fig:dnt}\n}\n\\hspace{-0.5cm}\n\\subfigure[TN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmdtn.pdf}\n\\end{minipage}\n\\label{fig:dtn}\n}\n\\hspace{-0.5cm}\n\\subfigure[TT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmdtt.pdf}\n\\end{minipage}\n\\label{fig:dtt}\n}\n\\centering\n\\caption{Performance evaluation of IAAT vs. OpenBLAS, BLIS, ARMPL for DGEMM}\n\\label{fig:dgemm}\n\\end{figure*}\n\n\\begin{figure*}[htbp]\n\\centering\n\\subfigure[NN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmcnn.pdf}\n\\end{minipage}\n\\label{fig:cnn}\n}\n\\hspace{-0.5cm}\n\\subfigure[NT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmcnt.pdf}\n\\end{minipage}\n\\label{fig:cnt}\n}\n\\hspace{-0.5cm}\n\\subfigure[TN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmctn.pdf}\n\\end{minipage}\n\\label{fig:ctn}\n}\n\\hspace{-0.5cm}\n\\subfigure[TT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmctt.pdf}\n\\end{minipage}\n\\label{fig:ctt}\n}\n\\centering\n\\caption{Performance evaluation of IAAT vs. OpenBLAS, BLIS, ARMPL for CGEMM}\n\\label{fig:cgemm}\n\\end{figure*}\n\n\\begin{figure*}[htbp]\n\\centering\n\\subfigure[NN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmznn.pdf}\n\\end{minipage}\n\\label{fig:znn}\n}\n\\hspace{-0.5cm}\n\\subfigure[NT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmznt.pdf}\n\\end{minipage}\n\\label{fig:znt}\n}\n\\hspace{-0.5cm}\n\\subfigure[TN]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmztn.pdf}\n\\end{minipage}\n\\label{fig:ztn}\n}\n\\hspace{-0.5cm}\n\\subfigure[TT]{\n\\begin{minipage}[t]{0.23\\linewidth}\n\\centering\n\\includegraphics[width=4.1cm]{perf\/gemmztt.pdf}\n\\end{minipage}\n\\label{fig:ztt}\n}\n\\centering\n\\caption{Performance evaluation of IAAT vs. OpenBLAS, BLIS, ARMPL for ZGEMM}\n\\label{fig:zgemm}\n\\end{figure*}\n\nFig.\\ref{fig:sgemm} shows performances of NN, NT, TN, TT of SGEMM of IAAT, OpenBLAS, ARMPL, and BLIS. When input matrices are small, IAAT is faster than OpenBLAS, ARMPL, and BLIS for all transpositions. When $M=N=K\\le 80$ and transposition is NN, as shown in Fig.\\ref{fig:snn}, IAAT is on average 1.81, 2.3, and 20.17 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is NT, as shown in Fig.\\ref{fig:snt}, IAAT is on average 1.81, 2.29, and 20.19 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 32$ and transposition is TN, as shown in Fig.\\ref{fig:stn}, IAAT is on average 1.65 times faster than OpenBLAS. When $M=N=K>32$ and transposition is TN, as shown in Fig.\\ref{fig:stn}, IAAT is only faster than OpenBLAS when sizes of input matrices are multiples of 4. However, when $M=N=K\\le 100$ and transposition is TN, IAAT is faster than ARMPL and BLIS and is on average 2.15 and 11.57 times, respectively. \nWhen $M=N=K\\le 80$ and transposition is TT, as shown in Fig.\\ref{fig:stt}, IAAT is on average 1.73, 2.55, and 18.76 times faster than OpenBLAS, ARMPL, and BLIS, respectively.\n\nFig.\\ref{fig:dgemm} shows performances of NN, NT, TN, TT of DGEMM of IAAT, OpenBLAS, ARMPL, and BLIS. When input matrices are small, IAAT is faster than OpenBLAS, ARMPL, and BLIS for all transpositions. When $M=N=K\\le 80$ and transposition is NN, as shown in Fig.\\ref{fig:dnn}, IAAT is on average 1.48, 1.66, and 15.0 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is NT, as shown in Fig.\\ref{fig:dnt}, IAAT is on average 1.43, 1.66, and 14.56 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is TN, as shown in Fig.\\ref{fig:dtn}, IAAT is on average 1.32, 1.47, and 12.78 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is TT, as shown in Fig.\\ref{fig:dtt}, IAAT is on average 1.43, 1.64, and 14.54 times faster than OpenBLAS, ARMPL, and BLIS, respectively.\n\nFig.\\ref{fig:cgemm} shows performances of NN, NT, TN, TT of CGEMM of IAAT, OpenBLAS, ARMPL, and BLIS. When input matrices are small, IAAT is faster than OpenBLAS, ARMPL, and BLIS for all transpositions. When $M=N=K\\le 80$ and transposition is NN, as shown in Fig.\\ref{fig:cnn}, IAAT is on average 1.31, 1.30, and 13.24 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is NT, as shown in Fig.\\ref{fig:cnt}, IAAT is on average 1.37, 1.44, and 13.55 times faster than OpenBLAS, ARMPL, and BLIS, respectively. \nWhen $M=N=K\\le 64$ and transposition is TN, as shown in Fig.\\ref{fig:ctn}, IAAT is on average 1.16, 1.33, and 13.68 times faster than OpenBLAS, ARMPL, and BLIS, respectively. \nWhen $M=N=K\\le 80$ and transposition is TT, as shown in Fig.\\ref{fig:ctt}, IAAT is on average 1.27, 1.46, and 12.94 times faster than OpenBLAS, ARMPL, and BLIS, respectively.\n\nFig.\\ref{fig:zgemm} shows performances of NN, NT, TN, TT of ZGEMM of IAAT, OpenBLAS, ARMPL, and BLIS. When input matrices are small, IAAT is faster than OpenBLAS, ARMPL, and BLIS for all transpositions. When $M=N=K\\le 80$ and transposition is NN, as shown in Fig.\\ref{fig:znn}, IAAT is on average 1.09, 1.3, and 9.62 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is NT, as shown in Fig.\\ref{fig:znt}, IAAT is on average 1.09, 1.32, and 9.6 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is TN, as shown in Fig.\\ref{fig:ztn}, IAAT is on average 1.11, 1.32, and 9.69 times faster than OpenBLAS, ARMPL, and BLIS, respectively. When $M=N=K\\le 80$ and transposition is TT, as shown in Fig.\\ref{fig:ztt}, IAAT is on average 1.1, 1.34, and 9.6 times faster than OpenBLAS, ARMPL, and BLIS, respectively.\nei\nIn addition to the above performance description, we still observe the following three phenomena.\n\nFirstly, as shown in all Fig. \\ref{fig:sgemm}, \\ref{fig:dgemm}, \\ref{fig:cgemm}, and \\ref{fig:zgemm}, all performance curves of IAAT are very steep When input matrices are small and tend to be smooth along with increase of size. All performance curves of IAAT relate to the proportion of pack step, as shown in Fig.\\ref{fig:pack}. As mentioned in Section \\ref{sec:introduction}, performance improvement of small GEMM comes from removing pack steps. The greater proportion of pack step cost, the higher performance improvement. For example, when $M=N=K\\le 64$, the proportion of pack step of SGEMM\\_NN drops, when $M=N=K>64$, the curve of proportion is smooth. The corresponding performance curve of SGEMM\\_NN, as shown in \\ref{fig:snn}, rises when $M=N=K\\le 64$ and stops rising when $M=N=K>64$. The others curve are the same as the curve of SGEMM\\_NN.\n\nSecondly, performance of TN transposition is not as good as other transpositions as shown in Fig.\\ref{fig:sgemm}, \\ref{fig:dgemm}, \\ref{fig:cgemm} and \\ref{fig:zgemm}. Because data is not continuous and vectorized computation is not feasible in TN transposition, register allocator has to allocate individual registers for each element of block $C_c$. Therefore, blocks of matrix C occupy too many registers, which causes kernel sizes of SGEMM\\_TN smaller than other transpositions. We have to tile input matrices into smaller blocks than other transpositions. The number of loading instructions increases significantly. As the size of input matrices increases, the advantage of small GEMM for TN transposition will vanish.\n\nThirdly, the curves of performance of IAAT, as shown in Fig.\\ref{fig:sgemm}, is wavy. The performance of four transpositions reaches wave crests when the size of input matrices is multiples of 4 and it falls into wave troughs when sizes of input matrices are not multiples of 4. Here are two reasons for this phenomenon. First, Kunpeng920 platform has two fused multiply-add(FMA) units for single but Kunpeng920 cannot fully utilize units. Kunpeng920 can issue two FMA instructions or issue one FMA instruction and one loading instruction at the same time. \nTherefore, for a kernel of any size, the lower the proportion of loading instructions, the closer the performance is to the peak performance.\nWhen the size of the kernel is multiples of 4, the kernel can achieve better performance. When the sizes of input matrices are not multiples of 4, the tile algorithm tiles matrix into blocks, which corresponds to the low performance of kernel. Second, it is because only when the size of input matrices is multiples of 4, small GEMM can make full use of the registers. As one register can store four floats, other sizes of input matrices lead to insufficient register utilization. Therefore, the implementation of small GEMM for input matrices whose size is multiples of 4 has better performance. Similar waves occur in CGEMM as shown in Fig.\\ref{fig:cgemm}, which has the same reasons as SGEMM. Besides, compared with SGEMM and CGEMM, curves of DGEMM and ZGEMM, as shown in Fig.\\ref{fig:dgemm} and Fig.\\ref{fig:zgemm}, are more smooth and the performance curve of DGEMM and ZGEMM reaches wave crest when the size of input matrices is multiples of 2. Because Kunpeng920 platform has one fused multiply-add(FMA) unit for double, which can be fully utilized. Besides, it is also because the size of data type of DGEMM and ZGEMM is bigger than that of SGEMM and CGEMM. DGEMM and ZGEMM can make better use of registers than SGEMM and CGEMM.\n\nConsider the above performance results, we conclude that our implementation is faster than the others library when the size of input matrices is small enough. As shown by above performance analysis, we define small GEMM, as $\\sqrt[3]{MNK}\\le 80$, when transposition of input matrices is not TN, or $\\sqrt[3]{MNK}\\le 32$ when transposition of input matrices is TN as mentioned in Section \\ref{sec:introduction}.\n\n\\section{Conclusions}\n\\label{sec:conclusions}\nIn this paper, we propose the input-aware adaptive tuning framework(IAAT) for small GEMM with two stages: the install-time stage and the run-time stage. The install-time stage auto-generates assembly kernels for ARMv8 platform and the run-time stage tiles input matrices into blocks. Finally, IAAT constructs a kernel executing plan by connecting kernels, which corresponds to the sizes of tiled blocks. As shown in the experiment, IAAT utilizes code generation and adaptive tuning to achieves near-optimal performance for small GEMM. IAAT fits the situation where computes matrix multiplication with the same size repeatedly. Our future work will focus on extending IAAT to other platforms.\n\n\\section*{Acknowledgements}\nWe would like to express our gratitude to all reviewer's constructive comments for helping us polish this article. This work is supported by the National Key Research and Development Program of China under Grant Nos.2017YFB0202105, the National Natural Science Foundation of China under Grant No.61972376 and the Natural Science Foundation of Beijing under Grant No.L182053.\n\n\\bibliographystyle{IEEEtran}\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} {"text":"\\section{Introduction} \\label{sec-intro}\n\nBulk metallic glasses are strongly out-of-equilibrium industrially relevant materials with exceptional physical and mechanical properties~\\cite{Hufnagel2016}. Produced by a rapid quench from the under-cooled liquid, the amorphous state emerges during the glass transition temperature ($T_{\\mathrm{g}}$) regime with an extensive configurational entropy. However, this entropy is considerably lower than that of the liquid indicating strong constraints on the available atomic configurations~\\cite{Debenedetti2001}. Understanding these constraints and how they are overcome is central to a proper control of both structure and mechanical properties --- a parameter space that is explored via structural relaxation and rejuvenation of the glass. Increasingly, such structural tuning is assessed via the excess enthalpy storage of the glass, which is amongst the highest of any metallic material~\\cite{Sun2016,Kuechemann2017,Kuechemann2018,Ding2019}.\n\nTwo structural asymptotes have remained omnipresent in both the experimental and theoretical efforts to understand glass tunability. The first is crystallization due to annealing protocols close to $T_{\\mathrm{g}}$, and the second is relaxation towards the ideal glass state, characterized by a sub-extensive configurational entropy~\\cite{Kauzmann1948}. Generally these are considered to be quite different and unrelated structural states. Due to undesirable mechanical properties and experimental difficulties, as-produced glasses tend to be away from the latter extreme, whereas metallic-glass matrix composites (multi-phase structures containing crystalline and possibly amorphous regions) embrace the former. On the other hand, approaching the ideal glass limit, the low temperature limit of the undercooled liquid, poses interesting theoretical questions as first pointed out by Kauzmann~\\cite{Kauzmann1948} and also the alluring possibility of a glass structure which is in a true meta-equilibrium state.\n\nOnce a glassy structure is obtained after quenching a melt, there will be a natural tendency for the amorphous solid to relax. The resulting structural evolution is seen in small changes in the pair distribution function (PDF) at radial distances beyond the nearest neighbour peak(s) that characterize the short-range order (SRO). The more distant order has been referred to as medium-range order (MRO). A common framework to understand the developing MRO is with respect to the packing of SRO icosahedral content~\\cite{Sheng2006}. An atom is said to be icosahedrally coordinated if its nearest neighbour spatial environment can be characterized by a Wigner-Seitz or Voronoi generated twelve faced polyhedron where each face consists of three edges --- the icosahedron. This originates from the more fundamental unit structure of the tetrahedron~\\cite{Chaudhari1978}. When isolated, this atomic arrangement can usually minimize the energy of all six bonds. However it is not possible to pack such tetrahedra in a space-filling way whilst maintaining this minimum ground-state energy and therefore bonds become frustrated, both in terms of energy and volume. Optimal space-filling packing of icosahedra at the length-scale of the MRO (and beyond) is a difficult problem involving defected icosahedra and more general Voronoi polytopes~\\cite{Frank1952,Nelson1983a,Nelson1983b}, underlying the very close connection between local structure, bond energy and atomic volume~\\cite{Ding2017}.\n\nThe relationship between dynamical heterogeneities and structure in the under-cooled liquid-metal regime gives additional insight into the nature of this structural relaxation. In particular the connection to amorphous disorder, which is normally considered to have little in common with those local structures ultimately giving rise to crystalline order~\\cite{Charbonneau2016}. This aspect may be articulated as the competition of local structures characterized by five- (icosahedral) and six-fold bond symmetries (close-packed)~\\cite{Taffs2016}. Common equilibrium crystal structures are close-packed and therefore dominated by six-fold bond-order. However there do exist a class of crystal structures for which the five-fold bond symmetry dominates. These are the so-called topologically close packed phases discovered by Frank and Kasper~\\cite{Frank1958}. For binary systems common realizations are the cubic (C15), the two hexagonal (C14 and C36) laves structures, and the A15 structure. Atomistic simulations of model binary glasses have revealed connected fragments of the Laves C15 structure for both Lennard-Jones (LJ) force models~\\cite{Pedersen2010} (using the Wahnstr{\\o}m parameterization~\\cite{Wahnstrom1991}), and material specific force models for the experimentally realizable CuZr binary alloy~\\cite{Zemp2014,Zemp2016,Ryltsev2016}. Experimental evidence for such local icosahedral structures mainly relies on a combination of x-ray diffraction and the reverse Monte-Carlo method. For the CuZr alloy, for a range of concentration, this method suggests extended structures of connected icosahedral units~\\cite{Wang2008} possibly inter-dispersed amongst liquid-like structures~\\cite{Li2009}. For the case of the Cu$_{50}$Zr$_{45}$Al$_{5}$ ternary alloy, reverse Monte Carlo simulations in combination with fluctuation electron microscopy suggested the existence of a population of both icosahedral and crystal-like (six-fold bonded) atomic structures~\\cite{Hwang2012}. The LJ work of Pedersen {\\em et al}~\\cite{Pedersen2010} found that such Laves fragments took the form of two dimensional ring-structures referred to as Frank-Kasper backbone polyhedrons. Earlier work also showed that at sufficiently high temperatures, within the undercooled liquid regime, the Wahstr{\\o}m LJ potential can also crystallize into the C15 Laves phase~\\cite{Pedersen2006}.\n\nPast MD works probing the nano-second timescale~\\cite{Ding2014,Derlet2017,Derlet2017a,Derlet2018}, have shown that below $T_{\\mathrm{g}}$, the cohesive energy decreases with respect to increasing icosahedral content. Indeed, Ref.~\\cite{Derlet2018}, which considers the model Wahnstr{\\o}m LJ binary glass, has demonstrated that glass relaxation in terms of both energy and pressure\/volume originates directly from the conversion of non-icosahedral environments to icosahedral environments, via structural excitations characterized by thermally activated collective string-like atomic displacements~\\cite{Derlet2017,Derlet2017a}. Such a geometry of structural evolution has also been observed in the dynamical heterogeneities of the under-cooled liquid~\\cite{Donati1998,Schroeder2000,Gebremichael2004,Vogel2004,Kawasaki2013}.\n\nIn the present work we employ atomistic simulation to investigate the non-negligible structural relaxation in a model binary glass which occurs at time-scales up to approximately $80$ $\\mu$sec. We show that that the linear relation between icosahedral content and energy remains valid over this time-scale and therefore to glassy structures significantly more relaxed than previously considered. We find that this very general relaxation trajectory can lead to emergent structural length-scales reflecting both the nano-composite and ideal-glass structural asymptotes, suggesting that the ideal glass and crystallization might be intimately related if not associated with the same structural state. We argue that this perspective offers a new approach to structural tuning of nano composite (nc) amorphous-crystalline microstructures, which we here reveal for binary metallic glass formers. In sec.~\\ref{sec-simulation} we outline our simulation approach, in sec.~\\ref{sec-results} we detail the major simulation results, and in sec.~\\ref{sec-discussion} we discuss them within the framework of temperature-time-transition (TTT) diagrams that are now accessible within the time-frame of an atomistic simulation. Finally, we formulate a number of open questions resulting from this work and in sec.~\\ref{sec-conc} we summarize and conclude.\n\n\\section{Simulation Methodology} \\label{sec-simulation}\n\nAs already noted, the physics of structural frustration can be captured by simple pair potential force models such as the Lennard-Jones (LJ) potential~\\cite{Rodney2011}, whereas for metal-specific applications embedded atom~\\cite{Daw1984} or second-moment~\\cite{Finnis1985} model potentials may be used. This demonstrates the more involved force models are not essential to understanding the underlying structural glass physics~\\cite{Derlet2017a,Derlet2018} --- glassy physics is a universal phenomenon~\\cite{Debenedetti2001,Kauzmann1948,Goldstein1969} which can be equally well simulated using an appropriate LJ parameterization. Because of this, and due to their more-rapid numerical evaluation, we use a model binary LJ system parameterized by Wahnstr\\\"{o}m~\\cite{Wahnstrom1991} to investigate its microstructural relaxation behaviour at the timescale of many tens of $\\mu$sec. For two atoms of type $a$ and $b$, separated by a distance $r$, the interaction potential energy is given by,\n\\begin{equation}\nV_{ab}(r)=4\\varepsilon\\left(\\left(\\frac{\\sigma_{ab}}{r}\\right)^{12}-\\left(\\frac{\\sigma_{ab}}{r}\\right)^{6}\\right),\n\\end{equation}\nwhere $\\sigma_{22}=5\/6\\sigma_{11}$ and $\\sigma_{12}=\\sigma_{21}=11\/12\\sigma_{11}$. The atoms of type 1 may be considered as the larger atom type. The atomic masses of the two atom types are arbitrarily chosen such that $m_{1}\/m_{2}=2$. For a molecular dynamics iteration, a time step of $0.002778\\sigma_{11}\\sqrt{m_{1}\/\\varepsilon}$ is used. The distance unit is taken as $\\sigma=\\sigma_{11}$ and the energy unit as $\\varepsilon$. For this work, the potential is truncated to a distance 2.5$\\sigma$. Atoms of type 1 may be considered as the larger atom. All molecular dynamics (MD) simulations are done using the LAMMPS software~\\cite{LAMMPS}, and atomic scale analysis via the OVITO visualization software~\\cite{Stukowski2010}.\n\nWhen metallic units (representative of say, CuZr) are taken for $\\varepsilon$ and $\\sigma$, an MD time-step is of the order of a femto-second. Thus one billion MD iterations corresponds to approximately one micro-second. Throughout the remainder of this paper, simulation times will be measured with respect to one billion MD iterations, which in turn is approximated as one micro-second.\n\nA model binary glass system is created via an NVT temperature quench from a close-to-equilibrium liquid state~\\cite{Derlet2017,Derlet2017a}. Following either pressure or cohesive energy, a change in slope with respect to temperature indicates a glass transition is reached and the amorphous solid regime is entered. The temperature at which this occurs is referred to as the fictive glass transition temperature ($T_{\\mathrm{f}}$). For MD, $T_{\\mathrm{f}}$ is usually taken as a reference glass transition temperature, $T_{\\mathrm{g}}$. Experimentally, $T_{\\mathrm{f}}$ is seen as the glass transition temperature without any additional annealing protocol. Such a temperature protocol, sometimes with a pressure protocol, embodies the standard method to produce a glass using atomistic simulation~\\cite{Rodney2011}. At a somewhat lower temperature than $T_{\\mathrm{f}}$, the temperature quench may be halted and long-time constant temperature simulations are performed, followed by a further quench to zero temperature. This annealing step is known to produce more relaxed samples~\\cite{Derlet2017a}. The present work considers only fixed volume simulations, the so-called NVT ensemble. Recent work has shown that when performed at appropriately rescaled temperatures, both fixed volume and fixed pressure (NPT ensemble) sample production protocols result in similar relaxation trajectories and thus similar final structural states with zero temperature volumes that differ by only $\\sim0.2\\%$. See Ref.~\\cite{Derlet2018} for more details.\n\nIn the first instance, we consider a glass sample consisting of 500 atoms, at a fixed volume per atom equal to 0.767$\\sigma^{3}$. This sample is initially produced using the linear-quench protocol just discussed. Such a small atom number is chosen to maximize computational throughput, but is large enough to accommodate the local structural excitations (LSEs) that mediate general structural relaxation~\\cite{Swayamjyoti2014,Derlet2017,Derlet2017a}. The precise details of the quench protocol are identical to Ref.~\\cite{Derlet2017a}, resulting in the present sample having the same value of $T_{\\mathrm{f}}$ as that of Ref.~\\cite{Derlet2017a}.\n\n\\section{Results} \\label{sec-results}\n\n\\subsection{Long time $TT_{\\mathrm{f}}$ relaxation and variation of chemical content} \\label{ssec-lts1}\n\nA similar annealing protocol for the 50:50 sample is now performed at a temperature equal to 1.2$T_{\\mathrm{f}}$ (here the temperature quench from the melt has been halted at 1.2$T_{\\mathrm{f}}$ instead of 0.95$T_{\\mathrm{f}}$). The energy per atom and icosahedral content per atom as a function of time is plotted in Fig.~\\ref{Fig4}a. At this higher temperature, initially there is little relaxation when compared to the first $\\mu$sec of the lower temperature constant temperature anneal of Fig.~\\ref{Fig1}a. Brief excursions to lower energy structures are however seen, and at approximately 1.2 $\\mu$sec a significant irreversible reduction in structural energy occurs. The anti-correlation with icosahedral content is again seen (Fig.~\\ref{Fig4}b) and the resulting relaxation trajectory is shown in Fig.~\\ref{Fig4}c. Inspection of the figure reveals the same linear correlation as seen in Fig.~\\ref{Fig1}b. Indeed, from a general structural perspective there is little difference between that of the final state arising from this higher temperature and that of the structure at a comparable energy per atom arising from the 80 $\\mu$sec anneal, where in both cases the icosahedrally coordinated atoms arise from fragments of the C15 Laves crystal structure.\n\n\\begin{figure*}\n\t\\begin{center}\n\t\\subfloat[]{\\includegraphics[width=0.45\\linewidth]{fig4a.pdf}}\n\t\\subfloat[]{\\includegraphics[width=0.45\\linewidth]{fig4b.pdf}} \\\n\t\\subfloat[]{\\includegraphics[width=0.45\\linewidth]{fig4c.pdf}}\n\\end{center}\n\t\\caption{a) Energy per atom and b) icosahedral content evolution over a time at an annealing temperature $1.2T_{\\mathrm{f}}$ for the small:large atom type compositions 33:67, 50:50 and 67:33. c) Corresponding scatter plots of energy per atom and percentage icosahedral content. Also shown are the isolated data points of the perfect laves structure and the nano composite laves structure of Fig.~\\ref{Fig3}b evaluated at the corresponding volumes.}\n\t\\label{Fig4}\n\\end{figure*}\n\nApplying the present results to a variation of chemistry, suggests that a 67:33 composition of small to large atoms would exhibit a relaxation trajectory which asymptotes to the perfect C15 Laves crystal or poly-crystal. For a direct validation of this we redo the $T>T_{\\mathrm{f}}$ isotherm NVT simulations now using a 67:33 composition, but at the fixed volume for which the average volume available to the small and large atoms remains the same as that of the 50:50 simulations~\\footnote{At the fixed volume of $0.76\\sigma^{3}$, the average volume per atom (derived from a Voronoi tessellation) of the different sized atoms is $\\Omega_{\\mathrm{small}}=0.579\\sigma^{3}$ and $\\Omega_{\\mathrm{large}}=0.955\\sigma^{3}$. The global volume for an $N=N_{\\mathrm{small}}+N_{\\mathrm{large}}$ atom system, is then taken as $N_{\\mathrm{small}}\\Omega_{\\mathrm{small}}+N_{\\mathrm{large}}\\Omega_{\\mathrm{large}}$.}. Fig.~\\ref{Fig4} displays the energy and icosahedral content as a function of time, and at approximately 0.6 $\\mu$sec an abrupt change occurs demonstrating significant structural relaxation. This may also bee seen in the resulting relaxation trajectory shown in fig.~\\ref{Fig4}c, where also the energy and icosahedral data-point corresponding to the perfect Laves structure at the same volume per atom is shown. As with the 50:50 relaxation trajectory there is alignment between the glass and the suggested asymptotic structure, confirming our initial hypothesis of a fundamental connection between glass relaxation and the Laves crystal structure.\n\nTo further investigate the effect of stoichiometry, we also perform similar simulations for the 33:67 composition which, by our current reasoning, would result in small C15 crystallites surrounded by a dominate mono-atomic amorphous phase of the larger atom. This structural asymptote scenario is however unlikely since we have already demonstrated that the remaining mono-atomic region (without a high density of laves crystal surfaces) rapidly crystallizes to a close-packed structure. Inspection of the corresponding energy versus icosahedral trajectory in Fig.~\\ref{Fig4}c does indeed demonstrate an abrupt cessation of the trajectory in terms of the icosahedral structural measure. Inspection of the atomic scale processes underlying this behaviour reveals an initial segregation of the smaller atoms into clusters involving several atoms and the creation of icosahedral content. This is followed by a system-spanning ordering to a chemically disordered cubic structure dominant in FCC\/HCP content, and negligible icosahedral content (see Fig.~\\ref{Fig4}b).\n\nThe similar gradients seen in Fig.~\\ref{Fig4}c are a result of the appropriately scaled global volumes which ensure that in all three compositions the same average volume is available to the differently sized atoms. This reiterates the importance of local volume. When the 67:33 and 33:67 simulations are done at the fixed volume of the 50:50 simulations, similar trajectories are seen (with the 67:33 trajectory again asymptoting to the Laves crystal limit), but with gradients which now depend on composition.\n\n\\subsection{Global and local energy} \\label{ss-eos}\n\nTo gain a better understanding of the energetic origin of the observed behaviour, Fig.~\\ref{Fig5} displays the equation of state (EOS) curves for the Wahnstr{\\o}m LJ potential for a variety of relevant crystal phases. The black vertical line indicates the fixed volume at which the present simulations were performed, and it is seen that the Laves, the intermetallic bcc-b2 and the bcc-C11b phases have comparable energies at this chosen volume per atom. Note that there is also little difference between the EOS curves of the hcp and fcc phases of each atom type, which is to be expected for a short-range pair potential.\n\n\\begin{figure*}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.55\\linewidth]{fig5.pdf}\n\t\\end{center}\n\t\\caption{Plot of equation-of-state curves for a number of pure and binary alloy phases. Also included are scatter plots of local potential energy versus local volume for the 80 micro-second annealed glass and the nano composite Laves structure at a fixed volume of 0.767$\\sigma^{3}$ --- indicated by the black vertical line, the thicker red part of which indicates the energy per atom range of the glass. The two inverted black triangles indicate the volume and energy per atom of the equilibrium laves C15 phase at a similar fixed volume.}\n\t\\label{Fig5}\n\\end{figure*}\n\nThe Laves C15 EOS curve indicates that a significant reduction in energy could be achieved by forming this phase at a reduced volume, and that the remaining larger atoms of non-stoichiometric compositions (such as 50:50) could become hcp\/fcc by increasing their volume per atom. This possibility may be quantified by writing the energy of this dual phase as\n\\begin{equation}\nE_{\\mathrm{Laves-hcp}}=\\frac{3}{4}E_{\\mathrm{Laves}}\\left(V_{\\mathrm{Laves}}\\right)+\\frac{1}{4}E_{\\mathrm{hcp}}\\left(V_{\\mathrm{hcp}}\\right) \\label{Eqn1}\n\\end{equation}\nwhere the volume per atom of each phase must satisfy the global fixed volume per atom, V,\n\\begin{equation}\nV=\\frac{3}{4}V_{\\mathrm{Laves}}+\\frac{1}{4}V_{\\mathrm{hcp}}. \\label{Eqn2}\n\\end{equation}\nUsing the EOS curves of Fig.~\\ref{Fig5}, a minimum of Eqn.~\\ref{Eqn1} is found to be $-7.7\\varepsilon$ which occurs at $V_{\\mathrm{Laves}}=0.69\\sigma^{3}$ and $V_{\\mathrm{hcp}}=1.00\\sigma^{3}$. Such an energy does not include the cost of the interface energy and therefore represents the limit where the microstructural length-scales have diverged and the interface region becomes negligible compared to the volume occupied by the Laves and hcp\/fcc phases. Indeed, drawing a line between the energies of the two ncL micro-structures (which are distinguished by the two grain sizes) and extrapolating this to the regime of an icosahedral content of $50\\%$ yields an energy close too and slightly higher than the bulk value of $-7.7\\varepsilon)$. Together, these results give insight into the origin of the energetics of the dynamics seen in Fig.~\\ref{Fig1}b. Whilst certainly influenced by the bulk energies, the interface energy between the laves or laves-like regions and an approximately mono-atomic close-packed or amorphous structure plays a significant role in setting the overall micro-structural energy scale and therefore the emergent length scales of the well relaxed amorphous solid. \n\nFurther insight can be gained by inspecting the distribution of local energies and volumes in the considered systems. For the perfect Laves phase, the local energy and volume are indicated by the black inverted triangles in Fig.~\\ref{Fig5} with the low\/high volumes representing the small\/large atoms. Also included in Fig.~\\ref{Fig5} is a scatter plot of the local energies of the final glass structure of the 80 $\\mu$sec anneal, and of the artificially constructed ncL microstructure (grain size $6\\sigma$). Both structures show local energies that are centered close to the equilibrium local energies of the perfect Laves crystal --- this becomes more clear when a density plot with respect to local energy and volume is made (not shown). This is particularly the case for the smaller atoms which are predominantly in icosahedral environments. The remaining atoms not associated with the Laves structures tend to have higher energies and volumes, especially the larger atoms in the amorphous interface of the ncL microstructure. Thus the local energies and volumes of the amorphous structure, derived from a direct quench from the melt and a long-time anneal are similar to the artificially generated nano-phase Laves structure generated in Fig.~\\ref{Fig3}b.\n\n\\section{Discussion} \\label{sec-discussion}\n\nThe temperature-time-transformation (TTT) diagram provides a framework in which to quantify when either glass formation or crystallization occurs. Fig.~\\ref{Fig6} details a schematic of such a diagram with a normalized temperature regime on the vertical axis. The quantitative details depend strongly on the chemistry of the melt. Traditional quenching of a glass-forming metallic liquid requires cooling rates less than the critical value $(dT\/dt)_{\\mathrm{crit}}$, such that the temperature-time trajectory does not intersect the so-called nose of the crystalline region. Exceptional glass formers have low $(dT\/dt)_{\\mathrm{crit}}$ of the order of 1 K\/s, whereas mono-atomic metallic glasses may require quench rates up to 10$^{14}$ K\/s to bypass the crystallization nose~\\cite{Mao2014}.\n\nThe crystallization nose in Fig.~\\ref{Fig6} extends over a finite time interval, underlying a transition (as time evolves) from a dominant glassy structure to a dominant equilibrium polycrystalline structure. On the glassy side of the nose this encompasses the micro-structural regime of nanocrystalline composites ~\\cite{Calin2003,Pekarskaya2003,Wu2017} --- a microstructure characterized by nanocrystals of the equilibrium crystalline structure typically embedded in a glassy matrix. To follow a particular isotherm above the glass transition temperature regime, after a heating or quenching, is experimentally challenging due to the short accessible time-window prior to the crystallization nose, and requires exceptionally stable glassy alloys with a crystallization nose located at several tens of seconds~\\cite{Loffler2000}. Alternatively, new high-speed calorimetric instrumentation can now be used to access the shorter time-scales of a TTT diagram~\\cite{Schawe2019}. \n\n\\begin{figure*}[t]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.9\\linewidth,trim=0cm 4cm 2cm 4cm]{fig6.pdf}\n\t\\end{center}\n\t\\caption{Schematic of a temperature-time-transformation (TTT) diagram showing the glass and crystalline regions which can be accessed during a temperature quench protocol from the liquid state. The region indicated by red represents a possible intermediate regime in which out-of-equilibrium nano composite structures are encountered that are not consisting of the equilibrium polycrystalline phases of the inner nose region.}\n\t\\label{Fig6}\n\\end{figure*}\n\nThe consequences of following such isotherms are best illustrated for the two different regimes, $TT_{\\mathrm{f}}$. The first case considers the structural trajectory of a glassy solid, as done in the simulations of sec.~\\ref{ssec-lts}. The typical timescales associated with MD places the onset of the $\\mu$sec MD isotherm far to left of the TTT diagram. At the beginning of the isotherm, the glass is unrelaxed and the connectivity of SRO is low. With increasing time, the icosahedral content increases, leading to the development of MRO and internal length scales which increase as a function of annealing time. The second isotherm in Fig.~\\ref{Fig6} at $T>T_{\\mathrm{f}}$, is motivated by the idea that shorter time-scales are needed to approach the crystallization nose. The results of sec.~\\ref{ssec-lts1} indeed demonstrate this, where within the order of 1$\\mu$sec, significant relaxation associated with the creation of icosahedral SRO and MRO is seen, producing structures not so different from the 80 $\\mu$sec anneal of sec.~\\ref{ssec-lts} at $TT_{\\mathrm{f}}$ and towards the melting temperature regime, whereas the latter becomes relevant at lower temperatures, $T