We review a unified approach for computing: (i) spin-transfer torque in magnetic trilayers like spin-valves and magnetic tunnel junction, where injected charge current flows perpendicularly to interfaces; and (ii) spin-orbit torque in magnetic bilayers of the type ferromagnet/spin-orbit-coupled-material, where injected charge current flows parallel to the interface. Our approach requires to construct the torque operator for a given Hamiltonian of the device and the steady-state nonequilibrium density matrix, where the latter is expressed in terms of the nonequilibrium Greens functions and split into three contributions. Tracing these contributions with the torque operator automatically yields field-like and damping-like components of spin-transfer torque or spin-orbit torque vector, which is particularly advantageous for spin-orbit torque where the direction of these components depends on the unknown-in-advance orientation of the current-driven nonequilibrium spin density in the presence of spin-orbit coupling. We provide illustrative examples by computing spin-transfer torque in a one-dimensional toy model of a magnetic tunnel junction and realistic Co/Cu/Co spin-valve, both of which are described by first-principles Hamiltonians obtained from noncollinear density functional theory calculations; as well as spin-orbit torque in a ferromagnetic layer described by a tight-binding Hamiltonian which includes spin-orbit proximity effect within ferromagnetic monolayers assumed to be generated by the adjacent monolayer transition metal dichalcogenide.