This application claims the priority benefit of Taiwan application serial no. 97100344, filed on Jan. 4, 2008. The entirety of the above-mentioned patent application is hereby incorporated by reference herein and made a part of this specification.
1. Field of the Invention
The present invention relates to a method for data calculation. More particularly, the present invention relates to a method for assisting in data calculation by using a display card.
2. Description of Related Art
A central processing unit (CPU) is a main tool of a computer for executing calculations. Besides the CPU, to meet an increasing demand of drawing, a display card disposed on a motherboard is generally equipped with an independent graphic processing unit (GPU) and a display memory, so as to accelerate a drawing speed. During drawing of the display card, texture data is first obtained to execute a texture-related calculation, and then a calculation result is displayed on a target.
In detail,
With the development of technology, data required to be processed by the computer is greatly increased, to meet such a demand, it seems to have no other solutions besides applying a high-efficiency CPU. However, as described above, the GPU of the display card actually has a powerful calculation capability, and if such calculation capability can be appropriately utilized during an idle time thereof, a part of calculation tasks of the CPU can be shared by the GPU so as to reduce a usage rate of the CPU, which is come to an idea of the present invention.
Accordingly, the present invention is directed to a method for assisting in data calculation by using a display card, by which calculation tasks originally executed by a system CPU are transformed into data and program codes that can be executed by GPU of the display card and a part of the system tasks is transferred to the display card for calculation, so that a usage rate of the system CPU is reduced.
The present invention provides a method for assisting in data calculation by using a display card, which is suitable for calculating system input data by using the display card to obtain output data. The display card includes a first processing unit and a display memory, and the system includes a second processing unit and a system memory. The method includes following steps. First, the input data is transformed into texture data and is stored in the display memory. Next, a texture calculation is performed to the texture data by the first processing unit, and a result of the texture calculation is stored in a display target of the display memory. Finally, the display target is outputted to the system memory as the output data.
In an embodiment of the present invention, before the step of transforming the input data of the system memory into the texture data and storing it in the display memory, the method further includes detecting a usage rate of the second processing unit of the system; judging whether the usage rate is greater than a predetermined standard; and performing a follow up operation to transfer the input data to the first processing unit for calculation, when the usage rate is greater than the predetermined standard.
In an embodiment of the present invention, the texture data is stored in a first block of the display memory, and the display target is stored in a second block of the display memory.
In an embodiment of the present invention, the step of executing the texture calculation to the texture data by using the first processing unit includes following steps. First, the first block is set as a texture source to be referred to during drawing of the first processing unit. Then, the second block is set as an output target for drawing of the first processing unit. Finally, the texture calculation is executed by using the first processing unit with reference of the texture source.
In an embodiment of the present invention, the step of transforming the input data into the texture data, and storing it in the display memory includes following steps. First, image data is transformed into first texture data, in which the image data includes pixel values of a plurality of pixels of an image. Next, positions of the pixels to be referred to during the texture calculation in the image are transformed into second texture data. Finally, the first texture data and the second texture data are stored in the display memory.
In an embodiment of the present invention, the step of executing the texture calculation to the texture data by using the first processing unit includes following steps. First, the first texture data is read to obtain the positions of the pixels to be referred to during the texture calculation in the image. Next, the second texture data is read with reference of the positions of the pixels in the image to obtain the pixel values of the pixels to be referred to during the texture calculation. Finally, the texture calculation is executed with reference of the pixel values of the pixels.
In an embodiment of the present invention, the texture data includes pixel values of a plurality of pixels of an image and positions of the pixels in the image.
In an embodiment of the present invention, the step of executing the texture calculation to the texture data by using the first processing unit includes following steps. First, a calculation program code executed by the second processing unit is transformed into a pixel shader code that can be executed by the first processing unit. Next, the pixel shader code is executed to read the texture data, and a drawing result is obtained via calculation. Finally, the drawing result is output to the display target.
In an embodiment of the present invention, the texture calculation includes performing one of image processing, encrypting, decrypting, compressing and decompressing to the input data.
In an embodiment of the present invention, a size of the texture data of each of the pixels is four bytes.
In an embodiment of the present invention, the first processing unit is a graphic processing unit (GPU), and the second processing unit is a central processing unit (CPU).
In the present invention, a structure of sharing the system tasks by using the display card is provided, by which when a calculation load of the system is too high, a part of the system tasks is transformed into the data and the program codes that can be executed by the GPU of the display card. Then, after calculation of the GPU, the calculation result is output to the system memory, so as to assist in completing a part of the system tasks, so that calculation burden of the system CPU can be reduced.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, a preferred embodiment accompanied with figures is described in detail below.
The accompanying drawings are included to provide a further understanding of the invention, and are incorporated in and constitute a part of this specification. The drawings illustrate embodiments of the invention and, together with the description, serve to explain the principles of the invention.
Generally, a full algorithm includes three parts: data input, execution process and result output. The algorithm calculation is generally perform by a CPU of a computer, and if the algorithm calculation is about to be handed to the display card for execution, the above three parts of data then have to be suitably adjusted or format conversion thereof has to be performed, so as to meet a demand for processing data by using the display card. The present invention provides a method for assisting in data calculation by using a display card based on the above concept. To fully convey the spirit of the present invention to those skilled in the art, embodiments are provided below for detailed description.
In detail, in the present embodiment, a graphic processing unit (GPU) of a display card is utilized to substitute the CPU for processing the system input data, and after the calculation, a calculation result is transferred back to the system and served as output data. The aforesaid display card includes a GPU and a display memory, and the system includes a CPU and a system memory. In the following, detailed steps of the present embodiment are described.
First, the input data is transformed into texture data by using the CPU, and is stored in the display memory of the display card (step S310). In detail, since during the drawing of the display card, information of any point on the texture can be obtained, as long as a sequence thereof is suitably arranged, the texture then can be regarded as a block of memory stored with the input data. In most cases, the block of memory is the display memory of the display card, and now the input data stored in the system memory is moved into the texture (memory) by using a three-dimensional application programming interface (API), for example, Direct 3D, and the texture is set as a reference for drawing of the display card. Accordingly, the display card can perform the drawing with reference of the input data stored in the texture.
After the texture data is ready, the GPU then executes the texture calculation to the texture data (step S320). This step represents an actual data calculation process, in which the texture calculation can be executed includes image processing of the input data, or other processes such as encrypting, decrypting, compressing and decompressing, which is not limited by the present invention.
It should be noted that in the present embodiment, pixel shader codes are applied for obtaining the texture data, executing certain calculations and outputting the calculation result to a display target. By utilizing the three-dimensional API, the pixel shader code is set as program code that can be called by the GPU during the drawing, so that the program code is called each time when the display card draws a pixel. A size of the texture data of the pixel called each time is, for example, four bytes, and data amount output to the display target is also four bytes, which is not limited by the present invention.
Next, the result of the texture calculation is stored in a display target of the display memory (step S330). The so-called display target has to be a block of display memory, and here the display target can also be set as an output destination of the display card by using the three-dimensional API. In detail, the texture data is, for example, stored in a first block of the display memory, and the display target is stored in a second block of the display memory. When the GPU executes the texture calculation, the first block can be set as a texture source to be referred to during the drawing, and the second block can be set as the output destination for the drawing. Then, the required texture calculation is executed with reference of the set texture source.
Finally, the display target is output to the system memory and served as the output data (step S340) for completing the data calculation. The output data then can be regarded as a calculation result originally obtained by processing the input data stored in the system memory via the CPU. By such means, a part of calculation tasks of the CPU is transferred to the GPU, so that a calculation burden of the CPU is reduced.
As described above, a main purpose of the present invention is to assist in data calculation of the system CPU by using the GPU of the display card, and a utilization opportunity thereof is when the CPU is in a high usage rate, and then a part of the calculation tasks can be transferred to the GPU. Therefore, before the GPU is utilized for assisting in calculation, the usage rate of the system CPU is detected first, and whether the usage rate is higher than a predetermined standard is judged. When the usage rate is greater than the predetermined standard, the CPU is then judged to be overloaded, and the assistance is required. At this time, the aforementioned steps such as data format conversion and texture calculation are performed, so as to transfer the input data to the GPU for calculation and reduce the calculation burden of the CPU.
To fully convey the spirit of the present invention, in the following, a color space conversion is taken as an example with reference of figures for describing the method of the present invention in detail.
First, the image data stored in the system memory is transformed into first texture data, stored in the display memory of the display card, and set as a texture source (step S410). Since information of any point on the texture can be obtained during drawing of the display card, as long as a sequence thereof is suitably arranged, the first texture data then can be regarded as a block of memory stored with the input data.
Next, characteristic of relative positions in the first texture data is obtained by using the three-dimensional API, and a mapping table is established to serve as another texture source (which can be regarded as second texture data) (step S420). A main function of the mapping table is to assist the GPU to obtain correct texture positions, so as to search required data for the calculation.
After conversion and establishment of the texture data required by the texture calculation are completed, the GPU then executes the texture calculation to the texture data (step S430). The step S430 can be further divided into following steps.
First, a program code originally executed by the CPU is transformed into a pixel shader code that can be executed by the GPU (step S431). Next, the pixel shader code is executed for reading the mapping table stored in the display memory, so as to obtain positions of the pixels to be referred to in the image during the texture calculation (step S432). By referring to the position data, the first texture data can be further read, so as to obtain pixel values of the pixels to be referred to during the texture calculation (S433). Finally, the texture calculation is executed with reference of the pixel values to obtain a calculation result (step S434).
As described above, the texture data can be the pixel values of a plurality of pixels within an image (for example, the second texture data), or the positions of the pixels in the image (for example, the first texture data), which is not limited by the present invention. After the texture calculation is completed, the calculation result is output to the display target (step S440) to complete the color space conversion.
For example,
It should be noted that, in the above embodiment, an image and positions of pixels in the image are regarded as the texture data to be referred to during the texture calculation of the GPU. However, those skilled in the art should understand that other types and numbers of the texture data can also be applied according to actual requirement of the texture calculation, so as to achieve a purpose of diversified calculation. In other words, as long as a suitable data conversion is performed, work threads originally executed by the CPU can be transferred to the GPU for processing, so as to share the calculation burden of the CPU.
In summary, the method for assisting in data calculation by using the display card has at least the following advantages:
1. The calculation capability and memory of the display card can be utilized to assist in a part of the calculation tasks of the CPU, so as to effectively reduce the usage rate of the CPU.
2. Various data such as image data or pixel positions can be set as the texture data to be referred to during the texture calculation, so as to provide a flexible range for the texture calculation.
3. By detecting the usage rate of the CPU, a substitute approach is provided to share the calculation burden of the CPU when it is overloaded, so that problems such as delay of processing procedure caused by overload of the CPU can be avoided.
It will be apparent to those skilled in the art that various modifications and variations can be made to the structure of the present invention without departing from the scope or spirit of the invention. In view of the foregoing, it is intended that the present invention cover modifications and variations of this invention provided they fall within the scope of the following claims and their equivalents.
Number | Date | Country | Kind |
---|---|---|---|
97100344 | Jan 2008 | TW | national |