A code generating method, applied to a scheduling system, wherein the scheduling system comprises a heterogeneous system and a compiler, code is executable code, the executable code is applied to the heterogeneous system, and the heterogeneous system comprises an accelerated processing unit and a central processing unit; and the method comprises: acquiring, by the compiler, resource information of the accelerated processing unit and resource information of the central processing unit, calling a running cost evaluation function to perform running cost evaluation for the accelerated processing unit and the central processing unit, so as to generate an operable platform list and a preferential processor list, and identifying accelerable code from first user code according to the resource information of the accelerated processing unit, wherein the operable platform list comprises all accelerated processing units and central processing units, the preferential processor list comprises a preset quantity of accelerated processing units that are in the operable platform list and whose running cost is less than a preset value; embedding, by the compiler, a hook function and an exception handling function before the accelerable code to form second user code; and compiling, by the compiler, the second user code to obtain the executable code, wherein the executable code comprises executable user code obtained by compiling the hook function and the exception handling function, and first accelerable branch code and second accelerable branch code that are obtained by compiling the accelerable code, wherein the first accelerable branch code is used for execution on an accelerated processing unit in the preferential processor list, the second accelerable branch code is used for execution on a central processing unit in the operable platform list, and a purpose of embedding the hook function and the exception handling function is to: when the hook function is being executed in a process of executing the executable code, use condition control code in the exception handling function to acquire, from the preferential processor list of the process scheduling interface, an accelerated processing unit that has the lightest load and/or the lowest running cost as a target processing unit that executes the first accelerable branch code; and acquire, from the operable platform list of the process scheduling interface, a central processing unit that has the lightest load and/or the lowest running cost as a target processing unit that executes the second accelerable branch code. acquiring, by the compiler, resource information of the accelerated processing unit and resource information of the central processing unit, calling a running cost evaluation function to perform running cost evaluation for the accelerated processing unit and the central processing unit, so as to generate an operable platform list and a preferential processor list, and identifying accelerable code from first user code according to the resource information of the accelerated processing unit, wherein the operable platform list comprises all accelerated processing units and central processing units, the preferential processor list comprises a preset quantity of accelerated processing units that are in the operable platform list and whose running cost is less than a preset value; embedding, by the compiler, a hook function and an exception handling function before the accelerable code to form second user code; and compiling, by the compiler, the second user code to obtain the executable code, wherein the executable code comprises executable user code obtained by compiling the hook function and the exception handling function, and first accelerable branch code and second accelerable branch code that are obtained by compiling the accelerable code, wherein the first accelerable branch code is used for execution on an accelerated processing unit in the preferential processor list, the second accelerable branch code is used for execution on a central processing unit in the operable platform list, and a purpose of embedding the hook function and the exception handling function is to: when the hook function is being executed in a process of executing the executable code, use condition control code in the exception handling function to acquire, from the preferential processor list of the process scheduling interface, an accelerated processing unit that has the lightest load and/or the lowest running cost as a target processing unit that executes the first accelerable branch code; and acquire, from the operable platform list of the process scheduling interface, a central processing unit that has the lightest load and/or the lowest running cost as a target processing unit that executes the second accelerable branch code.