D3DDEVTYPE_HAL specifies that the hardware is used for rendering. D3DDEVTYPE_REF stands for reference rasterizer, it specifies that the hardware features will have to be emulated, that is why it runs so slow. Also REF is only available with the DX9 SDK, it is not redistributed with the retail runtimes, so the only two devices you could use in production are hardware and software.
In some samples you can't choose the hardware because you hardware might not be capable of doing whatever Direct3D needs it to do, so it has to emulated.