
Computer Science
#include<cmath>
#include<stdio.h>
__global__void
process_kernel1(float *input1,float *input2,float *output,int datasize){
int idx = threadIdx.x + blockIdx.x * blockDim.x;
int idy = threadIdx.y + blockIdx.y * blockDim.y;
int idz = threadIdx.z + blockIdx.z * blockDim.z;
int index = idz * (gridDim.x * blockDim.x) * (gridDim.y*blockDim.y) + idy * (gridDim.x * blockDim.x) +idx;
if(index<datasize)
output[index] = sinf(input1[index]) + cosf(input2[index]);
}
__global__void
process_kernel2(float *input,float *output,int datasize){
int idx = threadIdx.x + blockIdx.x * blockDim.x;
int idy = threadIdx.y + blockIdx.y * blockDim.y;
int idz = threadIdx.z + blockIdx.z * blockDim.z;
int index = idz * (gridDim.x * blockDim.x) * (gridDim.y*blockDim.y) + idy * (gridDim.x * blockDim.x) +idx;
if(index<datasize)
output[index] = logf(input[index]);
}
_global__void
process_kernel3(float *input,float *output,int datasize){
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if(index<datasize)
output[idx] = sqrtf(input[index]);
}
int main(void){
int datasize = 128*128*8;
float *input1, *input2, *input,*output;
cudaMallocManaged(&input1, datasize*sizeof(float));
cudaMallocManaged(&input2, datasize*sizeof(float));
cudaMallocManaged(&input, datasize*sizeof(float));
cudaMallocManaged(&output, datasize*sizeof(float));
dim3 threadsPerBlock1(32, 32, 1);
dim3 blocksPerGrid1(4, 2, 2);
process_kernel1<<<blocksPerGrid1,threadsPerBlock1>>>(input1,input2,output,datasize);
cudaDeviceSynchronize();
dim3 threadsPerBlock2(8, 8, 2);
dim3 blocksPerGrid2(2,datasize/(8*8*2), 1);
process_kernel2<<<blocksPerGrid2,threadsPerBlock2>>>(output,input,datasize);
cudaDeviceSynchronize();
dim3 threadsPerBlock3(128, 1, 1);
dim3 blocksPerGrid3(datasize/128, 1, 1);
process_kernel3<<<blocksPerGrid3,threadsPerBlock3>>>(input,output,datasize);
cudaDeviceSynchronize();
cudaFree(input1);
cudaFree(input2);
cudaFree(input);
cudaFree(output);
return 0;
}
I am finding these error
File "<ipython-input-4-1c245d54f409>", line 4
process_kernel1(float *input1,float *input2,float *output,int datasize){
^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
why ? can you correct it?

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- C+++ #include <iostream>#include <pthread.h>#include <stdlib.h> #define TOTAL_THREADS 4 int count;pthread_mutex_t the_mutex; // phread mutex variable - initialize here if using the initializer macro void* myFunction(void* arg){int actual_arg = *((int*) arg);for(unsigned int i = 0; i < 10; ++i) {// TODO:// Use a Pthread mutex to control// access to the critical region. // Beginning of the critical regioncount++;std::cout << "Thread #" << actual_arg << " count = " << count << std::endl; // End of the critical region// TODO:// Relinquish access to the Pthread mutex// since critical region is complete. // Random wait - This code is just to ensure that the threads// show data sharing problemsint max = rand() % 100000;for (int x = 0; x < max; x++);// End of random wait code}pthread_exit(NULL);} int main(){int rc[TOTAL_THREADS];pthread_t ids[TOTAL_THREADS];int args[TOTAL_THREADS];// TODO: Initialize the pthread mutex here if using the…arrow_forward// // main.c // Assignment1 // // Created by Hassan omer on 15/10/21. // #include <stdio.h> # include <stdlib.h> int input(); int multiples(); int cions(); void display_change(); int main() { int num; num = input(); multiples(num); cions(); display_change(); return 0; } int input(int num) { printf("enter 5-95 number\n"); scanf("%d",&num); return num; } int multiples(int num) { int sum5 =0; if (sum5 %5 != 0 ||sum5<5|| sum5 >95) { printf("invaild input %d",sum5); } cions(sum5); return sum5; } int cions(int sum05){ int cent50 = 0; int cent20 = 0; int cent10 = 0; int cent05 = 0; if (sum05 > 0) { if (sum05 >= 50){ sum05 -= 50; cent50++; } else if (sum05 >=20){ sum05 -= 20; cent20++; } else if (sum05 >= 10){ sum05 -=10;…arrow_forwardC Sharp How do I format my code to 2 decimal places whem I am calling my code in Main using System.Threading.Tasks; namespace ssullivan_A2_1.cs{ class Program { //The output should display the Object Type (Circle, Square or Triangle) //the values used to initialize the shape, the area, and the perimeter static void Main(string[] args) { ////Store the objects in a Collection object (List, Array, HashSet, etc...) objects in the collection will be of type Shape Shapes[] arrayOfShapes = new Shapes[3]; arrayOfShapes[0] = new Circle(5);// arrayOfShapes[1] = new Rectangle(5, 5);// arrayOfShapes[2] = new Triangle(3, 5, 5);// //the values used to initialize the shape, the area, and the perimeter foreach (Shapes objects in arrayOfShapes) {// use arrayOfShapes to call methods //The output should display the Object Type (Circle, Square or Triangle)…arrow_forward
- Part 3: JavaScript - Program Outline, Startup Function, and Prompt We are going to use a function that we can consider an entry point into our running JavaScript. Below is an outline of the major elements in our JavaScript file. getRandomInt() function: generate a random integer startup() function: entry point function call to startup() function Below is your startup code: function getRandomInt(min, max) {}function startup() {}startup(); >> Add the above code components to your cis111-07.js JavaScript file below your multiline comment. >> Copy the getRandomInt function code from your previous assignment, or from this Stackoverflow article (Links to an external site.). Remember to add a single line comment above the getRandomInt function that documents the source of the code. Before attempting to use the prompt function in your code, you should try out the function in the console. >> Enter the following into the console to test displaying the prompt dialog. prompt();…arrow_forwardBuild a C program that performs the following operations: Declares three pointer variables called iPtr of type int, cPtr of type char, and fFloat of type float Declares three new variables called iNumber of int type, fNumber of float type, and cCharacter of char type Assigns the address of each non-pointer variable to the matching pointer variable Prints the value of each non-pointer variable Prints the value of each pointer variable Printer the address of each non-pointer variable Prints the address of each pointer variablearrow_forward#include <iostream>#include <pthread.h>#include <stdlib.h> #define TOTAL_THREADS 4 int count;pthread_mutex_t the_mutex; // phread mutex variable - initialize here if using the initializer macro void* myFunction(void* arg){int actual_arg = *((int*) arg);for(unsigned int i = 0; i < 10; ++i) {// TODO:// Use a Pthread mutex to control// access to the critical region. // Beginning of the critical regioncount++;std::cout << "Thread #" << actual_arg << " count = " << count << std::endl; // End of the critical region// TODO:// Relinquish access to the Pthread mutex// since critical region is complete. // Random wait - This code is just to ensure that the threads// show data sharing problemsint max = rand() % 100000;for (int x = 0; x < max; x++);// End of random wait code}pthread_exit(NULL);} int main(){int rc[TOTAL_THREADS];pthread_t ids[TOTAL_THREADS];int args[TOTAL_THREADS];// TODO: Initialize the pthread mutex here if using the…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





