Yes, you are right. In this case , I was lucky since the labels are composed by single words.
Thanks for the cuda trick 
Yeah, a more general solution will be fantastic. Anyway, thanks for your kind attention