The literary device used in these lines is Personification.
The personification is a figure of speech in which a thing is given human attributes. The non-human objects are portrayed in such a way that we feel they have the capacity to act like human beings. This device makes the piece more interesting to read and makes it more sensitive to the reader.