The autonomous vehicles (AVs), like that in knight rider, were completely a scientific fiction just a few years ago, but are now already practical with real-world commercial deployments. A salient challenge of AVs, however, is the intensive computing tasks to carry out on board for the real-time traffic detection and driving decision making; this imposes heavy load to AVs due to the limited computing power. To explore more computing power and enable scalable autonomous driving, in this paper, we propose a collaborative task computing scheme for AVs, in which the AVs in proximity dynamically share idle computing power among each other. This, however, raises another fundamental problem on how to incentivize AVs to contribute their computing power and how to fully utilize the pool of group computing power in an optimal way. This paper studies the problem by modeling the issue as a market-based optimal computing resource allocation problem. In specific, we develop a software-defined network (SDN) architecture and consider a star topology where a centered AV outsources its computing tasks to the surrounding AVs for its autonomous driving. A market mechanism is developed in which the surrounding AVs sell their computing power at a cost based on their local idle computing resources. Then, we classify the tasks requested by the centered AV into two types which are task with time to live (TTL) and task without TTL, respectively. With different task types, we define corresponding cost models of the centered AV and formulate them as two minimization problems. The optimal solutions of the problems are achieved to guide the centered AV to wisely allocate computing tasks to surrounding AVs towards minimal cost. Finally, the performance of the proposed scheme is evaluated using simulations, which show that the proposed scheme can result in the guaranteed computing performance yet the lowest costs compared with other conventional schemes.