| 79 | explicit LuOpGpu(OpKernelConstruction* context) : AsyncOpKernel(context) {} |
| 80 | |
| 81 | void ComputeAsync(OpKernelContext* context, DoneCallback done) final { |
| 82 | const Tensor& input = context->input(0); |
| 83 | |
| 84 | // Analyze shape and validate inputs. |
| 85 | const int input_rank = input.dims(); |
| 86 | |
| 87 | OP_REQUIRES_ASYNC( |
| 88 | context, input_rank >= 2, |
| 89 | errors::InvalidArgument("Input must have rank >= 2, got ", input_rank), |
| 90 | done); |
| 91 | |
| 92 | const int64 num_rows = input.dim_size(input_rank - 2); |
| 93 | const int64 num_cols = input.dim_size(input_rank - 1); |
| 94 | |
| 95 | OP_REQUIRES_ASYNC( |
| 96 | context, num_rows == num_cols, |
| 97 | errors::InvalidArgument("Input matrices must be squares, got", num_rows, |
| 98 | " != ", num_cols), |
| 99 | done); |
| 100 | |
| 101 | TensorShape batch_shape; |
| 102 | for (int dim = 0; dim < input_rank - 2; ++dim) { |
| 103 | batch_shape.AddDim(input.dim_size(dim)); |
| 104 | } |
| 105 | TensorShape permutation_indices_shape = batch_shape; |
| 106 | permutation_indices_shape.AddDim(num_rows); |
| 107 | |
| 108 | const GPUDevice& device = context->eigen_device<GPUDevice>(); |
| 109 | auto solver = absl::make_unique<CudaSolver>(context); |
| 110 | |
| 111 | // We output the packed triangular factors in a dense form. |
| 112 | // The lower triangular factor L corresponds to the strictly lower |
| 113 | // triangular part of packed_triangular_factors with an implicit unit |
| 114 | // diagonal. The upper triangular factor U is the upper triangular part of |
| 115 | // packed_triangular_factors. The triangular factors satisfy the equation |
| 116 | // P * input_matrix = L * U |
| 117 | // where P is the permutation matrix corresponding to the indices in |
| 118 | // permutation_indices. |
| 119 | // |
| 120 | // Reuse the input buffer or make a copy for the factorization step, |
| 121 | // depending on whether this ops owns it exclusively. |
| 122 | Tensor* packed_triangular_factors; |
| 123 | OP_REQUIRES_OK_ASYNC(context, |
| 124 | context->forward_input_or_allocate_output( |
| 125 | {0}, 0, input.shape(), &packed_triangular_factors), |
| 126 | done); |
| 127 | if (!packed_triangular_factors->SharesBufferWith(input)) { |
| 128 | device.memcpy(packed_triangular_factors->flat<Scalar>().data(), |
| 129 | input.flat<Scalar>().data(), |
| 130 | input.NumElements() * sizeof(Scalar)); |
| 131 | } |
| 132 | |
| 133 | // Allocate output permutation. |
| 134 | Tensor* permutation_indices = nullptr; |
| 135 | OP_REQUIRES_OK_ASYNC(context, |
| 136 | context->allocate_output(1, permutation_indices_shape, |
| 137 | &permutation_indices), |
| 138 | done); |
nothing calls this directly
no test coverage detected