You can use this method to fetch all parent products (products with variations) through the product repository (dependency inject it). This works because parent products does not have a parent and they have at least one child product.
If you want all variants, search for all products with parentId not null.
You can also consider using ->searchIds() instead of ->search() (much faster, you et the IDs only) and then fetch specific variations afterwards based on a specific parent ID.
$criteria = new Criteria();
$criteria->addFilter(new RangeFilter('childCount', [RangeFilter::GT => 0]));
$criteria->addFilter(new EqualsFilter('parentId', null));
$parentProducts = $this->productRepository->search(
$criteria,
Context::createDefaultContext()
)->getElements();