If we take materialism as a philosophical doctrine to the effect that all that exists is matter in its various forms and interactions, then this is a view developed by Engels, Plekhanov, Kautsky and certain others towards the end of the nineteenth century - not a view that can credibly be attributed to Marx himself.
Doubtless the idea that Marx was a philosophical materialist derives from the occurrence of 'materialism' in Marx's position of 'historical materialism' and by inference from his opposition to the anti-materialist and 'idealist' philosophy of Hegel.
Marx's remarks in The German Ideology - such remarks as 'Certainly Feuerbach has a great advantage over the "pure" materialists' and 'As far as Feuerbach is a materialist he does not deal with history, and as far as he considers history he is not a materialist' (GI: 58-9) - should give one pause in attributing materialism or its defence to Marx.
Marx accepts that in human 'activity, this unceasing sensuous labour and creation, this production ... the priority of external nature remains unassailed' (GI: 58). If 'external nature' is given a materialist interpretation, it is human activity that creates 'the whole sensuous world as it now exists', a world of 'social connection' which is also a world of 'social structure' (GI: 58).
In this social world, each generation 'exploits the materials, the capital funds, the productive forces handed down to it by all preceding generations' and in the divide between the forces of production (the means of exploiting those materials, &c.) and the relations of production (patterns of ownership) different social structures, emerge - feudalism, capitalism - and the phenomena of exploitation and alienation. The relations of production differentiate social classes, with ownership of the forces - the means - of production residing in the ruling class.
That Marx's theory of historical materialism is not a form of philosophical materialism as outlined at the start is made yet more clear in the following passage from The German Ideology:
The ideas of the ruling class are in every epoch the ruling ideas: i.e., the class, which is the ruling material force of society is at the same time the ruling intellectual force. The class which has the means of material production at its disposal, has control at the same time over the means of mental production, so that thereby, generally speaking, the ideas of those who lack the means of mental production are subject to it. The ruling ideas are nothing more than the ideal expression of the dominant material relationships, the dominant material relationships grasped as ideas. (GI: 60)
If all that exists is matter in its various forms and interactions, how could Marx draw a distinction between 'material' and 'intellectual' force? It is plain, or seems so to me, that 'materialism' in historical materialism takes its point from the centrality to Marx's social theory of who controls 'material production' and, presupposed to this, the recognition that such production is a primary human activity.
References
K. Marx & F. Engels, The German Ideology, London: Lawrence & Wishart, 1965.
F.L. Bender, 'Marx, Materialism and the Limits of Philosophy', Studies in Soviet Thought, 25, 1983: 79-100.