MCPcopy Create free account
hub / github.com/dmlc/xgboost / CopyGradientFromArrays

Function CopyGradientFromArrays

src/c_api/c_api.cc:1170–1189  ·  view source on GitHub ↗

Helper function to copy gradient from array interface to linalg::Matrix

Source from the content-addressed store, hash-verified

1168
1169// Helper function to copy gradient from array interface to linalg::Matrix
1170void CopyGradientFromArrays(Context const *ctx, ArrayInterface<2, false> const &i_grad,
1171 ArrayInterface<2, false> const &i_hess,
1172 linalg::Matrix<GradientPair> *out_gpair) {
1173 auto grad_is_cuda = ArrayInterfaceHandler::IsCudaPtr(i_grad.data);
1174 auto hess_is_cuda = ArrayInterfaceHandler::IsCudaPtr(i_hess.data);
1175 CHECK_EQ(grad_is_cuda, hess_is_cuda) << "gradient and hessian should be on the same device.";
1176
1177 if (!grad_is_cuda) {
1178 out_gpair->Reshape(i_grad.Shape<0>(), i_grad.Shape<1>());
1179 auto h_gpair = out_gpair->HostView();
1180 DispatchDType(i_grad, DeviceOrd::CPU(), [&](auto &&t_grad) {
1181 DispatchDType(i_hess, DeviceOrd::CPU(), [&](auto &&t_hess) {
1182 common::ParallelFor(h_gpair.Size(), ctx->Threads(),
1183 detail::CustomGradHessOp{t_grad, t_hess, h_gpair});
1184 });
1185 });
1186 } else {
1187 CopyGradientFromCudaArrays(ctx, i_grad, i_hess, out_gpair);
1188 }
1189}
1190} // namespace xgboost
1191
1192XGB_DLL int XGBoosterTrainOneIter(BoosterHandle handle, DMatrixHandle dtrain, int iter,

Callers 2

XGBoosterTrainOneIterFunction · 0.85

Calls 7

CPUFunction · 0.85
ParallelForFunction · 0.85
ReshapeMethod · 0.80
ThreadsMethod · 0.80
DispatchDTypeFunction · 0.50
HostViewMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected