function [dZ, dOffset, dScale] = internal_layernormBackward(dZ, X, scale, XMean, XInvStd, normalizationDim, channelDim)
% This function is undocumented and will change in a future release.

%   Copyright 2020-2022 The MathWorks, Inc.

% gpuArray method for internal_layernormBackward. The help for this method
% is similar to the CPU method internal_layernormBackward

if ~isreal(dZ)
    error(message('deep:dlarray:ComplexGradientOutput', 'layernorm'));
end

% Call the cnnhost backward method since no ad-hoc GPU implementation is
% yet available
[dZ, dOffset, dScale] = nnet.internal.cnnhost.layerNormalizationBackward(...
    dZ, X, XMean, XInvStd, scale, normalizationDim, channelDim);

end
