我最近开始使用AWS AppSync&Flutter。我很难将它们彼此连接。
我正在使用graphql_flutter软件包,但无法弄清楚如何将其用于查询目的。
以下是我的代码段:
g++
我遇到以下错误:
$ cat basic_add.h
#ifndef BASIC_ADD_H_
#define BASIC_ADD_H_
__host__ __device__ int add_test( int a, int b );
#endif
$ cat basic_add.cu
__host__ __device__ int add_test(int a, int b)
{
return a + b;
}
int my_add_test(int a, int b){ return add_test(a,b);} //wrapper
$ cat add_func.h
#ifndef ADD_FUNC_H_
#define ADD_FUNC_H_
#include <iostream>
#include <math.h>
int my_add_test(int a, int b);
int gpu_main(void);
#endif
$ cat add_func.cu
#include "basic_add.h"
#include <iostream>
// Kernel function to add the elements of two arrays
__global__
void add(int n, float *x, float *y)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
printf("gridDim %d, blockDim %d, blockIdx %d, threadIdx %d\n", gridDim.x, blockDim.x, blockIdx.x, threadIdx.x);
for (int i = index; i < n; i += stride)
{
y[i] = add_test(x[i],y[i]);
printf("blockIdx %d, threadIdx %d, %d\n", blockIdx.x, threadIdx.x, i);
break;
}
}
int gpu_main(void)
{
int N = 1<<10;
float *x, *y;
// Allocate Unified Memory . accessible from CPU or GPU
cudaMallocManaged(&x, N*sizeof(float));
cudaMallocManaged(&y, N*sizeof(float));
// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
// Run kernel on 1M elements on the GPU
int blockSize = 256;
int numBlocks = (N + blockSize - 1) / blockSize;
add<<<numBlocks, blockSize>>>(N, x, y);
// Wait for GPU to finish before accessing on host
cudaDeviceSynchronize();
// Check for errors (all values should be 3.0f)
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i]-3.0f));
std::cout << "Max error: " << maxError << std::endl;
// Free memory
cudaFree(x);
cudaFree(y);
return 0;
}
$ cat main.cpp
#include <iostream>
#include <math.h>
#include "add_func.h"
int main(void)
{
gpu_main();
int a = my_add_test(1,2);
std::cout << a << std::endl;
return 0;
}
$ nvcc -dc basic_add.cu
$ nvcc -dc add_func.cu
$ nvcc -dlink -o add.dlink.o add_func.o basic_add.o
$ g++ -c main.cpp
$ g++ main.o add.dlink.o add_func.o basic_add.o -o test -L/usr/local/cuda/lib64 -lcudart
$
我如何使整个工作正常进行?
答案 0 :(得分:1)
在使用异步方法时,您需要使用Future函数。您可以像this一样更改方法:
Future<QueryResult> getRepositories(int numOfRepositories) async {
final HttpLink httpLink = HttpLink(
uri: 'https://myapi.xyz.com/graphql',
);
final AuthLink authLink = AuthLink(
getToken: () async => 'Bearer ${globals.token}',
);
final Link link = authLink.concat(httpLink);
GraphQLClient client = GraphQLClient(link: link, cache: InMemoryCache());
QueryOptions query = QueryOptions(documentNode: gql(queries.getAll));
var result = await client.query(query);
}
您可以从official documentation中了解有关异步编程的更多信息。